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

Thread Subject:
separating bluish color from other colors

Subject: separating bluish color from other colors

From: nman2084

Date: 13 Jun, 2011 15:21:05

Message: 1 of 4

I am trying to separate the point cloud which is bluish color from other colors, i need suggestions whether this will work or not.


[fn,pn] = uigetfile('*.txt', 'Open the txt file to be read');
file=fullfile(pn,fn);
dat = load(file);
x = dat(:,1);
y = dat(:,2);
z = dat(:,3);
r = dat(:,4)/255;
g = dat(:,5)/255;
b = dat(:,6)/255;



%c = [r,g,b];
blue_Diff1 = b(:,1) - r(:,1);
blue_Diff2 = b(:,1) - g(:,1);
%scatter3(x,y,z,5,c,'filled');

%%
[m,n] = size(x(:,1));
for i = 1:m
    if((blue_Diff1(i,1) > 0) && (blue_Diff2(i,1) > 0))
        xi(i,1) = x(i,1);
        yi(i,1) = y(i,1);
        zi(i,1) = z(i,1);
        ri(i,1) = r(i,1);
        gi(i,1) = g(i,1);
        bi(i,1) = b(i,1);
    end
end

Subject: separating bluish color from other colors

From: ImageAnalyst

Date: 13 Jun, 2011 15:53:44

Message: 2 of 4

That should work, although you're doing it for just the first column.
You might want to take a look at my color segmentation demos for
different approaches:
http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862

Subject: separating bluish color from other colors

From: nman2084

Date: 13 Jun, 2011 16:06:04

Message: 3 of 4

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <259d6348-18e7-4863-a735-675482322eea@s9g2000yqm.googlegroups.com>...
> That should work, although you're doing it for just the first column.
> You might want to take a look at my color segmentation demos for
> different approaches:
> http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862


I did not understand what you mean only one column:

x is (100000,1);
y is (100000,1);
z is (100000,1);
r is (100000,1);
g is (100000,1);
b is (100000,1);

Subject: separating bluish color from other colors

From: ImageAnalyst

Date: 13 Jun, 2011 20:48:00

Message: 4 of 4

Well you did this:
for i = 1:m
    if((blue_Diff1(i,1) > 0) && (blue_Diff2(i,1) > 0))
        xi(i,1) = x(i,1);
        yi(i,1) = y(i,1);
        zi(i,1) = z(i,1);
        ri(i,1) = r(i,1);
        gi(i,1) = g(i,1);
        bi(i,1) = b(i,1);
    end
end

Instead of this:
for row = 1:m
  for column = 1:n
    if((blue_Diff1(row, column) > 0) && (blue_Diff2(row, column) > 0))
        xi(row, column) = x(row, column;
        yi(row, column) = y(row, column);
        zi(row, column) = z(row, column);
        ri(row, column) = r(row, column);
        gi(row, column) = g(row, column);
        bi(row, column) = b(row, column);
    end
end

In your code, your column was just 1, not 1 through n, so it does only
one columns: the first one. Actually that whole slow mess can all be
replaced by the vectorized version

blue_Diff1 = b - r;
blue_Diff2 = b - g;
bluishPixelsMap = blue_Diff1 > 0 && blue_Diff2 > 0;
That's a binary (logical) image where each pixel says whether the
original image has a blue value that is brighter than both the red
value and the green value.

Then to extract them (mask them from the original image):
bluePixelsR = r;
bluePixelsR(~bluishPixelsMap ) = 0;
bluePixelsG = g;
bluePixelsG(~bluishPixelsMap ) = 0;
bluePixelsB = b;
bluePixelsB(~bluishPixelsMap ) = 0;
bluishPixelsImage = cat(3, bluePixelsR, bluePixelsG, bluePixelsB);

By the way, you'll need a way to inspect the 3D color gamut. Since
MATLAB doesn't have that capability (yet), I think you should follow
the steps I've outlined in post #2 here:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308559#838749

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us