Finding the RGB value of a .fig at given X and Y locations

6 visualizaciones (últimos 30 días)
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 comentarios
Madeleine Groves
Madeleine Groves el 6 de Abr. de 2016
Hi Muhammad it's a map. I run a script that produces this colormap from my data (a .fig file). I don't want to save it as an image file as I want to use the specific X and Y values to get the color data at that point on the map.
Muhammad Usman Saleem
Muhammad Usman Saleem el 6 de Abr. de 2016
Editada: Muhammad Usman Saleem el 6 de Abr. de 2016
see my answer below. Firstly save this map in tiff or jpeg format and then try my solution

Iniciar sesión para comentar.

Respuesta aceptada

Chad Greene
Chad Greene el 6 de Abr. de 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.
  1 comentario
Madeleine Groves
Madeleine Groves el 7 de Abr. de 2016
Thank you your clickz function does what I was wanting to do without having to find what z value the RGB relates to and has solved my problem.

Iniciar sesión para comentar.

Más respuestas (2)

Muhammad Usman Saleem
Muhammad Usman Saleem el 6 de Abr. de 2016
Editada: Muhammad Usman Saleem el 6 de Abr. de 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 comentarios
Muhammad Usman Saleem
Muhammad Usman Saleem el 7 de Abr. de 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
Adam el 7 de Abr. de 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.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 6 de Abr. de 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 comentarios
Image Analyst
Image Analyst el 6 de Abr. de 2016
If you know the coordinates in advance, just hard code them in, like Muhammad showed.
Muhammad Usman Saleem
Muhammad Usman Saleem el 7 de Abr. de 2016
@Image you are my teacher. I want to learn from you a lot of new stuff..
Stay bless always

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by