How can i change the value of the color?

조회 수: 3 (최근 30일)
Sergiu Craciun
Sergiu Craciun 2014년 6월 13일
댓글: Sergiu Craciun 2014년 6월 13일
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

답변 (1개)

Image Analyst
Image Analyst 2014년 6월 13일
편집: Image Analyst 2014년 6월 13일
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
  댓글 수: 1
Sergiu Craciun
Sergiu Craciun 2014년 6월 13일
My thesis is of this particular modification in the program. The sequence code diff_im = imsubtract(data(:,:,1), rgb2gray(data)); only extracts pure red objects with (255,0,0) value in rgb.can you please help me with a sequence to track red objects between (32,0,0) and (132,0,0) in rgb.Thank you !

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by