Hi Ahmed,
I understand that you are trying to segment two objects with similar colors.
I think you can achieve the same by performing simple colour thresholding in L*a*b* color space.
The L*a*b* color space is actually intended to quatify the perceived colors. Therefore, it serves useful in detecting small differences in color, which is exactly the application you are looking for.
In the following lines, please find the code and steps to generate the appropriate image segmentation as per your query.
- Save the following code as a MATLAB script named "createMask.m". This is auto-generated code from MATLAB's color thresholder app.
function [BW,maskedRGBImage] = createMask(RGB)
sliderBW = (I(:,:,1) >= channel1Min ) & (I(:,:,1) <= channel1Max) & ...
(I(:,:,2) >= channel2Min ) & (I(:,:,2) <= channel2Max) & ...
(I(:,:,3) >= channel3Min ) & (I(:,:,3) <= channel3Max);
maskedRGBImage(repmat(~BW,[1 1 3])) = 0;
- Then execute the following commands in MATLAB by substituting the <ImageName> with the image name that you want to segment:
rgb = imread('<ImageName>');
- The following are the outputs that I am able to achieve using the above code on the sample image that you have shared. First image shows the binarized output and second image is the segmented RGB Image.
-