Any way to polish / improve the output produced by the Lab colour space segmentation.
조회 수: 1 (최근 30일)
이전 댓글 표시
[reposting this question as the previous one was very vague]
Following the tutorial posted here: https://uk.mathworks.com/help/images/color-based-segmentation-using-the-l-a-b-color-space.html
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 = imread('sequence_1.tif');
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_;
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:
open to suggestions and help please.
Thanks
댓글 수: 0
채택된 답변
Steve Eddins
2019년 7월 8일
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.
Then you can use Export / Export Function to generate the corresponding MATLAB code.
댓글 수: 1
Harshita Bhurat
2019년 11월 8일
Here's a video that shows how to use the app -
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!