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!