MATLAB: Can a particular portion of an image be cropped according to the requirement

image processing

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

Best 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.