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
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
2021년 6월 9일
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
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
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 Center 및 File Exchange에서 Image Data Workflows에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!