Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

BobRon

macrumors member
Original poster
Oct 13, 2012
34
7
I am using imagemagick to detect the color of one pixel of an image. I need a program in bash that matches the discovered hex cold to the nearest of 11 pre-definded pixels. Is this possible? Or do i need to write if/else statements for every possible tint of purple.:(
 

mwb

macrumors newbie
Jul 21, 2011
26
17
Once you have defined a suitable a way of measuring distance between colours, all you need to do is loop through your 11 pre-defined pixels and choose the (or 'a' in some cases) closest one. Not sure why you'd dream of creating millions if/else statements!

Depending on your overall goal, you might want to try Image Magick's C++ API. Furthermore, if you're just looking up pixel values then maybe you should be using OpenImageIO.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.