Threshold Image Segmentation with different contrasts
Show older comments
Hey there,
I am trying to make some easy image segmentation for a lot of images like the test_image above. The resolution of the image is quite bad. Now my question: I am trying to separate it with an easy threshold segmentation, but there are too many parameters that I have to adjust for images with different contrasts. Is there a more easy and accurate way to separate the black parts within the white circle?
Thanks a lot for your help!
Here is my code:
[filelist, pathname] = uigetfile({'*.jpg';'*.tif';'*.bmp';'*.png'}, ...
'Select Folder', 'MultiSelect', 'on');
data_in = imread([pathname,filename]);
images(:,:,1) = rgb2gray(data_in);
[x,y,z] = size(images);
bw = (30 <= images(:,:,1)) & (images(:,:,1) <= 190);
bw2 = bwpropfilt(bw,'Area',[20,Inf]);
bw2 = ~bwareaopen(~bw2, 80);
mask = imfill(bw2, 'holes');
se = strel('disk', 20, 0); % Adjust to erase outer ring
mask = imerode(mask, se);
bw2(~mask) = false;
figure, imshow(bw2);
Answers (0)
Categories
Find more on Image Segmentation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!