Borrar filtros
Borrar filtros

How can I access the RGB data in this figure

2 visualizaciones (últimos 30 días)
Kenneth Morley
Kenneth Morley el 21 de En. de 2014
Comentada: Image Analyst el 26 de Abr. de 2017
I have a 61x1 array. From the picture I can see exactly what I want, which is the RGB values for each X. I want to use this data in another part of my code. How can I extract this RGB data?
Thank you!

Respuestas (2)

Walter Roberson
Walter Roberson el 21 de En. de 2014
61 x 1 arrays do not have RGB values. You would need 61 x 1 x 3 to have an RGB value.
Unless:
  1. The values stored in the arrays are one of the integer datatypes and are acting as indices into a colormap that you have defined; or
  2. The values stored in the arrays are floating point numbers in the range 0 to 1 that are acting to indicate locations into a colormap based upon "fraction of the colormap length"; or
  3. The values stored in the arrays are floating point numbers and you have used imagesc() or imshow([]) to map the minimum value in the array to the beginning of the color map and the maximum value in the array is to be mapped to the highest location in the colormap; or
  4. #2 or #3 but caxis has been used to restrict to a smaller portion of the colormap
Notice that in each of these 4 cases, there is no absolute RGB value defined by the data directly, only indexing into a colormap that defines the colors to use.
  1 comentario
Kenneth Morley
Kenneth Morley el 21 de En. de 2014
Editada: Kenneth Morley el 21 de En. de 2014
Yes #1 is correct. The data I have is acting as an index in the image. My final goal is to use this indexed number to color various counties on a map based on their value. That is why I was trying to get RGB values. Is there some other way to do this?

Iniciar sesión para comentar.


ArthurHB
ArthurHB el 26 de Abr. de 2017
I'm with the same problem now.
I have generated a colormap figure and I want to get the RGB values from each element of the figure.
  2 comentarios
Walter Roberson
Walter Roberson el 26 de Abr. de 2017
cmap = copper(10);
r = 5; c = 7;
img = randi(10, r, c);
rgbimg = reshape( cmap(img,:), size(img,1), size(img,2), 3);
Image Analyst
Image Analyst el 26 de Abr. de 2017
If you have an indexed image, and you applied a colormap to it,
imshow(indexedImage);
colormap(yourColorMap);
colorbar;
and you want the RGB color of every pixel in the image, you can use ind2rgb() to make an RGB image.
rgbImage = ind2rgb(indexedImage, yourColorMap);
That gives you the RGB values of every pixel the whole image. If you want the RGB values of a particular pixel (a row and column) in that image, you can do
rgbThisPixel = rgbImage(row, column, :);
You can also get it from the original indexed image:
index = indexedImage(row, column); % Get the index.
rgbThisPixel = yourColorMap(index,:); % Retrieve the RGB value from the colormap.

Iniciar sesión para comentar.

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by