ginput to select RGB values of image to hold over when I turn image to grayscale
3 views (last 30 days)
Show older comments
Im working on a function to where i can use ginput to selct and area on th image and hole those values when i convert it ot grey scale. Having issues with it and index size.
imagein = 'Bird.jpg';
imshow('Bird.jpg');
n = 4;
% read and display color image
A = imread(imagein);
pic=uint8(A);
grayscale(:,:,1) = uint8(0.2989 * pic(:,:,1) + 0.5870 * pic(:,:,2) + ...
0.1140 * pic(:,:,3));
grayscale(:,:,2) = grayscale(:,:,1);
grayscale(:,:,3) = grayscale(:,:,1);
[x,y] = ginput(2);
% Put a cross where they clicked.
hold on;
plot(y:x)
% Get the location they click on.
row = int32(y);
column = int32(x);
% Extract the RGB color from that location.
selected_color = pic(row, column, :)
gray_color(:,:,1) = selected_color(grayscale(:,:,1)+1);
gray_color(:,:,2) = selected_color(grayscale(:,:,1)+1);
gray_color(:,:,3) = selected_color(grayscale(:,:,1)+1);
subplot(2,2,1)
image(pic)
subplot(2,2,2)
image(grayscale)
subplot(2,2,3)
image(gray_color)
10 Comments
DGM
on 14 Apr 2021
I should point out that there are other color-based mask generation tools around. If you have IPT, you can try the Color Thresholder app.
Answers (1)
Image Analyst
on 14 Apr 2021
The red pepper has thousands of red colors in it. Do you want to have only the two pixels you clicked on stay red and all other pixels turn gray? Or do you want to find all colors within a certain delta E color distance of the red you clicked on stay red and all other pixels turn gray? See attached demo.
2 Comments
Image Analyst
on 14 Apr 2021
So this is what the demo does now. Can you modify it to make it gray outside the mask? Not too hard but let me know if you can't figure it out.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!