How to I get the coordinates of a given pixel?
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
James Richards
il 21 Mar 2016
Commentato: Pablo Velez
il 6 Mag 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 Commenti
Walter Roberson
il 21 Mar 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.
Risposta accettata
Image Analyst
il 22 Mar 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 Commenti
Image Analyst
il 3 Feb 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
il 6 Mag 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?
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Convert Image Type in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!