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.
Threshold red color on an all red transparent PNG
-
- Posts: 1
- Joined: 2017-09-14T14:59:09-07:00
- Authentication code: 1151
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Threshold red color on an all red transparent PNG
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.
Also please always provide your IM version and platform, since syntax may differ.
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Threshold red color on an all red transparent PNG
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...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.
Code: Select all
convert input.jpg -alpha set ^
( -clone 0 -colorspace gray -brightness-contrast 25,100 -negate -alpha copy ) ^
-compose copyopacity -composite output.png
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 ...".