Centerline and bounding curve in image

7 次查看(过去 30 天)
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
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
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