![Screen Shot 2019-07-08 at 1.26.10 PM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/228029/Screen%20Shot%202019-07-08%20at%201.26.10%20PM.png)
Any way to polish / improve the output produced by the Lab colour space segmentation.
2 ビュー (過去 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:
![b4.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/227979/b4.jpeg)
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/227980/smooth.jpeg)
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/227981/smoothed_yellow.jpeg)
But interestingly, the prurple region is segmented much better:
![smoothed_purple.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/227982/smoothed_purple.jpeg)
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/227983/contrast.jpeg)
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.
![Screen Shot 2019-07-08 at 1.26.10 PM.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/228029/Screen%20Shot%202019-07-08%20at%201.26.10%20PM.png)
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 件)
参考
カテゴリ
Help Center および File Exchange で Image Segmentation and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!