Centerline and bounding curve in image
8 ビュー (過去 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.
0 件のコメント
採用された回答
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 件)
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
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!