Finding corner pixels in multiple images

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
miguellint
Posts: 22
Joined: 2015-09-27T20:26:53-07:00
Authentication code: 1151

Finding corner pixels in multiple images

Post by miguellint »

Hello...

In an earlier thread I found the following reply...

Try -fuzz 1% -fill black -floodfill +0+0 white
and repeat the flood fill on each corner pixel.


viewtopic.php?t=17659#p66613

How do I find each corner pixel when I have multiple images of varying sizes.

I was trying to use gravity (NorthEast, SouthEast, SouthWest) but was unsuccessful.

I think I need something to find width-1 and height-1

Advice appreciated.

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

Re: Finding corner pixels in multiple images

Post by fmw42 »

use -gravity with

Code: Select all

-gravity XX -fuzz 1% -fill black -draw "color 0,0 floodfill"
miguellint
Posts: 22
Joined: 2015-09-27T20:26:53-07:00
Authentication code: 1151

Re: Finding corner pixels in multiple images

Post by miguellint »

Hello Fred...

Thank you for the reply.

The command you gave was the same command I thought would do the trick but no matter which gravity I try the floodfill always starts in the NorthWest corner.

Here is a link to a stock image of a black diamond. The link is on Dropbox so just X the Register/Sign-In pop-up.

http://tinyurl.com/qcoz6ul

All I'm trying to do is black floodfill the SouthEast corner. Then I'd like to use the same command on identical images but of varying sizes.

The following command simply fills the NorthWest corner, not the SouthEast corner as expected.

Code: Select all

convert black_diamond.jpg -gravity SouthEast  -fuzz 1% -fill black -draw "color 0,0 floodfill"  black_diamond_filled.jpg 
I can sort of make it work if I include a -region but that seems to be a bit of a kludge.

It's just a learning exercise at the moment but I'll eventually need a gravity/floodfill command for several hundred scans I need to tidy up. It would be nice if I understood what I was doing and not just copy/paste :-)

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

Re: Finding corner pixels in multiple images

Post by fmw42 »

I can verify. This would appear to be a bug. I will report it. A workaround is to rotate the image 180 deg, do the floodfill, then rotate (back) by 180. Or extract the southwest corner coordinates in a prior command and store as a variable. For example

Code: Select all

convert black_diamond.jpg -rotate 180 -fuzz 10% -fill black \
-draw "color 0,0 floodfill"  -rotate 180 black_diamond_filled.jpg
or in unix format

Code: Select all

coords=`convert black_diamond.jpg -format "%[fx:w-1],%[fx:h-1]" info:`
convert black_diamond.jpg -fuzz 10% -fill black \
-draw "color $coords floodfill" black_diamond_filled.jpg

P.S In the future, please always provide your version of IM and platform.
miguellint
Posts: 22
Joined: 2015-09-27T20:26:53-07:00
Authentication code: 1151

Re: Finding corner pixels in multiple images

Post by miguellint »

Hello Fred...

Thanks once again for taking the time to reply.

Your rotation work-around is quite clever but your Unix solution is absolutely perfect :-)

Thanks again
Miguel

IM 6.8.9-9
Kubuntu 15.04 (better late than never)
Post Reply