필터 지우기
필터 지우기

How can I access the RGB data in this figure

조회 수: 2 (최근 30일)
Kenneth Morley
Kenneth Morley 2014년 1월 21일
댓글: Image Analyst 2017년 4월 26일
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!

답변 (2개)

Walter Roberson
Walter Roberson 2014년 1월 21일
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
Kenneth Morley
Kenneth Morley 2014년 1월 21일
편집: Kenneth Morley 2014년 1월 21일
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?

댓글을 달려면 로그인하십시오.


ArthurHB
ArthurHB 2017년 4월 26일
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
Walter Roberson
Walter Roberson 2017년 4월 26일
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 2017년 4월 26일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Red에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by