MATLAB: How can the middle portion of an image be extracted

image extraction

I want to extract the middle object from the entire image It will be very helpful if someone can guide, as I am new to matlab.The image has a resolution of 200meters.I have written the code as:
A= ('A.tif');
props=(A, 'centroid');
props=regionprops(labeledImage,'Centroid');
allCentroids=props.Centroid;
xCentroids=allCentroids(1:2:end);
yCentroids=allCentroids(2:2:end);
allCentorids=allCentroids';
[size1,size2]=size(allCentroids);
imshow(A);

Best Answer

In your loop, you need to set
xmin=xCentroids(1,k) - r(k).BoundingBox(3) - 6;
ymin=yCentroids(1,k) - r(k).BoundingBox(4) - 6;
width = r(k).BoundingBox(3) + 12;
height = r(k).BoundingBox(3) + 12;
croppedImage = imcrop(A, [xmin ymin width height]);