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?".
My first question at imageMagick forum was honestly answered by very kind experts.
I hope my 2nd one will be the same. And once again, please correct me if I say something stupid
My problem was a bit complicated :
I have some colored texts & graphics on white background, like islands over the sea. (Let's suppose that each group of non-white pixels stands one by one - every pix is next to each other is an "ISLAND", and the white background is the SEA)
I need to get all the pixels' coordinates (x,y) of each ISLAND that exisiting on the SEA. Some thing like :
Do you want just the upper left corner and bounds of the region or do you want to see the coordinates of every pixel that is not white?
The latter can be done by simply using txt:- and filtering out all white pixels using something like grep -v or using sed.
The former could be done using my script, separate, to cut out each region. However, the script expects white regions on a black background. So you would have to negate your image first. Also it is a bash shell script and so you would need cygwin to run it on Windows. It may also need to be modified slightly to keep the virtual-canvas, so that you know the region size and offset. I think currently it throws that away using +repage.
fmw42 wrote:Do you want just the upper left corner and bounds of the region or do you want to see the coordinates of every pixel that is not white?
Yes, I need the coordinate of every pixel.
fmw42 wrote:
The latter can be done by simply using txt:- and filtering out all white pixels using something like grep -v or using sed.
The former could be done using my script, separate, to cut out each region. However, the script expects white regions on a black background. So you would have to negate your image first. Also it is a bash shell script and so you would need cygwin to run it on Windows. It may also need to be modified slightly to keep the virtual-canvas, so that you know the region size and offset. I think currently it throws that away using +repage.
I will spend times to read about Cygwin and your script for separation. I have to confess that I'm brand new to Imagemagick, and all what I've achieved so far have been made by JScript (similar to VBScript). But my code is extra slow (~1 mins to deal with a 1500x2300 png file), that's why I'm expecting a faster method from imageMagick.
I've achived the same result as your "separate-script" (by JScript) like this before :
-Replace all white pixels by transparent
-Export the colored-pixels' coordinate to a text file (as you suggested above)
- Read the text file & scan through all pixels
- Check each pixel to see if it's "next-door neighbour" of any other pixel. If true, push the new pixel to existing "ISLAND" of the neighbour pixel. Else, create a new "ISLAND".
Please let me know if your algorithm was the same as mine ( )
But, at all, thank you for your help very much !
Please let me know if your algorithm was the same as mine ( )
But, at all, thank you for your help very much !
Not really the same. And it may not be the fastest way. It makes a new image for each section.
But if it is modified so that it does not remove the virtual canvas, it can be made to tell you the bounding box coordinates. Then it could be modified further to tell you how many non-white pixels are in each bounding box. But it does not do any of the latter right now. See http://www.fmwconcepts.com/imagemagick/ ... /index.php or http://www.fmwconcepts.com/imagemagick/ ... /index.php (though this latter one is not designed to find small regions)
If you want every pixel but the background (say within XX% of white), you can do the following:
convert image -fuzz XX% -transparent white sparse-color:-
That will list out x,y,color for every non-transparent pixel. But it is new to 6.8.3-10.
Otherwise, the slower method is
convert image txt:- | grep -v "white"
It will not tell you each separate region without your further processing. But my script could be modified to just find each rectangular area and tell you the bounding box coordinates, and compute how many pixels are in each section.
the minus means send to standard out. You can leave the minus off. Try that and see if both work. If not, post a link to the file that does not work, so others can test with it.
fmw42 wrote:the minus means send to standard out. You can leave the minus off. Try that and see if both work. If not, post a link to the file that does not work, so others can test with it.
I tried these commands, but nothing was responded :
If that does not work for you be sure your IM version is at least 6.8.3.10. If your version is appropriate, then you need to report this on the bugs forum. Perhaps it did not get into the Windows build.
Otherwise, try the slower method
convert rose: -fuzz 80% -transparent red -background black -alpha background txt: | grep -v "none"