Page 1 of 1
How to the get the coordinates of pixels?
Posted: 2017-08-09T09:12:35-07:00
by etrader
I want to get the coordinates of the points in a line from an image to re-draw it.
I tried
Code: Select all
convert photo.png txt:- | sed -n 's/^\(.*\):.*black$/\1/p'
but it didn't work. I also tried to create white edges as
Code: Select all
convert photo.png -edge 1 -threshold 0 photo.png
convert photo2.png txt:- | sed -n 's/^\(.*\):.*white$/\1/p'
but it didn't work either. Where did I do wrong?
In any case, my ideal solution is to find a set of approximate points (probably from the center of the line) to have the full line coordinates.
Re: How to the get the coordinates of pixels?
Posted: 2017-08-09T09:41:21-07:00
by fmw42
try
Code: Select all
convert xpd2F2A.png -threshold 50% -type bilevel txt:- | tail -n +2 | sed -n 's/^\(.*\):.*gray(0)$/\1/p'
or
Code: Select all
convert xpd2F2A.png -threshold 50% -depth 1 txt:- | tail -n +2 | sed -n 's/^\(.*\):.*black$/\1/p'
or
Code: Select all
convert xpd2F2A.png -threshold 50% -depth 1 txt:- | tail -n +2 | grep "black" | sed -n 's/^\(.*\):.*$/\1/p'
Re: How to the get the coordinates of pixels?
Posted: 2017-08-09T10:19:30-07:00
by etrader
WOW, it worked like a charm. The key is that my points are not completely black and I have to use gray instead, right?
Re: How to the get the coordinates of pixels?
Posted: 2017-08-09T10:22:13-07:00
by fmw42
See my edits above. That is part of it. You need to threshold to make it binary. But different -type or different -depth will result in txt showing the color as gray(0) or black. You should always test your command up to the txt: to see what format you get for the color before filtering.
Note I corrected my first line. I had accidentally put gray(255) which is white and you wanted black or gray(0). I also forgot the -n and have added that.
Re: How to the get the coordinates of pixels?
Posted: 2017-08-09T10:28:44-07:00
by fmw42
If you only want the truly black pixels and not the near black ones, then you can do
Code: Select all
convert xpd2F2A.png txt:- | tail -n +2 | sed -n 's/^\(.*\):.*gray(0)$/\1/p'
Re: How to the get the coordinates of pixels?
Posted: 2017-08-09T11:28:12-07:00
by snibgo
IM version? Platform?
etrader wrote:In any case, my ideal solution is to find a set of approximate points (probably from the center of the line) to have the full line coordinates.
The centreline can be traced, and the line expressed as a series of Bezier curves, which IM can draw, or you can create SVG.
See my
Lines, points and curves page. I show how to do it, and give away the
essential software, but not the
complete software.
Code: Select all
%IM%convert oneLine.png -negate -threshold 50%% x.png
call %PICTBAT%lns2pts x.png x.txt
pts2bez /ix.txt /ob.txt
%IM%convert ^
-size 300x300 xc:White ^
-fill None ^
-draw @b.txt ^
redcurve.png
pts2bez /ix.txt /ob2.txt /e5
%IM%convert ^
-size 300x300 xc:White ^
-fill None ^
-draw @b2.txt ^
redcurve2.png
Re: How to the get the coordinates of pixels?
Posted: 2017-08-10T10:29:49-07:00
by etrader
snibgo wrote: ↑2017-08-09T11:28:12-07:00
IM version? Platform?
ImageMagick 6.8.9-9
Ubuntu 16.04