[Solved] Get colors of the image edge

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
vldvrfc
Posts: 5
Joined: 2011-05-15T09:43:06-07:00
Authentication code: 8675308

[Solved] Get colors of the image edge

Post by vldvrfc »

Image

I need 4 colors, which are closest to left, top, right, bottom. (In this image, the colors I need are green, orange, blue, gray.)

Thanks.
Last edited by vldvrfc on 2011-05-21T13:52:27-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Get colors of the image edge

Post by fmw42 »

trim the bound of white, then convert the first and last rows and columns to text format and then filter out all white pixels, and keep only one return value (unless you want all non-white values along the edges?)

In unix this would be:

convert Z1UPu.gif -trim +repage Z1UPu_trim.gif

convert Z1UPu_trim.gif -gravity north -crop x1+0+0 txt:- | tail -n +2 | grep -m 1 -v "white"
81,0: (255,102, 0) #FF6600 rgb(255,102,0)

convert Z1UPu_trim.gif -gravity east -crop 1x+0+0 txt:- | tail -n +2 | grep -m 1 -v "white"
0,56: ( 0, 0,255) #0000FF blue

convert Z1UPu_trim.gif -gravity south -crop x1+0+0 txt:- | tail -n +2 | grep -m 1 -v "white"
83,0: (128,128,128) #808080 fractal

convert Z1UPu_trim.gif -gravity west -crop 1x+0+0 txt:- | tail -n +2 | grep -m 1 -v "white"
0,53: ( 0,255, 0) #00FF00 lime

If on Windows, then you need to review http://www.imagemagick.org/Usage/windows/ or get one of the Windows users to help deal with the unix, tail and grep and pipes
vldvrfc
Posts: 5
Joined: 2011-05-15T09:43:06-07:00
Authentication code: 8675308

Re: Get colors of the image edge

Post by vldvrfc »

Thank you. :D
Post Reply