how to get the position of the pixel?

1 view (last 30 days)
for example I have an 256x256 image,called A.
any method to get every pixel position?
actually, I try to find the longest line on 3D the image in binary.
So I want to write a loop to calculate distance between every pixel in white and find the max one .

Accepted Answer

Image Analyst
Image Analyst on 3 Aug 2014
Edited: Image Analyst on 3 Aug 2014
Every pixel position is given by meshgrid
[rows, columns, numberOfColorChannels] = size(yourImage);
[x, y] = meshgrid(1:rows, 1:columns);
You most likely don't need that. If you want to find the two points in the image that are fartest apart, you need to use bwboundaries to get a list of boundary coordinates, then use a nested for loop to calculate which pair of points have the greatest distance between them. This is exactly what my attached demo (below the image) does.
See the red line below:
That red line goes between the farthest points in the binary image. The magenta line is the line at the midpoint that is perpendicular to it.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!