Finding the RGB value of a .fig at given X and Y locations
7 views (last 30 days)
Show older comments
Madeleine Groves
on 6 Apr 2016
Commented: Madeleine Groves
on 7 Apr 2016
Hello there may be a really straight forward way to do this that I can't work out but basically...
I want to open up a matlab figure which looks like this and be able to find the RGB values at specific X and Y coordinates that I enter for example x = -122.078519830603 y = 59.3516220639968.
I can do something like this with the data cursor but I have a large number of x and y locations that I need the RGB values for and so would like to write it into my code.
Thanks for any help!
4 Comments
Muhammad Usman Saleem
on 6 Apr 2016
Edited: Muhammad Usman Saleem
on 6 Apr 2016
see my answer below. Firstly save this map in tiff or jpeg format and then try my solution
Accepted Answer
Chad Greene
on 6 Apr 2016
I wrote colorpicker to get rgb values from mouse clicks on a figure. You could modify colorpicker to use specified coordinates instead of mouse clicks.
More Answers (2)
Muhammad Usman Saleem
on 6 Apr 2016
Edited: Muhammad Usman Saleem
on 6 Apr 2016
x=imread('YourImage');
- Images are matrices (2D if grayscale, 3D if colored) in MATLAB.
- You can use x(i,j) to access a pixel at location (i,j) in a grayscale image.
- If the image is colored, you can use x(i,j,:) to access the r, g, b values in a 3-vector, respectively. If you need individual channels, then, you can use x(i,j,1) for red for example.
- You may read to learn this page more.
4 Comments
Muhammad Usman Saleem
on 7 Apr 2016
what is your prescription about -x,-y?
It is coordinates of the frame in which image has open. Are you know georeference image/ Ungeoreference image??
This function run smoothly for all inputs even on -x,y, if gray value at this location exited! You are trying to get where there no DN value at this location! @Adam
Adam
on 7 Apr 2016
Well, I don't know what the author of the question has in mind, but it seems clear some sort of interpolation has to be done if they want to query such a specific point because it will not exist on the grid, even if negative integers are appropriately shifted to be interpreted as indices into the image.
I assume that a value is still required to be calculated for these cases rather than just a "no value exists at this location" type of error.
Image Analyst
on 6 Apr 2016
You can use impixelinfo() to have a little status bar on your GUI that gives you the x and y and RGB values as you mouse around the image. It's easy - I do it all the time.
4 Comments
Image Analyst
on 6 Apr 2016
If you know the coordinates in advance, just hard code them in, like Muhammad showed.
Muhammad Usman Saleem
on 7 Apr 2016
@Image you are my teacher. I want to learn from you a lot of new stuff..
Stay bless always
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!