How to Find the min and max coordinates of an object in an image

 Accepted Answer

[I,J]=find(yourImage);
minIJ=min([I,J],[],1);
maxIJ=max([I,J],[],1);

5 Comments

thanks Matt J. One more thing. If I want to get min of I and min of J from your recommended code [ I,J]=find(yourImage);. Similarly max of I and J separately. what should I do for that.
minI = minIJ(1);
minJ = minIJ(2);
maxI = maxIJ(1);
maxJ = maxIJ(2);
hello,
I have a doubt . if i have coordinates of a point and a digital image (i.e., either black or white (bitmap)). How to find the distance between the point and each pixel of the image.
Try this, where (xp, yp) are the coordinates of your single point.
[rows, columns, numberOfColorChannels] = size(yourImage);
[x, y] = meshgrid(1:columns, 1:rows);
distanceImage = sqrt((x-xp).^2 + (y-yp).^2);
imshow(distanceImage, []);

Sign in to comment.

More Answers (1)

Note: Matt's solution only works if you have only 1 object in your binary image. If you have multiple objects, use regionprops() and ask for the BoundingBox measurement. See my Image Segmentation Tutorial for a full demo: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

Asked:

on 3 Oct 2015

Commented:

on 16 Feb 2019

Community Treasure Hunt

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

Start Hunting!