How can i change the value of the color?
6 views (last 30 days)
Show older comments
The code works perfectly for pure red extract.I have a problem with the colour.I need it to be different.
% Get the snapshot of the current frame
data = getsnapshot(vid);
% Now to track red objects in real time
% we have to subtract the red component
% from the grayscale image to extract the red components in the image.
diff_im = imsubtract(data(:,:,1), rgb2gray(data));
%Use a median filter to filter out noise
diff_im = medfilt2(diff_im, [3 3]);
% Convert the resulting grayscale image into a binary image.
diff_im = im2bw(diff_im,0.18);
% Remove all those pixels less than 300px
diff_im = bwareaopen(diff_im,300);
% Label all the connected components in the image.
bw = bwlabel(diff_im, 8);
% Here we do the image blob analysis.
% We get a set of properties for each labeled region.
stats = regionprops(bw, 'BoundingBox', 'Centroid');
% Display the image
imshow(data)
hold on
%This is a loop to bound the red objects in a rectangular box.
for object = 1:length(stats)
counter=counter+1;
bb = stats(object).BoundingBox;
bc = stats(object).Centroid;
rectangle('Position',bb,'EdgeColor','r','LineWidth',2)
plot(bc(1),bc(2), '-m+')
a=text(bc(1)+15,bc(2), strcat('X: ', num2str(round(bc(1))), ' Y: ', num2str(round(bc(2)))));
%b=stract('X',strcat('X: ', num2str(round(bc(1)))), ' Y: ', num2str(round(bc(2))));
%A(counter)=a;
set(a, 'FontName', 'Arial', 'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
end
hold off
end
% Both the loops end here.
The color of the object is this.
I've taken a snapshot from my webcam (the red plane)
The rgb value of the color >(32,0,0), <(132,0,0)
I tried to modify with redThrash with values 0.3,0.4,0.5 ....and it doe not work.
The value of the trashhold is 0.18...i tried even there but,it recognizes skin.
Please help,it is for an important thesis for my school !
<http://uploadimage.ro/img.php?image=7620_redcolour_x2zc.jpg >> http://uploadimage.ro/img.php?image=7620_redcolour_x2zc.jpg
0 Comments
Answers (1)
Image Analyst
on 13 Jun 2014
Edited: Image Analyst
on 13 Jun 2014
That code does not find only red objects. It thresholds the red channel. White, magenta, and yellow objects will also have a high red signal, and it will find those as well. Not sure who gave you that code but they don't know much about color segmentation. See my color segmentation demos in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!