How to I get the coordinates of a given pixel?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
James Richards
el 21 de Mzo. de 2016
Comentada: Pablo Velez
el 6 de Mayo de 2021
I was wondering if there was a method to get the X,Y coordinate of a pixel in an image? I have the pixels that I'd like to get the coordinates of, but as they aren't regions, a regionprops centroid doesn't help, and I need it to be done without user input, so I can't click on them with ginput.
3 comentarios
Walter Roberson
el 21 de Mzo. de 2016
X coordinate 1003.87333157056 with Y coordinate 989.636902390572 would be found at index (989.636902390572, 1003.87333157056) in the array. Y then X.
Respuesta aceptada
Image Analyst
el 22 de Mzo. de 2016
Use bilinear interpolation, like interp2() if you want the exact value of fractional coordinates. However, it may be good enough for you to do a much simpler operation of just rounding the coordinates to the nearest integer and just getting the array element
grayLevel = grayImage(round(y), round(x));
Remember, like Walter said above, it's (y,x) not (x,y) because the first index is rows and y is the row.
You might also like the impixel() function, but I don't find that any more convenient than simple indexing.
3 comentarios
Image Analyst
el 3 de Feb. de 2020
No, it's (x, y) not (row, column), which would be (y, x). That's one thing you always have to keep mindful of and a common cause of beginners' problems. It's described in the help documentation.
props = regionprops(mask, 'Centroid');
xy = vertcat(props.Centroid);
x = xy(:, 1); % Columns
y = xy(:, 2); % Rows
I can't help you with the conversion to geographical coordinates. Look into functions of the Mapping Toolbox.
Pablo Velez
el 6 de Mayo de 2021
"a common cause of beginners' problems" happend to me but I didn't find it in the documentation https://www.mathworks.com/help/matlab/ref/imread.html I could only infer it from the example, is that what you mean with "described in the help documentation" or am I missing something.
Also I don't undertand why they switch x y places, python matplotlib does the same, why?
Más respuestas (0)
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!