Region Growing algorithm not working properly
1 次查看(过去 30 天)
显示 更早的评论
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)
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing and Computer Vision 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!