i need to grade the mangoes based on matured level.

1 次查看(过去 30 天)
i need to grade the mango based on mature level. How can i get the RGb value for the overall mangoes to make it separated based on the value. and im using webcam to snap the picture
this is my coding now
cam = webcam(1);
I = snapshot(cam);
imshow(I);
clear cam;
RGB = imresize(I,[100 100]);
subplot(2,2,[1,2]), imshow(I);
%yellow
maskYellow = makeMaskYellow(RGB);
yellowArea = bwarea(maskYellow)
yellow = bsxfun(@times, RGB, cast(maskYellow, 'like', RGB));
subplot(2,2,3), imshow(yellow);
%green
maskGreen = makeMaskGreen(RGB);
greenArea = bwarea(maskGreen)
green = bsxfun(@times, RGB, cast(maskGreen, 'like', RGB));
subplot(2,2,4), imshow(green);
if yellowArea > greenArea
msgbox('Yellow')
else
msgbox('Green')
end
  1 个评论
DGM
DGM 2022-6-5
If you're asking how to find the mean color within the masked regions, you can do:
meanyellow = RGB(repmat(maskYellow,[1 1 3]));
meanyellow = mean(reshape(meanyellow,[],3),1)
otherwise, you'll have to clarify what specifically you're trying to do, what your user-defined functions are, and what your images look like.

请先登录,再进行评论。

回答(1 个)

prabhat kumar sharma
Hi jie
I assume that you are encountering issues in finding the RGB values for the overall mangoes, whether they are yellow or green.
Please refer to the following code snippet for reference:
% Obtain RGB values for the overall mangoes
overallMangoes = bsxfun(@times, RGB, cast(maskYellow | maskGreen, 'like', RGB));
overallMangoes = reshape(overallMangoes, [], 3); % Reshape to N-by-3 matrix
RGBValues = unique(overallMangoes, 'rows');
disp(RGBValues);
In this code, the “overallMangoes” matrix is created by applying the logical OR (|) operation to the "maskYellow" and "maskGreen" matrices.
This combined mask is then used to select the corresponding RGB values from the original image (RGB). The resulting RGB values are reshaped into an N-by-3 matrix, where each row represents an RGB value. The “unique“ function is then used to obtain the unique RGB values, and they are displayed using disp.
Regards,
Prabhat Sharma
  1 个评论
Image Analyst
Image Analyst 2023-10-10
I think the real problem was how to segment out only mangos in a cluttered image (like with leaves and still on the tree) regardless of what color they are. Even if they were already picked and laying on a black tabletop, you'd still have to segment them out (create a mask), regardless of what color they are. Unfortunately @jie tarmizi didn't/doesn't really care because no images were ever uploaded.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by