[BW, maskedImage] = segmentImage(I);
BW2_left = imcrop(BW, [tlX_left tlY_left width height]);
BW2_right = imcrop(BW, [tlX_right tlY_right width height]);
RGB_left = imcrop(I, [tlX_left tlY_left width height]);
RGB_right = imcrop(I, [tlX_right tlY_right width height]);
BW2_left = bwareaopen(BW2_left, 100);
BW2_right = bwareaopen(BW2_right, 100);
imshowpair(BW2_left,BW2_right, "montage")
lines_left = HoughLines(BW2_left);
lines_right = HoughLines(BW2_right);
figure, imshow(RGB_left), hold on
for k = 1:length(lines_left)
xy = [lines_left(k).point1; lines_left(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','red');
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','green');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','green');
len = norm(lines_left(k).point1 - lines_left(k).point2);
disp("max length on left side: ")
img_frame = getframe(gca);
BW2_left = img_frame.cdata;
figure, imshow(RGB_right), hold on
for k = 1:length(lines_right)
xy = [lines_right(k).point1; lines_right(k).point2];
plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','red');
plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','green');
plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','green');
len = norm(lines_right(k).point1 - lines_right(k).point2);
disp("max length on right side: ")
img_frame = getframe(gca);
BW2_right = img_frame.cdata;
imshowpair(BW2_left,BW2_right, "montage")