Page 1 of 1
Threshold red color on an all red transparent PNG
Posted: 2017-09-14T15:16:27-07:00
by graftonclipper
Hi, I have transparent PNGs that look like this
And I'm wondering how I can threshold the red so that it only shows the darkest reds, like in the image below.
Ideally, the output would be have the white as a transparent png background.
Re: Threshold red color on an all red transparent PNG
Posted: 2017-09-14T15:40:26-07:00
by fmw42
Please post your transparent PNG input and desired output. You have posted JPGs or you hosting provide has changed them.
Also please always provide your IM version and platform, since syntax may differ.
Re: Threshold red color on an all red transparent PNG
Posted: 2017-09-14T23:16:37-07:00
by GeeMack
graftonclipper wrote: ↑2017-09-14T15:16:27-07:00Hi, I have transparent PNGs that look like this [...] And I'm wondering how I can threshold the red so that it only shows the darkest reds, like in the image below. [...] Ideally, the output would be have the white as a transparent png background.
You can get a result much like your example output image if you start by creating a sort of threshold transparency mask from a clone of your input image. Then you can composite that mask onto the input image to leave only the darkest red showing on a transparent background. I've tried this with IM 6.9.8 in Windows and IM 6.7.7 from bash. In Windows CMD syntax...
Code: Select all
convert input.jpg -alpha set ^
( -clone 0 -colorspace gray -brightness-contrast 25,100 -negate -alpha copy ) ^
-compose copyopacity -composite output.png
The threshold can be adjusted by changing N in the "-brightness-contrast N,100" setting. To nearly match your output example I have to set it between 25 and 50 depending on which version of IM I'm using.
To run a command like this from a *nix shell or script you'd have to change the continued line carets "^" to backslashes "\" and escape the parentheses with backslashes "\( ... \)".
If you're using IM 7 you'll use the command "magick ..." instead of "convert ...".