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*')

採用された回答

Bjorn Gustavsson
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 件のコメント
Max V
Max V 2021 年 11 月 17 日
編集済み: Max V 2021 年 11 月 17 日
@Image Analyst thank you for your response!
If I am to classify these images based on Texture analysis will the GCLM properties like Contrast, Correlation, Energy, Homogenity etc suffice or shall I also use LBP (Local Binary Pattern) and Law's Texture Energy Measures too for accuracy?
Bjorn Gustavsson
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
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*')
  1 件のコメント
Max V
Max V 2021 年 11 月 16 日
Thank you for taking time to reply @yanqi liu!
I want to also perform Shape Signature analysis by calculating the distance and angle from the centroid to the edge of the image.
Can you help/guide me on how to do it?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by