Filter löschen
Filter löschen

RGB image in the yellow green mixed color?

9 Ansichten (letzte 30 Tage)
djamaleddine djeldjli
djamaleddine djeldjli am 3 Dez. 2017
Kommentiert: Image Analyst am 18 Okt. 2021
i have an RGB image and i separate it's three components R, G, B (image in Red component,.......) to see my image in each component ,i convert it from rgb2cmy and i can plot it in associted red and green components or green an bleu components ....but i can't do that for yellow and green associed components ?
i need to plot my image in associted two components yellow and green
thank you in advance for your help
RGB =imread('image2.jpg');
G = RGB;
G(:,:,1) = 0;
G(:,:,3) = 0;
subplot(2,2,1);
image(G);
axis image
title('Green Component')
y=255-B;
subplot(2,2,2);
image(y);
axis image
title('yellow Component')
GY=y+G;???????????????????
subplot(2,2,3);
image(GY);
axis image
title('yellow and Green Components')
  1 Kommentar
djamaleddine djeldjli
djamaleddine djeldjli am 3 Dez. 2017
I want my image to contain only the colors between yellow and green

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Image Analyst
Image Analyst am 3 Dez. 2017
I'm not sure what you mean by the yellow component. The image has only red, green, and blue components. If you want you can use rgb2lab() and display the b component. Positive b would be yellow colors.
colorcloud(rgbImage, 'lab');
labImage = rgb2lab(rgbImage);
bImage = labImage(:,:,3);
figure;
imshow(bImage, []);
  4 Kommentare
Allinone
Allinone am 17 Okt. 2021
Is it possible to see two colours in an RGB image and then convert it in a gray scale?
Image Analyst
Image Analyst am 18 Okt. 2021
You can have two, or millions, or any number of colors in an RGB image. To visualize/see them, use the imshow() function:
imshow(rgbImage);
Then, to convert the RGB image into grayscale, use the rgb2gray() function:
grayImage = rgb2gray(rgbImage);

Melden Sie sich an, um zu kommentieren.


Guillaume
Guillaume am 4 Dez. 2017
"I want my image to contain only the colors between yellow and green"
First, you need to define mathematically what that means.
As IA says, you're probably better off working in the HSV colour space. You can easily set a threshold on the hue for whatever you define as between yellow and green (maybe 52/360 to 154/360 ?). Even then, you probably also need thresholds for value and saturation. For example:
yellow1 = hsv2rgb(cat(3, 57/360, 1, 1)); %yellow at full saturation and brightness
yellow2 = hsv2rgb(cat(3, 57/360, 1, 0.1); %same yellow at full saturation but much lower brightness
imshowpair(repmat(yellow1, 200, 200), repmat(yellow2, 200, 200), 'montage');
The 2 images generated above are exactly the same yellow hue. Yet not many people would say that the right hand image is yellow.
So maybe:
rgbimage = hsv2rgb(cat(3, mod(hankel(50:249, 249:448)/200, 1), repmat(1, 200, 200), 1-toeplitz(1:200)/200)); %demo image
hsvimage = rgb2hsv(rgbimage);
isyellowgreen = hsvimage(:, :, 1) >= 52/360 & hsvimage(:, :, 1) <= 154/360 & ... filter on hue, adjust as required
hsvimage(:, :, 2) >= 0.2 & ... filter on saturation, adjust as required
hsvimage(:, :, 3) >= 0.2; % filter on value, adjust as required
filteredimage = hsvimage;
filteredimage(repmat(~isyellowgreen, 1, 1, 3)) = 0; %set non yellow-green to 0
imshowpair(rgbimage, hsv2rgb(filteredimage), 'montage')
Adjust thresholds as required
  6 Kommentare
Image Analyst
Image Analyst am 6 Dez. 2017
I still don't think your approach is right, but whatever...let's discuss... Since yellow is red + green, if you want green + yellow you'd want green + green + red. However that double counts the pixels' contribution from the green wavelength part of the spectra, so you need to subtract that out. So if you want yellow + green you'd need to subtract out the red. However red contributes to yellow. There is no yellow in RGB images without red. But if you subtract out the red, you're just left with green. You see, digital cameras have 3 spectral sensitivity ranges, each taking up about a third of the spectrum but with a lot of overlap. There is no sensor that just looks at yellow, only green and red. So I'm back to the original suggestion which is if you want pixels in the yellow to green range, then you should do color segmentation on the hue channel in HSV color space. And if you want the amount of Yellowness/blueness in any color, then you should convert to LAB color space and use the b channel.
Guillaume
Guillaume am 6 Dez. 2017
I don't really understand the question anymore. As Image Analyst just explained there isn't a yellow channel in RGB (which is what matters for display), so you can't isolate yellow in RGB. It's a mix of red and green.
You can isolate yellow (and green) in the HSV colour space, which is what I've shown in my answer.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Image Processing Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by