Mean line of object boundary
Mostra commenti meno recenti

I have sample picture as above. I want to find average line of this object. Who have any idea to do that?
1 Commento
Mohammad Abouali
il 2 Gen 2015
could you provide each border as a separate image?
Risposta accettata
Più risposte (1)
Image Analyst
il 3 Gen 2015
0 voti
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 Commenti
Montree
il 3 Gen 2015
Image Analyst
il 3 Gen 2015
I think you misunderstood or didn't think it through so maybe I need to give it in a little more detail.
- First of all, find the centroid, and you did that so that's good.
- Next, use interp1() to make sure each list has the same number of elements in it. That's important because we need to align them and take the average and we can't do that unless they have the same number of elements in them. (You might plot the resized outlines again just to make sure they look right.)
- Next, find the y value for each coordinate list that is closest to the centroid, and then use circshift() to align them all so that element 1 is the same line (same Y value). This is probably the trickiest part but I'm sure you can handle it.
- Now convert each list to radii with cart2pol() and knowledge of where the radii are.
- Then average the 3 lists of radii. Now we have the average radii for each element.
- Now use pol2cart() and the centroid location to turn the average radii into outline curves.
Post your code and data, or output image, so we can verify that you did it correctly.
Mohammad Abouali
il 3 Gen 2015
Can you upload the three BW images containing each border in a separate image?
Image Analyst
il 4 Gen 2015
Seems like you're still having trouble, or else you're just enjoying something else over the weekend. So I've done steps 4, 5, and 6 for you, in the latter part of this code. The first half is just code to get the curves (because you didn't supply me with any data).
clear all;
close all;
clc;
xCenter = 12;
yCenter = 10;
theta = 0 : 0.1 : 2*pi;
radius = 5;
x = radius * cos(theta) + xCenter;
y = radius * sin(theta) + yCenter;
plot(x, y, 'k-');
axis square;
xlim([6 18]);
ylim([4 18]);
grid on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get 3 wiggly circles for sample data
amplitude = .8;
x1 = x + amplitude * rand(size(x)) - amplitude/2;
y1 = y + amplitude * rand(size(y)) - amplitude/2;
x2 = x + amplitude * rand(size(x)) - amplitude/2;
y2 = y + amplitude * rand(size(y)) - amplitude/2;
x3 = x + amplitude * rand(size(x)) - amplitude/2;
y3 = y + amplitude * rand(size(y)) - amplitude/2;
hold on;
plot(x1,y1, 'r-', 'LineWidth', 2);
plot(x2,y2, 'g-', 'LineWidth', 2);
plot(x3,y3, 'b-', 'LineWidth', 2);
% x1, y1, x2, y2, and x3, y3 are our three curves.
% Now do steps 4, 5, and 6 of my algorithm in the prior comment.
% Now find the distances of each point from the centroid.
radii1 = sqrt((x1 - xCenter).^2 + (y1 - yCenter).^2);
radii2 = sqrt((x2 - xCenter).^2 + (y2 - yCenter).^2);
radii3 = sqrt((x3 - xCenter).^2 + (y3 - yCenter).^2);
% Get the average radii
averageRadii = (radii1 + radii2 + radii3) / 3;
% Get the new mean circle
xMean = averageRadii .* cos(theta) + xCenter;
yMean = averageRadii .* sin(theta) + yCenter;
figure
plot(xMean, yMean, 'k-', 'LineWidth', 2);
axis square;
xlim([6 18]);
ylim([4 18]);
grid on;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
Montree
il 4 Gen 2015
Montree
il 4 Gen 2015
Categorie
Scopri di più su Image Arithmetic in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



