MATLAB Answers

0

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

Asked by PhD Problems on 8 Jul 2019
Latest activity Commented on by Harshita Bhurat on 8 Nov 2019 at 18:18
[reposting this question as the previous one was very vague]
Im trying to segment the yellow region in the below image:
b4.jpg
To begin with I tried smoothing the image first by applying a Gaussian filter:
img = imread('sequence_1.tif');
img = imgaussfilt(img, 3);
smooth.jpg
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:
smoothed_yellow.jpg
But interestingly, the prurple region is segmented much better:
smoothed_purple.jpg
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_;
img_imadjust = img_lab;
img_imadjust(:,:,1) = imadjust(L)*max_;
img_imadjust = lab2rgb(img_imadjust);
But the image generated from this will do me no good after thresholding:
contrast.jpg
open to suggestions and help please.
Thanks

  0 Comments

Sign in to comment.

1 Answer

Answer by Steve Eddins on 8 Jul 2019
 Accepted Answer

I used the Color Thresholder app in the Image Processing Toolbox to give this a try.
rgb = imread('b4.jpeg');
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.
Screen Shot 2019-07-08 at 1.26.10 PM.png
Then you can use Export / Export Function to generate the corresponding MATLAB code.