Finding the RGB value of a .fig at given X and Y locations
3 次查看(过去 30 天)
显示 更早的评论
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!
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/160268/image.png)
4 个评论
Muhammad Usman Saleem
2016-4-6
编辑:Muhammad Usman Saleem
2016-4-6
see my answer below. Firstly save this map in tiff or jpeg format and then try my solution
采纳的回答
Chad Greene
2016-4-6
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.
更多回答(2 个)
Muhammad Usman Saleem
2016-4-6
编辑:Muhammad Usman Saleem
2016-4-6
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 个评论
Muhammad Usman Saleem
2016-4-7
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
2016-4-7
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
2016-4-6
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 个评论
Image Analyst
2016-4-6
If you know the coordinates in advance, just hard code them in, like Muhammad showed.
Muhammad Usman Saleem
2016-4-7
@Image you are my teacher. I want to learn from you a lot of new stuff..
Stay bless always
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!