Region Growing algorithm not working properly
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Warid Islam
le 6 Oct 2022
Commenté : Warid Islam
le 7 Oct 2022
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 commentaires
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Processing Toolbox dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!