Region Growing algorithm not working properly

조회 수: 5 (최근 30일)
Warid Islam
Warid Islam 2022년 10월 6일
댓글: Warid Islam 2022년 10월 7일
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)

채택된 답변

Image Analyst
Image Analyst 2022년 10월 6일
Try this
imshow(seg1, [])

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by