How do I reduce the number of points in a plotted trace?
Show older comments
Hello,
I am trying to create an algorithm that converts an image of a black and white tracing into a plot. So far, my code can convert the image into points using the code:
lion = imread('lion.png')
r = 1024;
c = 768;
count = 1;
for i = 1:r
for j = 1:c
if lion(i,j,1) ~= 255
%lion
lion_y(count) = -i + 1000;
lion_x(count) = j;
end
count = count + 1;
end
end
plot(lion_x,-lion_y,'.')
It can successfully convert the png into plotted points (I have attached the png to this posting as well):
--->
But, when zooming in, the line is composed of multiple points to make it appear thicker:

How would I create a trace of these points (perhaps some sort of average?) so that the image can be reduced to a single-point width?
so that the final image would look something like this:

This was made by manually outlining the trace using ginput(). This is not the ideal approach because it is not as accurate and it would be time consuming for processing over 100 images. Is there a way to automate this process?
I tried using the boundry function but it did not capture the details inside the image. It also didn't have a high enough resolution to capture the sharp edges (like in the mane).
Thank you for your help!
Accepted Answer
More Answers (0)
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





