Question about colormap? how to change color from one image?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have an image(a bike),I need to write a well commented program that loads this picture and creates a new black-white picture of the yellow part of the bike frame, but nothing else.
my question is how can I change the color to black and white from the yellow color?
that's what I did:
pic=imread('bike.jpg');
size(pic)
images(pic)
colormap(gray)
colorbar
r=pic(:,:,1)
g=pic(:,:,2)
b=pic(:,:,3)
then, i don't know how to do next? does anyone who can help me with that question?
0 commentaires
Réponse acceptée
Geoff
le 15 Avr 2012
To detect your yellow, you need to find the relationship between the RGB channels that creates a yellow colour. Now, pure yellow is where the red and green channels are equal and the blue channel is zero.
Unfortunately, this is not likely to be the case in your image. What you'll find is that for the yellow parts, your red and green channels are 'roughly similar', and the blue channel is just about anything (as the blue channel value increases, the yellow becomes more saturated (as the RGB triple approaches a gray value). As the red and green diverge, the colour becomes more orange or lime.
So there's no 'yes/no' logical value that will tell you what to do, but if you try creating one you'll end up with jagged edges, colour bleeding, or both.
What you want is to devise a 'fuzzy truth' value which is 1 for pure yellow, and drops to zero as it becomes less yellow. You calculate that for each pixel (it'll be a single vector operation on your image data), and then use it to blend between the gray image and the colour image.
graypic = rgb2gray(pic);
isyellow = ...
pic = isyellow .* pic + (1-isyellow) .* graypic;
I don't have the image processing toolbox so I can't check rgb2gray. You may need to use repmat and possibly reshape to make it the same dimension as your pic. Do the same with your isyellow selector.
Speaking of the selector...
You need to work out a formula for how yellow something can be. I would start by taking those r, g, and b splits you have already shown, and doing something like this:
isyellow = (1 - abs(r-g)) * (r+g - 2*b);
This gives a maximum value when r and g are similar and large, and when the blue value is furthest from the average of r and g. I would probably also scale the result by some gaussian and clip it between 0 and 1.
2 commentaires
Walter Roberson
le 15 Avr 2012
Once you have created the isyellow array like Geoff shows above,
BWImage = isyellow;
or if you prefer for certainty:
BWImage = uint8(isyellow) * uint8(255);
Plus de réponses (1)
Image Analyst
le 15 Avr 2012
Your duplicate is here: http://www.mathworks.com/matlabcentral/answers/35506-question-about-how-to-change-color-on-an-image For some reason you didn't check it. If you had trouble using my routines like the "Simple color detection by hue" which finds yellow objects, let me know. Here again is the link: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
0 commentaires
Voir également
Catégories
En savoir plus sur Orange dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!