Centerline and bounding curve in image

8 ビュー (過去 30 日間)
Prabhat Srivastava
Prabhat Srivastava 2021 年 1 月 9 日
I have an Image to which I want to fit a centerline and extract the bounding curves of the object. Here is the image and the best that I could manage with my code.
I = img(501:3500,501:5500);
im_bin = imbinarize(I);
se = strel('disk',3);
opened_im = imopen(im_bin,se);
BWdfill= imfill(opened_im, 4,'holes');
BWoutline= bwperim(BWdfill);
Segout = I;
Segout(BWoutline) = 255;
for indx = 1:5000
temp = find(BWoutline(:,indx)==1);
if isempty(temp)==1
temp= NaN;
else
end
top(indx) = max(temp);
bottom(indx) = min(temp);
end
top_temp = sgolayfilt(top,polsgf, winsgf);
top1 = fillmissing(top_temp,'movmedian',10);
bottom_temp = sgolayfilt(bottom, polsgf, winsgf);
bottom1 = fillmissing(bottom_temp,'movmedian',10);
[maxR, Idx1] = max(I,[],1);
const1 = mean(Idx1,"omitnan");
for k = 1:length(Idx1)
if Idx1(:,k) == 1
Idx1(:,k) = NaN;
else
end
end
Idx1 = fillmissing(Idx1,"constant",const1) ;
Cline = sgolayfilt(Idx1, polsgf, winsgf);
Ignore the white line in the output image that is a scale bar.

採用された回答

Roy Kadesh
Roy Kadesh 2021 年 1 月 9 日
If this complex code doesn't work, can't you try something easy?
img=imread('1.png');
I = img(501:3500,501:5500);
im_bin = imbinarize(I);
mmm=zeros(size(im_bin,2),3);
for col=1:size(im_bin,2)
ind=find(im_bin(:,col));
mmm(col,:)=[min(ind) mean(ind) max(ind)];
end
figure(1),clf(1)
imshow(I)
hold on
plot(mmm)
This works better and should be easier to fine-tune.
  1 件のコメント
Prabhat Srivastava
Prabhat Srivastava 2021 年 1 月 9 日
編集済み: Prabhat Srivastava 2021 年 1 月 9 日
Thank you. I have tried this. I have a number of such images so algorithm fails in some images because they don't have consistent structure. The process that you have suggested is what I am trying too. This certainly is more elegant than mine. Thank you very much.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 1 月 9 日
You can either scan the image columns, or use bwskel. In the attached code I do it both ways.
If you want, you could smooth the rows.
  3 件のコメント
Image Analyst
Image Analyst 2021 年 1 月 9 日
The advantage of the skeleton is that the center will be the center even if the blob is tilted (if that's what you want). The scanning method only looks in the vertical direction (1-D), not 2-D like the skeleton. These approaches could differ at times in where they find the centerline, with the skeleton being the more accurate way. Imagine if your blob had a shape like a C or an S instead of something horizontal. What would the column scanning way give you? Yeah, exactly -- now you get it. A line straight through the half way point vertically (actually even goes outside the blob itself), it will NOT be a centerline following the curve that is the blob. So, beware.
Prabhat Srivastava
Prabhat Srivastava 2021 年 1 月 9 日
I see!! Sure, I will experiment with these to see which one gisve the best estimation. Thank you.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by