# How do i find the RGB values of color image in range 1 to 255

조회 수: 50 (최근 30일)
Shri.s 2022년 12월 1일
편집: DGM 2022년 12월 2일
I want know the RGB values are in the form of three digit like 100,243,122,etc.
please anyone can tell me how to find RGB values....
##### 댓글 수: 7이전 댓글 5개 표시이전 댓글 5개 숨기기
Shri.s 2022년 12월 2일
The most frequent color?
DGM 2022년 12월 2일
편집: DGM 2022년 12월 2일
I offer some simple examples, and @Image Analyst offers one in the comments as well. If either are of interest, you should read the discussion under ImageAnalyst's answer as well. The "most common color" is the maximizing position in a 3-dimensional histogram, but there are often a number of broad, similarly-prominent maxima in the distribution. The global maxima is often not the one that is perceived to be visually important, as color is often correlated to object content.
If the goal is to use color frequency information, it might need to be paired with other forms of analysis, depending on what you hope color frequency represents within the images under test.

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

### 답변 (2개)

Benjamin Thompson 2022년 12월 1일
If the image is stored in MATLAB as a three dimensional array, which is the usual, then the red/green/blue channel is the third dimension. Sometimes there is a fourth channel alpha for transparency. You can access the entire red channel of such an image using, for example:
redData = myRGBImage(:,:,1);
Or access the red component of pixel 64, 128 specifically:
redDataOnePixel = myRGBImage(64,128,1);
Hope this helps. For a better answer attach a sample image and ask a more detailed question.
##### 댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
John D'Errico 2022년 12월 1일
The 4 channels of an image may also be CMYK code values, and I recall devices with 6 or even different 7 color inks, used to increase the color gamut for a corresponding device or other purposes. For example, you might have cyan, magenta, yellow, black, orange, green, light grey.

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

DGM 2022년 12월 1일
I want to find the RGB color at/around a specific location in an image
That can be done, but it depends how you want to select the points and whether you want the color of a specific pixel or not. Getting the color of a specific pixel is often pretty useless unless you're dealing with synthetic images or you only care about one pixel.
% inputs
% show the image
imshow(inpict);
% pick points somehow.
% in this case, do it interactively with the mouse; hit ENTER when done
[x y] = getpts(gca);
% get rid of points that are outside the image area
sz = size(inpict);
points = round([x y]);
badpts = any(points<1,2) | points(:,2)>sz(1) | points(:,1)>sz(2);
% get selected tuples
npoints = size(points,1);
pickedcolors = zeros([npoints size(inpict,3)],class(inpict));
xx = 1:sz(2);
yy = (1:sz(1)).';
end
for p = 1:npoints
x = points(p,1);
y = points(p,2);
% just one pixel
pickedcolors(p,:) = inpict(y,x,:);
else
% find the average of pixels within a given distance
for c = 1:size(inpict,3)
wpict = inpict(:,:,c);
end
end
end
% list the colors as a uint8 color table
pickedcolors
% show the color table as a stripe image
imshow(permute(pickedcolors,[1 3 2]))
There are purpose-built color picker tools that can do this more conveniently, but we'll cross that bridge if we come to it.
Also, bear in mind that most things in MATLAB that accept color tuples or color tables only accept them as unit-scale floating point arguments. You can use
pickedcolors = im2double(pickedcolors);
to get results that can be used for those cases.
I want all the colors of an RGB image as a color table
It doesn't really make much sense to get all the colors of an image. That's just a reshaped image. It might be useful to get all the unique colors.
% inputs
% get all unique colors
CT = reshape(inpict,[],size(inpict,3)); % this is all the colors
CT = unique(CT,'rows'); % just the unique colors
I want the average color of an RGB image
meancolor = uint8(reshape(mean(inpict,[1 2]),1,[])) % the average color
I want the color name of an RGB tuple -OR- RGB tuple for a color name
See Stephen's colornames() as mentioned in the prior thread for both. See also the references that @Image Analyst provided.

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

### 카테고리

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

### Community Treasure Hunt

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

Start Hunting!

Translated by