Clear Filters
Clear Filters

Region Growing algorithm not working properly

2 views (last 30 days)
I am implementing the region growing segmentation of 'ZhengGuoJin_03_0098_0180.png'. The segmentation result should look like 'seg.png', where the segmented region should be the region inside the red boundary. However, my segmentation result displays a completely black image. I think there might be leakage in my region growing algorithm although I am not sure about that. I have implemented the following lines of code.
l=imread('ZhengGuoJin_03_0098_0180.png');
figure,imshow(l)
grayImage = min(l, [], 3);
binaryImage = grayImage < 200;
binaryImage = bwareafilt(binaryImage, 1);
[rows, columns] = find(binaryImage);
row1 = min(rows);
row2 = max(rows);
col1 = min(columns);
col2 = max(columns);
% Crop
croppedImage = l(row1:row2, col1:col2, :);
figure,imshow(croppedImage)
croppedImage=rgb2gray(croppedImage);
boundaries = bwboundaries(croppedImage);
[xu, yu] = ginput(1);
minDistance = inf;
for k = 1 : numel(boundaries)
thisBoundary = boundaries{k};
x = thisBoundary(:, 2);
y = thisBoundary(:, 1);
distances = sqrt((x - xu).^2 + (y - yu).^2);
thisMinDistance = min(distances)
% If this one is the closest, log it.
if thisMinDistance < minDistance
minDistance = thisMinDistance;
selectedIndex = k;
end
end
fprintf('You chose boundary #%d.\n', selectedIndex);
% Highlight the one they picked.
thisBoundary = boundaries{selectedIndex};
x = thisBoundary(:, 2);
y = thisBoundary(:, 1);
hold on;
plot(x, y, 'm-', 'LineWidth', 2);
% x=256;y=256;
[x,y]=getpts;x=round(x);y=round(y);
a=imgaussfilt(croppedImage,2);
% a=rgb2gray(a);
b=adapthisteq(a);
m=regiongrowing_MLT(b,x,y,12);
m=imfill(m,'holes');
bw=imbinarize(m);
bw=bwareafilt(bw,1);
seg = region_seg(m, bw, 30);
figure, imshow(seg)
seg1=double(croppedImage).*double(seg);
figure, imshow(seg1)
img_class=class(l);
fill=cast(seg1,img_class);
figure, imshow(fill)

Accepted Answer

Image Analyst
Image Analyst on 6 Oct 2022
Try this
imshow(seg1, [])

More Answers (0)

Categories

Find more on Image Processing and Computer Vision in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!