Borrar filtros
Borrar filtros

May i know how to find for numYellowPixel in this code

2 visualizaciones (últimos 30 días)
Iszuzuldin amirull bin mohd janudin
Editada: Image Analyst el 11 de Jun. de 2021
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 comentarios
Jan
Jan el 9 de Jun. de 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
Sulaymon Eshkabilov el 9 de Jun. de 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.

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 10 de Jun. de 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 comentarios
Iszuzuldin amirull bin mohd janudin
Iszuzuldin amirull bin mohd janudin el 11 de Jun. de 2021
One more questions, how to get pixels of each mango?
Image Analyst
Image Analyst el 11 de Jun. de 2021
Editada: Image Analyst el 11 de Jun. de 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);

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by