How to segment image without losing information at the edges for finding centroid?
1 回表示 (過去 30 日間)
古いコメントを表示
I have the following image and when I segment and fill it, I'm getting some error which ends up in the image having mutiple centroids.
How to I fix it make sure that I get only one centroid for the entire image. I have attached the code of my progress till now
clc;clear;close all;
I=imread("Abdomen CT.jpeg");I=im2gray(I);
imshow(I); title('Original Image')
level = graythresh(I);
BW = imbinarize(I,'adaptive','Sensitivity',level,"ForegroundPolarity","dark");
imshow(BW,[]); title('Segmented Image')
BW2 = imfill(BW,'holes');
figure
imshow(BW2)
title('Filled Image')
Trace region boundaries in binary image
[B,L] = bwboundaries(BW,'noholes');
imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
end
Centroid calculation
s = regionprops(BW,'centroid');
centroids = cat(1,s.Centroid);
plot(centroids(:,1),centroids(:,2),'b*')
0 件のコメント
採用された回答
Bjorn Gustavsson
2021 年 11 月 16 日
The only way I can imagine the meaning of centroid in a grayscale image like the one above is with the same definition as "centre of mass" has. For that you could do something like this:
[X,Y] = meshgrid(1:size(I,2),1:size(I,1));
Id = double(I)
r_centroid = [sum(X(:).*Id(:)),sum(Y(:).*Id(:))]/sum(Id(:));
This would properly give you a centre-of-brightness of the abdominal slice, which is not dependent on any arbitrary thresholding:
HTH
6 件のコメント
Bjorn Gustavsson
2021 年 11 月 17 日
@Max V: In the example image you've presented the only "Local Binary Pattern"s I can see are the regions with 2-pixel-wide interference-like patterns (either from the CT-operation, too sparse number of projections or too high noise-level), or from a horrendously rough jpeg-compression. Here you'll have to settle for size, orientation, shape and widths of the different regions, you could perhaps take brightness-profiles of the different regions at the narrowest point.
その他の回答 (1 件)
yanqi liu
2021 年 11 月 16 日
sir,may be use imclose to one block area
clc;clear all;close all;
I=imread("https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/802049/Abdomen%20CT.jpeg");
if ndims(I)==3
I=rgb2gray(I);
end
imshow(I); title('Original Image')
level = graythresh(I);
BW = imbinarize(I,'adaptive','Sensitivity',level,"ForegroundPolarity","dark");
imshow(BW,[]); title('Segmented Image')
BW2 = imfill(BW,'holes');
figure
imshow(BW2); hold on;
title('Filled Image')
s = regionprops(BW2,'centroid');
centroids = cat(1,s.Centroid);
plot(centroids(:,1),centroids(:,2),'b*')
% close bw
BW3 = imclose(BW2, strel('disk', round(mean(size(I)/2))));
figure
imshow(BW3); hold on;
title('Closed Image')
s = regionprops(BW3,'centroid');
centroids3 = cat(1,s.Centroid);
plot(centroids3(:,1),centroids3(:,2),'r*')
% distance
dis = centroids - repmat(centroids3(1,:), size(centroids,1), 1);
dis = dis(:,1).^2 + dis(:,2).^2;
[~,ind] = min(dis);
% display
figure;
imshow(BW2); hold on;
title('Filled Image')
s = regionprops(BW2,'centroid');
plot(centroids(ind,1),centroids(ind,2),'r*')
参考
カテゴリ
Help Center および File Exchange で Image Segmentation and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!