Hi All,
I wish to detect the rectangle as shown below in the image. After that, I want to crop out what's only inside the rectangle part.
Anyone can teach me how?
First, I changed this coloured image into grayscale image then to binary image. Then, I tried using 'regionprops' with 'BoundingBox' to detect the presence of rectangle. However, the cropped image is not exactly the rectangle size.
PS. I do refer from someone else code.
% Find boundary box
props = regionprops(binaryImage, 'BoundingBox');boundingBox = props.BoundingBox;width = boundingBox(3);height = boundingBox(4);% Crop off the top, shaded portion of column headers,
% which are known to be a fixed 29% of the height of the box.
newHeight = height * (1 - 0.29)% Make a new bounding box.
xLeft = boundingBox(1);yTop = boundingBox(2);boundingBox2 = [xLeft, yTop + 0.29 * height, width, newHeight];% Crop the image
newGrayScaleImage = imcrop(grayImage, boundingBox2);subplot(2, 3, 6);imshow(newGrayScaleImage);axis('on', 'image');impixelinfo;title('New Gray Scale Image', 'FontSize', fontSize);
Result:
Best Answer