How have I separate only one color?

13 views (last 30 days)
Pawel
Pawel on 30 Jan 2013
Hi,
I have an image in RGB.
fragment of code:
clc,clear all,close all, format long g, format compact
A=imread('car.jpg');
a=size(A);
w_image=a(2);
h_image=a(1);
s=round(0.05*w_image);
w=round(0.05*h_image);
C=imcrop(A,[0.05*w_image 0.4*h_image ...
w_image-1.5*s h_image-w]);
figure(1),imshow(C)
red=C(:,:,1);
green=C(:,:,2);
blue=C(:,:,3);
How could I separate only one color from an image?
I want to display new image which shows all blue pixels from old one (other pixels should be black/white).

Answers (1)

Image Analyst
Image Analyst on 30 Jan 2013
You already separated it. And you know how to display.
imshow(blue);
I'm not sure how to interpret your last sentence. It doesn't make sense. The blue channel of a color image is a monochrome image. If you just display the values, you can use the normal gray colormap, or any other one you want. ANd what are "other pixels"? And what color are they now?
  2 Comments
Pawel
Pawel on 30 Jan 2013
I want to display all blue pixels and other colors should be white or black.
I wrote:
red=C(:,:,1);
green=C(:,:,2);
blue=C(:,:,3);
t=find((green+red>=1.2*blue));
red(t)=0;
green(t)=0;
blue(t)=0;
D=cat(3,red,green,blue);
D=not(~D);
[wiersz_blue,kolumna_blue]=find(~(green+red>=1.2*blue));
D=[wiersz_blue kolumna_blue];
Now I have all blue pixels in image + col and row of those pixels. And this is what i wanted to do ;)
Image Analyst
Image Analyst on 30 Jan 2013
For better, more flexible and robust color segmentation, see my File Exchange where I have several methods.

Sign in to comment.

Categories

Find more on Display Image in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!