I need a faster way to generate locations of white pixels

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
dgpeters
Posts: 19
Joined: 2013-09-10T15:47:00-07:00
Authentication code: 6789

I need a faster way to generate locations of white pixels

Post by dgpeters » 2013-09-29T12:16:56-07:00

I need to display the locations of all the white pixels in my monochrome PNG file (i.e., identify reports it as: trythis3.png PNG 769x550 769x550+0+0 8-bit sRGB 2c 6.14KB 0.000u 0:00.000). I've got something that works: "convert trythis3.png sparse-color:- | tr ' ' '\n' | grep white" but I find it to take about 3 seconds per file which I think is slower than it needs to be. I read somewhere that there is a preferred (and faster) way to generate the information but I can't remember the other method. Basically I need the X,Y locations of all the white pixels. Like this:

10,11
12,13
1500,2021

Once again thanks to the author of this spectacular program.

snibgo
Posts: 12311
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: I need a faster way to generate locations of white pixel

Post by snibgo » 2013-09-29T12:28:11-07:00

Make everything other than white transparent first. See viewtopic.php?f=1&t=24095
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 25664
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: I need a faster way to generate locations of white pixel

Post by fmw42 » 2013-09-29T13:11:48-07:00

snibgo wrote:Make everything other than white transparent first. See viewtopic.php?f=1&t=24095
A more specific reference that user snibgo is referring is to the use of sparce-color: at viewtopic.php?f=1&t=24095#p102822

This is what you are using and was written to speed up such output rather than filter on txt: output format. So it is as fast is it can get. You need to make all other pixels transparent first (-fuzz XX% +transparent white) as user snibgo suggested. That will make the process much faster to extract only the white pixels.

The original slower method was

convert image txt: | grep "white" ...

Post Reply