Page 1 of 1

Need to map pixels: how to speed up txt: output ?

Posted: 2011-10-15T20:48:22-07:00
by homer314
Hi all

i need to create an edges pixel map using some BIG images and the txt: output takes a lot of time to write the file.

What i'm doing now is to convert the image with

Code: Select all

convert in.png -alpha extract -edge 1 out.png
and then

Code: Select all

convert out.png txt: | ... 
with the varius grep and sed arguments to extract white pixels coordinates, but commands must to read hundreds of input lines every time, causing slow elaboration.

So is there a way for a FAST edges-only pixel mapping on BIG images ?

Really thank's

Re: Need to map pixels: how to speed up txt: output ?

Posted: 2011-10-15T21:52:00-07:00
by fmw42
what is your exact command using grep and sed, etc.?

You might be able to convert much of that into using AWK, which may be faster.

Re: Need to map pixels: how to speed up txt: output ?

Posted: 2011-10-16T00:42:35-07:00
by homer314
fmw42 wrote:what is your exact command using grep and sed, etc.?

You might be able to convert much of that into using AWK, which may be faster.
Thank's for answer, i use

Code: Select all

convert $f txt: | sed 's/ *,/,/g' | grep "white" | cut -d: -f1 
to extract white pixels coordinates.

There's no way to tell to IM txt output to work only on white pixel directly, without creating a very large number of line input for grep, sed, or awk?

Thank's

Re: Need to map pixels: how to speed up txt: output ?

Posted: 2011-10-16T11:00:22-07:00
by fmw42
You may be able to speed it up a bit by putting the grep "white" first. You can also speed it up by combining the sed and cut commands into an sed search and replace.

try this

convert rose: txt: | grep "white" | sed -n 's/^\(.*\):.*$/\1/p'

Re: Need to map pixels: how to speed up txt: output ?

Posted: 2011-10-19T17:39:04-07:00
by homer314
Thank's, just another little question:

i use "-alpha extract -edge 1" (tried also higher edge values) to create the black and white png to use to extact pixel coordinates and all is working fine expect in a case.

If i've a circle selection, edges ar cutted out on borders, like in the example


Image

It is possibile to prevent this ?

Thank's

Re: Need to map pixels: how to speed up txt: output ?

Posted: 2011-10-19T18:07:31-07:00
by fmw42
try padding the image with whatever is the background color

find the background color before edges are extracted, I presume black for now.


convert in.png -alpha extract -gravity center -bordercolor black -border 2 -edge 1 out.png

Re: Need to map pixels: how to speed up txt: output ?

Posted: 2011-10-20T00:49:55-07:00
by anthony
The edge dector will generall get either the inside edge, or the outside edge, depending on which is lighter or darker. Looks like you detected the outside of the edge.

If you negate the image before doing the edge effect the edge will go in the oppisite direction.

See IM Examples, transforms, Edge
http://www.imagemagick.org/Usage/transform/#edge

Alternative, just draw the circle using -fill none -stroke {color}

If you need it absolutely balck and white (bitmap), then you need to threshold the image to remove 'grays'.

Give the command you are using and we can help further!

Re: Need to map pixels: how to speed up txt: output ?

Posted: 2011-10-20T01:49:00-07:00
by homer314
ok, these are my steps:

starting from this image for example (imageshack upload remove my alpha channel but you consider it)

Image

i need to find the edge's pixels coordinates so:

Code: Select all

convert $im_in -resize "$weight_dpi"x"$height_dpi" \ #I RESIZE THE IMAGE TO 96DPI TO SPEED UP THE TXT OUTPUT EXTRACTION
        -alpha extract -edge 1 \ #THIS CREATES THE IMAGE IN THE FIRST  POST
        -crop 1x"$lines"@ +repage +adjoin tmp_%d.png; #I DON'T NEED ALL EDGES PIXELS, BUT JUST THE MAX AND MIN "X" FOR EVERY OF THESE SLICES

...then i use txt: output on every slice
The code above works fine with all the tests images i tried, except when there is an image with "non closing edges"

Really sorry for my bad english, and really realy thank's for help

Re: Need to map pixels: how to speed up txt: output ?

Posted: 2011-10-20T20:27:17-07:00
by anthony
You could just take the image then using -trim.
By reading the resulting virtual canvas information you will get you X and Y 'bounds'.

Code: Select all

convert image.png -trim -format -format 'MinY = %X  MinY = %Y MaxX = %X+%w-1 MaxY = %Y+%h-1 ' info:
You can use %[fx:...] formulas to do the calculation too. Or just output the 'crop' that -trim applied which is simply...

Code: Select all

convert image.png -trim -format -format '%wx%h%O' info:

Re: Need to map pixels: how to speed up txt: output ?

Posted: 2011-10-25T09:46:24-07:00
by homer314
Really really thanks for all of these helpful tips :)