Page 1 of 1

Convert fuzzed color to second fuzzed color

Posted: 2014-03-13T07:34:14-07:00
by f.s.e
Hello,

I would like to convert a "fuzzed color" = range of colors around(similar to) a single color in an image, to another "fuzzed color" = range of colours similar to a second, single color.

So far i can only convert a "fuzzed color" to a second, fixed color using:

Code: Select all

convert in.jpg -fuzz 10% -fill "#00000" -opaque "#7d7970" out.jpg
In this example, the fuzzed range will be created for color #7d7970. But the target color is not another range, but all black.

I would like the replacing target color to be the closer to black, the closer the replaced color originally was to #7d7970. I.e. I would like it to be a mix with the background.

Here an example from Photoshop:

I replace the brown color (fuzzed) in the middle of the image with a yellow color (the closer to the yellow the closer it was to the brown):

Image

Image

Thank you for your help!

Re: Convert fuzzed color to second fuzzed color

Posted: 2014-03-13T09:03:06-07:00
by snibgo
I'll use your Photoshop example, i2.jpg.

One way of doing this: create a copy of the original, entirely yellow. Composite this over the original, with a mask (diff.png). The mask is light where i2.jpg is close to brown, and dark where i2.jpg is far from brown.

I find the distance in CIELab colorspace, as I find that best for photographs. For graphics, you might prefer to omit "-colorspace Lab".

"-evaluate pow 20" makes the effect tail off quickly. Change to suit.

Windows BAT syntax.

Code: Select all

convert ^
  i2.jpg ^
  ( +clone ^
    -fill #633619 ^
    -colorize 100 ^
  ) ^
  -colorspace Lab ^
  -compose Difference -composite ^
  -grayscale RMS ^
  -set colorspace sRGB ^
  -negate ^
  -evaluate pow 20 ^
  diff.png

convert ^
  i2.jpg ^
  ( +clone ^
    -fill #ffff00 ^
    -colorize 100 ^
  ) ^
  diff.png ^
  -composite ^
  out.png

Re: Convert fuzzed color to second fuzzed color

Posted: 2014-03-18T00:28:24-07:00
by f.s.e
Thank you!! This works very well. I had to change the PNG format to TIFF, because it took ages to write it out.

Re: Convert fuzzed color to second fuzzed color

Posted: 2014-03-18T12:42:37-07:00
by snibgo
Good stuff. Combining the two converts makes it much faster: no need to read the input twice, or to save the mask.

Code: Select all

convert ^
  i2.jpg ^
  ( +clone ^
    -fill #ffff00 ^
    -colorize 100 ^
  ) ^
  ( -clone 0 ^
    ( +clone ^
      -fill #633619 ^
      -colorize 100 ^
    ) ^
    -colorspace Lab ^
    -compose Difference -composite ^
    -grayscale RMS ^
    -set colorspace sRGB ^
    -negate ^
    -evaluate pow 20 ^
  ) ^
  -compose Over -composite ^
  out.png