Mean line of object boundary

3 次查看(过去 30 天)
I have sample picture as above. I want to find average line of this object. Who have any idea to do that?

采纳的回答

Mohammad Abouali
Mohammad Abouali 2015-1-4
Another Approach could be this:
B1=bwmorph(logical( round( double(imread('1_1.bmp'))/255 ) ),'skel','inf');
B2=bwmorph(logical( round( double(imread('1_2.bmp'))/255 ) ),'skel','inf');
B3=bwmorph(logical( round( double(imread('1_3.bmp'))/255 ) ),'skel','inf');
D1=bwdist(B1);
D2=bwdist(B2);
D3=bwdist(B3);
D=D1+D2+D3;
mask=bwmorph(bwmorph(D<50,'thin','inf'),'spur',100);
FinalImage(:,:,1)=B1+mask;
FinalImage(:,:,2)=B2+mask;
FinalImage(:,:,3)=B3+mask;
Although I have to mention that this is not averaging the borders. The resulting border is the white line in the following image:
  2 个评论
Montree
Montree 2015-1-4
Woww...amazing!!!
Thank very much.
Image Analyst
Image Analyst 2015-1-5
Looks like you're all set. If you do want the average though, you can still use my code.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2015-1-3
How about this method:
Convert to binary images and AND them then find the centroid and send out rays from the centroid to each perimeter to find the radii. Then average the radii. Could use cart2pol and pol2cart to help.
Can you supply the 3 lists of (x,y) or (row, column) coordinates?
  6 个评论
Montree
Montree 2015-1-4
Sory for late. Thank very much for your answer. This 3 image are sample data.
I follow your step and have a problem as below...
1. I find coordinate of line by use 'bwboundaries' function. The number of element of all line have difference number. So I use 'interp1' for resampling data (the number refer to maximum number of element.) and I have found this error 'The grid vectors are not strictly monotonic increasing.', I solve this problem by add small value to the same value such as.. [9 9] --> [9 9.0001] It can fix but....
(I use 1_1.bmp for testing) 'interp1' can use method 'nearest' only (other method not work) and I cannot solve this problem.
2. I think, I understand your concept but...
2.1) In picture 1. How you can make sure x, y and z are the sequence in them array. if the sequence of x, y and z are difference, your algorithm will have error.
2.2) If you can solve the problem in (2.1), you can calculate mean line by calculate mean of 3 position, this is true. But when the line parallel the radii line (same as picture 2) the mean position of x, y and z cannot calculate from mean of radii but you must calculate it from meaning of theta of 3 point. Do you think same as me? But this problem easy to solve by calculate mean of radii and theta.
Sorry for my english, hope you understand.
Montree
Montree 2015-1-4
This is my code but it is not complete...
clc
clear
%%load image
PIC1 = imread('sample_photo\1_1.bmp');
PIC2 = imread('sample_photo\1_2.bmp');
PIC3 = imread('sample_photo\1_3.bmp');
%%modify edge line
bw1 = im2bw(PIC1);
bw1 = imfill(bw1,'holes');
bw1 = edge(bw1);
bw2 = im2bw(PIC2);
bw2 = imfill(bw2,'holes');
bw2 = edge(bw2);
bw3 = im2bw(PIC3);
bw3 = imfill(bw3,'holes');
bw3 = edge(bw3);
nbw = bw1+bw2+bw3;
%%find centroid of all
stat1 = regionprops(bw1,'centroid');
stat2 = regionprops(bw2,'centroid');
stat3 = regionprops(bw3,'centroid');
cent1 = stat1.Centroid;
cent2 = stat2.Centroid;
cent3 = stat3.Centroid;
%%find coordinate of all line
B1 = bwboundaries(bw1);
B2 = bwboundaries(bw2);
B3 = bwboundaries(bw3);
Line1 = B1{1};
Line2 = B2{1};
Line3 = B3{1};
Line = {Line1,Line2,Line3};
%%Iterpolate (make sure all line have same number of element)
% resampling all line to 1000 element
Xmin = min(Line1(:,2));
Xmax = max(Line1(:,2));
X = linspace(Xmin,Xmax,500);
LX = Line1(:,2)';
LY = Line1(:,1)';
UXL = 0;
UYL = 0;
while(UXL<length(LX))
[UX,ia,ic] = unique(LX,'stable');
LX(ia) = LX(ia)+1e-4;
UXL = length(UX);
end
while(UYL<length(LY))
[UY,ia,ic] = unique(LY,'stable');
LY(ia) = LY(ia)+1e-4;
UYL = length(UY);
end
Y = interp1(LX,LY,X,'nearest');
imshow(bw1);
hold on;
plot(X,Y,'ob')

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Lighting, Transparency, and Shading 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by