Plotting dots on the edges of an object uniformly
5 次查看(过去 30 天)
显示 更早的评论
Hello, everyone. I wonder is it possible to distribute a specific number of dots on the edges of the acquired image. Think of a circle for instance, is it possible to distribute,like, 8 dots uniformly on the circle ? Note: As in the image i have uploaded. Red circles are the dots etc.(sorry for paint level image :3)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/159356/image.jpeg)
0 个评论
采纳的回答
Walter Roberson
2017-1-1
See http://www.mathworks.com/matlabcentral/answers/317921-distances-along-a-plotted-line#answer_248275
You would probably want to set marker_dist to dist_from_start(end)/N where N is the number of dots you want around the edge.
Note that that code does not try to put the markers at corners: it is code for placing the markers at equal distances along the path, where-ever that comes out to be.
2 个评论
Walter Roberson
2017-1-2
Hmmm, I remember fixing that at the time, but I do not remember what the fix I used then was. One fix would be
x = [0 5 10];
y = [2 4 1];
Number_of_divisions = 5;
dist_from_start = cumsum( [0, sqrt((x(2:end)-x(1:end-1)).^2 + (y(2:end)-y(1:end-1)).^2)] );
a = dist_from_start(end)/Number_of_divisions;
marker_dist = a;
marker_locs = marker_dist : marker_dist : dist_from_start(end); %replace with specific distances if desired
marker_indices = interp1( dist_from_start, 1 : length(dist_from_start), marker_locs);
marker_base_pos = floor(marker_indices);
weight_second = marker_indices - marker_base_pos;
mask = marker_base_pos < length(dist_from_start);
final_x = x(end); final_y = y(end);
final_marker = any(~mask) & (x(1) ~= final_x | y(1) ~= final_y);
marker_x = [x(1), x(marker_base_pos(mask)) .* (1-weight_second(mask)) + x(marker_base_pos(mask)+1) .* weight_second(mask), final_x(final_marker)];
marker_y = [y(1), y(marker_base_pos(mask)) .* (1-weight_second(mask)) + y(marker_base_pos(mask)+1) .* weight_second(mask), final_y(final_marker)];
plot(x, y, marker_x, marker_y, 'r+');
This code also checks to see if the curve is (exactly) closed and in that case avoids plotting the marker twice (because there is already a marker there from the plot from the beginning.)
更多回答(1 个)
Image Analyst
2017-1-2
See interparc http://www.mathworks.com/matlabcentral/fileexchange/34874-interparc by John D'Errico. It works for arbitrarily shaped curves in 2D as well as circles.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176379/image.jpeg)
1 个评论
Walter Roberson
2017-1-2
Note: a difference between my code and John's is that my code treats the points as a series of line segments that the markers must sit on, whereas John's code treats the points a subsampling of a curve and interpolates the curve, a more difficult task.
My code is suitable for the case where the points define the path, such as the situation of a vehicle traveling at constant velocity along a map.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Modify Image Colors 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!