May i know how to find for numYellowPixel in this code

2 次查看(过去 30 天)
clc
clear
clear all
images= []
webcamlist()
cam= webcam(1)
preview(cam)
pause(2);
images= snapshot(cam)
imshow(images)
r_channel= images(:,:,1);
g_channel= images(:,:,2);
b_channel= images(:,:,3);
images(:,:,1) =0;
images(:,:,3) = 0;
image(images);
mask= g_channel > 100, b_channel > 800, r_channel < 800, b_channel < 0, r_channel < 0;
numBlackPixels = sum(~mask(:))
gr_ratio = double(g_channel)./double(r_channel);
gb_ratio = double(g_channel)./double(b_channel);
rb_ratio = double(r_channel)./double(b_channel);
% gr_ratio(isnan(g_ratio))=0;
% grayImage = rgb2gray(image);
% binaryImage = grayImage > 20;
% binaryImage = bwareaopen(binaryImage, 50);
% binaryImage = imfill(binaryImage, 'holes');
% grayImage(~binaryImage) = 0;
falseMatrix= zeros(7,7);
targetMatrix= ones(7,7);
checkMatrix= ones(7,7);
fprintf('mask has %d black pixels.\n', numBlackPixels);
if targetMatrix == checkMatrix
% cam = camStop;
return
end
  2 个评论
Jan
Jan 2021-6-9
It is not getting clear to me, what you are asking for.
What is the purpose of this line:
mask= g_channel > 100, b_channel > 800, r_channel < 800, b_channel < 0, r_channel < 0;
Only the first comparison matters, the rest is ignored.
Sulaymon Eshkabilov
Note that "yellow" color pixel is the composition of three layers, viz. Red, Green, Blue. From these three layers in combination, you'd need to create a mask that gives a "Yellow" pixel.

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2021-6-10
Use the ColorThresholder app on the Apps tab of the tool ribbon to create a mask. Then export the function and call it whenever you need to find the yellow mask.
  2 个评论
Image Analyst
Image Analyst 2021-6-11
编辑:Image Analyst 2021-6-11
Exactly what does "get" mean to you. Please be very specific, like locations, colors, both, whatever. Basically use find() and imsplit().
[r,g,b] = imsplit(rgbImage);
[rows, columns] = find(mask); % the BW from the Color Threshold app.
redPixels = r(mask);
greenPixels = g(mask);
bluePixels = b(mask);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by