How do i find the RGB values of color image in range 1 to 255
38 ビュー (過去 30 日間)
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....
DGM 2022 年 12 月 2 日
編集済み: DGM 2022 年 12 月 2 日
See this thread:
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.
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.
inpict = imread('peppers.png');
sampleradius = 5;
% show the image
% 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);
points = points(~badpts,:);
% get selected tuples
npoints = size(points,1);
pickedcolors = zeros([npoints size(inpict,3)],class(inpict));
if sampleradius > 0
xx = 1:sz(2);
yy = (1:sz(1)).';
for p = 1:npoints
x = points(p,1);
y = points(p,2);
if sampleradius <= 0
% just one pixel
pickedcolors(p,:) = inpict(y,x,:);
% find the average of pixels within a given distance
mask = ((xx-x).^2 + (yy-y).^2) <= sampleradius^2;
samplesize = sum(mask(:));
for c = 1:size(inpict,3)
wpict = inpict(:,:,c);
pickedcolors(p,c) = sum(wpict(mask))/samplesize;
% list the colors as a uint8 color table
% 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.
inpict = imread('peppers.png');
% 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
See also this thread.
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.
Find more on Image Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!