# Any way to polish / improve the output produced by the Lab colour space segmentation.

4 views (last 30 days)
PhD Problems on 8 Jul 2019
Commented: Harshita Bhurat on 8 Nov 2019
[reposting this question as the previous one was very vague]
Im trying to segment the yellow region in the below image: To begin with I tried smoothing the image first by applying a Gaussian filter:
img = imgaussfilt(img, 3); imshow(img)
nColors = 3;
sample_regions = false([size(img,1) size(img,2) nColors]);
for count = 1:nColors
sample_regions(:,:,count) = roipoly;
end
lab_img = rgb2lab(img);
a = lab_img(:,:,2);
b = lab_img(:,:,3);
color_markers = zeros([nColors, 2]);
for count = 1:nColors
color_markers(count,1) = mean2(a(sample_regions(:,:,count)));
color_markers(count,2) = mean2(b(sample_regions(:,:,count)));
end
color_labels = 0:nColors-1;
a = double(a);
b = double(b);
distance = zeros([size(a), nColors]);
for count = 1:nColors
distance(:,:,count) = ( (a - color_markers(count,1)).^2 + ...
(b - color_markers(count,2)).^2 ).^0.5;
end
[~,label] = min(distance,[],3);
label = color_labels(label);
clear distance;
rgb_label = repmat(label,[1 1 3]);
segmented_images = zeros([size(img), nColors],'uint8');
for count = 1:nColors
color = img;
color(rgb_label ~= color_labels(count)) = 0;
segmented_images(:,:,:,count) = color;
end
The regions were marked manually using roipoly. I understand that the way this works is that it calculates the distance between each pixel and the marker and that once the regions are marked I can save them and load them for every image as done in the tutorial.
My region of interest is segmented poorly, as can be seen: But interestingly, the prurple region is segmented much better: Now for my question, looking at the results, I see it would be easier for me to improve the purple segmentation results and use that as a mask rather than focusing on the yellow region, but even in the purple image there are regions wrongly classified. This will create problems with masking for the yellow region.
Any idea how I can further improve this?
What else have I tried?
I also tried contrast enhancement on this in hopes that maybe thresholding after contrast enhancement would do the trick:
img_lab = rgb2lab(img);
max_ = 100;
L = img_lab(:,:,1)/max_;
But the image generated from this will do me no good after thresholding: open to suggestions and help please.
Thanks

Steve Eddins on 8 Jul 2019
I used the Color Thresholder app in the Image Processing Toolbox to give this a try.
colorThresholder(rgb)
I set up the tool to use the L*a*b* color space, and then I played with the a* and b* sliders. I got a reasonable segmentation (I think!) of your yellow region using only the b* slider. Then you can use Export / Export Function to generate the corresponding MATLAB code.
Harshita Bhurat on 8 Nov 2019