color apple fruit segmentation
4 次查看(过去 30 天)
显示 更早的评论
Dear sir, Good afternoon, I have faced some problems about fruits(different kinds of fruits) segmentation. Could you please help me sir? The example image is as below:
I want to remove leaf and a branch of it together, and i want to get only the shape of apples. Thanks all;
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/157849/image.jpeg)
0 个评论
回答(2 个)
Image Analyst
2016-11-9
See my color segmentation demos in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862.
You cannot know for certain the shape behind the leaf because it is not visible. However if you want to assume that the shape is convex, you can use bwconvhull() to make a convex apple and it will "draw a line" across under where the leaf is.
0 个评论
Image Analyst
2016-11-9
From the Color Thresholder app on the Apps Tab of the tool ribbon:
function [BW,maskedRGBImage] = createMask(RGB)
%createMask Threshold RGB image using auto-generated code from colorThresholder app.
% [BW,MASKEDRGBIMAGE] = createMask(RGB) thresholds image RGB using
% auto-generated code from the colorThresholder App. The colorspace and
% minimum/maximum values for each channel of the colorspace were set in the
% App and result in a binary mask BW and a composite image maskedRGBImage,
% which shows the original RGB image values under the mask BW.
% Auto-generated by colorThresholder app on 09-Nov-2016
%------------------------------------------------------
% Convert RGB image to chosen color space
I = rgb2hsv(RGB);
% Define thresholds for channel 1 based on histogram settings
channel1Min = 0.886;
channel1Max = 0.133;
% Define thresholds for channel 2 based on histogram settings
channel2Min = 0.308;
channel2Max = 1.000;
% Define thresholds for channel 3 based on histogram settings
channel3Min = 0.000;
channel3Max = 0.974;
% Create mask based on chosen histogram thresholds
sliderBW = ( (I(:,:,1) >= channel1Min) | (I(:,:,1) <= channel1Max) ) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
BW = sliderBW;
% Initialize output masked image based on input image.
maskedRGBImage = RGB;
% Set background pixels where BW is false to zero.
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
end
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!