Marsu42 wrote:I'd lke to do something like sepia-tone, but automatically set the tint color to the dominant color of the image...
Using "ImageMagick 7.0.2-2 Q16 x64" on Windows 7 64, this command might have most of what you need to get the job done...
Code: Select all
magick "input.jpg" ^
( ^
+clone ^
-resize 1x1! ^
-set option:pcolor "%[fx:p.r*255],%[fx:p.g*255],%[fx:p.b*255]" ^
+delete ^
) ^
-colorspace gray ^
( ^
-size 8x256 ^
gradient:white-black ^
-fill "rgb(%[pcolor])" ^
-tint 100% ^
-rotate 90 ^
) ^
-clut ^
"output.jpg"
It starts by bringing in your source image.
Inside the first set of parentheses it clones the input image.
Then it resizes that clone to a single pixel averaging all the colors into one.
Next it sets an IM variable to contain the R, G, and B values of the color of that one pixel.
Then it deletes that 1x1 temporary image.
After the first parenthesis it turns the input image to grayscale.
Inside the second set of parentheses it makes an 8x256 white-black gradient image.
Then it sets the fill color to that variable we made from the 1x1 color pixel above.
Using that fill color it tints the 8x256 gradient strip.
Before exiting that set of parenthesis it has to rotate the 8x256 image 90 degrees so we can use it as a color lookup table (-clut) in the next step.
Outside the parentheses it uses the "-clut" operator to apply the color gradient from that 256x8 image to the grayscale version of your input image.
Finally it names the output file and voila, done!
You can tweak the command by increasing or decreasing the percentage of the "-tint 100%" operator. I liked the result better at 110%. You may want to adjust the levels or normalize the image after you turn it to grayscale or before the final output. Of course you can add some "-modulate" or other color modifiers along the way to adjust the saturation, brightness, or contrast.
If you use this in a .bat file you'll need to make all the single percent signs "%" into doubles "%%".