Mean line of object boundary

3 visualizaciones (últimos 30 días)
Montree
Montree el 2 de En. de 2015
Comentada: Image Analyst el 5 de En. de 2015
I have sample picture as above. I want to find average line of this object. Who have any idea to do that?
  1 comentario
Mohammad Abouali
Mohammad Abouali el 2 de En. de 2015
could you provide each border as a separate image?

Iniciar sesión para comentar.

Respuesta aceptada

Mohammad Abouali
Mohammad Abouali el 4 de En. de 2015
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 comentarios
Montree
Montree el 4 de En. de 2015
Woww...amazing!!!
Thank very much.
Image Analyst
Image Analyst el 5 de En. de 2015
Looks like you're all set. If you do want the average though, you can still use my code.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 3 de En. de 2015
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 comentarios
Montree
Montree el 4 de En. de 2015
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 el 4 de En. de 2015
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')

Iniciar sesión para comentar.

Categorías

Más información sobre Lighting, Transparency, and Shading en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by