Reputation:
I need to create red, green and purple (and, if possible, yellow) versions of the following image:
Original image is here: https://github.com/jsx97/test/blob/main/folder.png
For this, I use
magick input.png -colorspace gray -fill red -tint 100 output-red.png
magick input.png -colorspace gray -fill green -tint 100 output-green.png
etc.
I don't know why, but the red folder is too bright. For example, here you can see a shadow:
But on the red image you won's see it:
How can I create such red, green, etc. versions with more balanced colors? Maybe we need to convert to Lab or LCH first?
Upvotes: -2
Views: 454
Reputation: 53164
Mark Setchell's command gives me two constant red images. The issue seems to be that ImageMagick 7 processes alpha channels different from ImageMagick 6, plus the fact that -colorize 100
just makes a constant color result. So this may be what he was trying to do.
magick img.png \
\( +clone -alpha extract -write mpr:alpha +delete \) \
-alpha off -colorspace HSL -separate -delete 0,1 \
\( +clone -fill red -colorize 100% \) -colorspace sRGB \
-compose multiply -composite -compose over \
mpr:alpha -alpha off -compose copy_opacity -composite result.png
Or using -compose softlight
rather than multiply
:
magick img.png \
\( +clone -alpha extract -write mpr:alpha +delete \) \
-alpha off -colorspace HSL -separate -delete 0,1 \
\( +clone -fill red -colorize 100% \) -colorspace sRGB \
-compose softlight -composite -compose over \
mpr:alpha -alpha off -compose copy_opacity -composite result.png
Or using -compose overlay
:
magick img.png \
\( +clone -alpha extract -write mpr:alpha +delete \) \
-alpha off -colorspace HSL -separate -delete 0,1 \
\( +clone -fill red -colorize 100% \) -colorspace sRGB \
-compose overlay -composite -compose over \
mpr:alpha -alpha off -compose copy_opacity -composite result.png
Or -compose pegtoplight
:
magick img.png \
\( +clone -alpha extract -write mpr:alpha +delete \) \
-alpha off -colorspace HSL -separate -delete 0,1 \
\( +clone -fill red -colorize 100% \) -colorspace sRGB \
-compose pegtoplight -composite -compose over \
mpr:alpha -alpha off -compose copy_opacity -composite result.png
Upvotes: 1
Reputation: 53164
An other approach in Imagemagick is to use -compose colorize. That swaps the hue in the blue image with the hue in the red image.
magick img.png \( +clone -fill red -colorize 100 \) -compose colorize -composite x.png
Upvotes: 1
Reputation: 53164
I do not see what is wrong with your result. But you could try my Imagemagick script, replace color, at http://www.fmwconcepts.com/imagemagick/replacecolor/index.php for Linux/Mac OSX/ Windows 10/11 Unix systems.
For example
Input:
replacecolor -i blue -o red -f 50 -g 100 img.png x.png
However, this is not very different from your simpler command result.
Upvotes: 1
Reputation: 53164
Similar to Mark Setchell's answer, you can convert to grayscale, then use +level-colors
magick img.png -colorspace gray +level-colors white,red x.png
However it makes the shading bright in place of dark. So this may not be a good method. So Mark's method is better.
Upvotes: 1
Reputation: 5395
This may not be exactly what you're looking for, but you can do a reasonable hue shift with ImageMagick's "-modulate" operation. This command will produce 6 output images showing the 6 colors evenly divided along the hue scale. (I appended them to a single image and resized them for this example.)
magick folder.png -duplicate 5 -modulate 100,100,%[fx:t*200/n] +append -resize 25% result.png
That uses an FX expression to calculate the hue shift evenly across the range, and creates this result...
I added about 1/12th to the hue shift by adding 16 to the "-modulate" calculation to get a slightly different assortment of colors. Experiment until you find some amount of shift that works for your purpose.
magick folder.png -duplicate 5 -modulate 100,100,%[fx:t*200/n+16] +append -resize 25% result2.png
To modify a single image, just make that third argument to "-modulate" any number from 0 to 200. This command...
magick folder.png -modulate 100,100,16 result3.png
Makes this image...
Upvotes: 2