May i know how to find for numYellowPixel in this code
1 view (last 30 days)
Show older comments
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 Comments
Jan
on 9 Jun 2021
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
on 9 Jun 2021
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.
Answers (1)
Image Analyst
on 10 Jun 2021
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 Comments
Image Analyst
on 11 Jun 2021
Edited: Image Analyst
on 11 Jun 2021
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);
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!