From: memo mohd on
hello for all ,,

I want to detect different colors from image , i am use this code
hr=M(:,:,1); %red
% image(hr)
% figure('Name','blue')
hb=M(:,:,3); %blue
% image(hb)

but , if I want to detect color rather than red , green , blue
i want to merge the green and blue for define yellow , but how can I modify this code for do that ?
thanks a lot
From: ImageAnalyst on
On Jan 2, 5:28 pm, "memo mohd" :
Here's a demo I've been working on. It's still in progress but you
should EASILY be able to adapt it to find the yellow objects instead
of the red objects. Just adjust the thresholds - very simple. This
is a very elementary color classification method performed in rgb
space. If you want, you could do it in hsv color space as well - the
hsv way might better compensate for exposure differences. But this
could help you get started.

% Demo macro to very, very simple color detection
% by ImageAnalyst
clc;
close all;
figuresc(0.9, 0.8);
% Read standard MATLAB demo image.
rgbImage = imread('onion.png');
% Display the original image.
subplot(3, 4, 1);
imshow(rgbImage);
title('Original RGB Image');
% Split into color bands.
redBand = rgbImage(:,:, 1);
greenBand = rgbImage(:,:, 2);
blueBand = rgbImage(:,:, 3);
% Display them.
subplot(3, 4, 2);
imshow(redBand);
title('Red Band');
subplot(3, 4, 3);
imshow(greenBand);
title('Green Band');
subplot(3, 4, 4);
imshow(blueBand);
title('Blue Band');

% Threshold each color band.
% first set up low and high thresholds.
lowRed = 68;
highRed = 255;
lowGreen = 0;
highGreen = 70;
lowBlue = 0;
highBlue = 72;
% Then get the binary image of where the color band
% falls within that threshold range.
redMask = (redBand > lowRed) & (redBand < highRed);
greenMask = (greenBand > lowGreen) & (greenBand < highGreen);
blueMask = (blueBand > lowBlue) & (blueBand < highBlue);

% Display them.
subplot(3, 4, 6);
imshow(redMask, []);
title('Red Mask');
subplot(3, 4, 7);
imshow(greenMask, []);
title('Green Mask');
subplot(3, 4, 8);
imshow(blueMask, []);
title('Blue Mask');
% Combine the masks to find where all 3 are "true."
% This will be where the "red" objects are.
redObjectsMask = redMask & greenMask & blueMask;
subplot(3, 4, 9);
imshow(redObjectsMask, []);
title('Combined Mask');
% Fill in holes, and display the image.
redObjects = uint8(imfill(redObjectsMask, 'holes'));
subplot(3, 4, 10);
imshow(redObjects, []);
title('Filled Mask');
% Multiply this mask times the original RGB image
% to get an image that has the red objects only.
maskedImageR = redObjects .* redBand;
maskedImageG = redObjects .* greenBand;
maskedImageB = redObjects .* blueBand;
maskedImage = cat(3, maskedImageR, maskedImageG, maskedImageB);
% Display it.
subplot(3, 4, 11);
imshow(maskedImage, []);
title({'Filled Mask times Original =';'Red Objects Only'});
From: memo mohd on
thanks image analyst
but there are error here when implemente the code

figuresc(0.9, 0.8);

???
From: ImageAnalyst on
Sorry - that was a function to enlarge the figure.
Delete it and replace it with this:

set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
From: memo mohd on
ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <220367f6-7e19-
thanks , it is work done
but it is large code , can i use simple than it ?
see this code but there are errors also
clear
M=(imread('D:\f4.jpg'));
figure('Name','Original')
image(M)
[row,col]=size(M);
for i=1:row
for j=1:col

if
M(i,j,1:3) = hr[255 0 0 ]; %red

image(M)
figure('Name','red')

else

M(i,j,1:3) = hr[0 255 255]; %yellow
image(M)
figure('Name','yellow')
end
end
end

the error in if
(Expression or statement is incomplete or incorrect.)
can you tel me where the error in code ?
thanks a lot
 |  Next  |  Last
Pages: 1 2
Prev: problem with mex
Next: java heap space error