Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How have I separate only one color?

Asked by 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).

0 Comments

Pawel

Tags

Products

No products are associated with this question.

1 Answer

Answer by 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 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 on 30 Jan 2013

For better, more flexible and robust color segmentation, see my File Exchange where I have several methods.

Image Analyst

Contact us