I am looking for help on how to adjust the color channel levels of a black and white (or grayscale) image. In photoshop this feature is called the Black and White filter.
The examples below demonstrate my process. The red shirt (which is a perfect mid-gray) is black in the final image.
Original Image
Changed Hue to Green
Final Image Now Black and White (with mid-gray/red shirt black)
2
Answers
With Imagemagick, you would use the -level operator to adjust the black & white end points, which in turn, can be applied to a specific color channel.
Example:
With PHP’s Imagick library, you would use the Imagick::levelImage method.
Update
To generate the intermediate image (green shirt), you would use the “red -> green” hue modulation with -modulate. Examples in Hue Modulation docs.
Now for swapping the color for black, simply use -fuzz and -opaque. But honestly, all the green hues remind me of Chroma Key which is defined as…
Once you have a mask isolated, it pretty simple to swap colors, backgrounds, or more complex images.
The main benefit of the mask approach is that the color details (shadows, highlights, & lines) will be preserved in the final image. Pulling this all together in PHP:
For populating the shirt with black 80% (or gray 20%). Compose the new image over a color-only image, and drop to grayscale.
Here’s example with populating the shirt with a pattern.
Again, this is ideal if you want to preserve details. If you want to do a full knockout (eg. all green to black 80%), just use -fill, -opaque & -fuzz.
Example:
Is it this command you are looking for?
Result (original red shirt on the left, black+white image on the right):
Or is it that you want the different red shades from the original to become (almost) pure black? — In this case add some
-gamma
adjustment, maybe:or
Here are the two resulting images:
Of course you can play a bit more with the exact parameters I used here…
Update
The following commands change the color level for the red channel first, then converts this intermediate result to grayscale:
or