can a particular portion of an image be cropped according to the requirement?

I need to crop a recangle(tray) in an image even if its orientation is changed, i tried thresholding and regionprops for detecting the rectangle, but i need to crop it. I am new to this field, any help on how i can proceed.
thanks in advance. my image is very much similar to the image in the link below. http://medcaretips.com/images/tray-for-keeping-sample-tubes

 Accepted Answer

Threshold, then you can get the bounding box in a number of ways, for example getting horizontal and vertical profiles by summing in each direction and then using find() to find the rows and columns where the intensity drops below some value. Or you can just pass the threshold image into regionprops and ask it for the bounding box. Then use imcrop. See my image segmentation tutorial BlobsDemo for an example, and come back if you're still having trouble.

3 Comments

i hav a doubt, regionprops returns a num of struct. how can that be connected to the imcrop.
You never ran my demo, did you? If you had you would have seen code like this:
message = sprintf('Would you like to crop out each coin to individual images?');
reply = questdlg(message, 'Extract Individual Images?', 'Yes', 'No', 'Yes');
% Note: reply will = '' for Upper right X, 'Yes' for Yes, and 'No' for No.
if strcmpi(reply, 'Yes')
figure;
% Maximize the figure window.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
for k = 1 : numberOfBlobs % Loop through all blobs.
% Find the bounding box of each blob.
thisBlobsBoundingBox = blobMeasurements(k).BoundingBox; % Get list of pixels in current blob.
% Extract out this coin into it's own image.
subImage = imcrop(originalImage, thisBlobsBoundingBox);
etc.
yes i did, it perfectly suits. thank you.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!