color apple fruit segmentation
7 views (last 30 days)
Show older comments
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;
0 Comments
Answers (2)
Image Analyst
on 9 Nov 2016
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 Comments
Image Analyst
on 9 Nov 2016
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 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!