Page 1 of 1

Fast method of finding min(R,G,B)

Posted: 2016-10-25T04:27:27-07:00
by tom_dl
I would like to find min(R,G,B) for an image. None of the -colorspace options provide this, so I've constructed a line to generate the desired results:

Code: Select all

convert input.png -separate \( -clone 0,1 -compose Darken -composite \) \( -clone 2,3 -compose Darken -composite \) -delete 0-3 output.png
but it is very slow. I had an idea that using the CMYK conversion's method for K (i.e. min(C,M,Y)) could work by fooling IM into taking the inverse of CMY as input, but couldn't get that to work.

Any ideas very much appreciated!

Re: Fast method of finding min(R,G,B)

Posted: 2016-10-25T09:09:14-07:00
by fmw42
try

Code: Select all

convert input.png -separate -evaluate-sequence min output.png

Re: Fast method of finding min(R,G,B)

Posted: 2016-10-25T09:19:14-07:00
by tom_dl
Can't believe I overlooked that! Thanks, that's 1.5x faster on my machine :-)

Re: Fast method of finding min(R,G,B)

Posted: 2016-10-25T11:38:13-07:00
by snibgo
Note that if the input has an alpha channel, in v7 "magick", "-separate" will give four outputs, where v6 gives three.

So, if you may upgrade to v7 in the future, I suggest you put "-channel RGB" before "-separate", and "+channel" after it.

Re: Fast method of finding min(R,G,B)

Posted: 2016-10-25T12:19:39-07:00
by fmw42
snibgo wrote:Note that if the input has an alpha channel, in v7 "magick", "-separate" will give four outputs, where v6 gives three.

So, if you may upgrade to v7 in the future, I suggest you put "-channel RGB" before "-separate", and "+channel" after it.

Good point. Or if the alpha channel is pure opaque, just add -alpha off. However, if the image might be CMYK, the you may want to convert to RGB first (preferably using profiles). So some checks and conditionals may be needed.