Photoshop's RGB levels with ImageMagick

拥有回忆 提交于 2019-12-03 08:52:33

Shadows, Midtones and Highlights are colors that fall within a certain range of luminosity. For example, shadows are the lower range of the luminosity histogram, midtones are colors in the middle and highlights are the ones up high. However - you can't use a hard limit on these values, which is why you will have to use curves like these that weight the histogram (a pixel may lie in multiple ranges at the same time).

To adjust shadows, midtones and highlights separately, you will need to create a weighted sum per pixel that uses the current shadow, midtone and highlight values to create a resultant value.

I don't think you can do this directly using ImageMagick API's - perhaps you could simply write it as a filter.

Hope this helps.

So I stumbled across this website: http://www.fmwconcepts.com/imagemagick/levels/index.php

Based on the information there, I was able to come up with the following php which seems pretty effective at simulating what Photoshop does with input and output and all that.

function levels($im, $inshadow, $midtone, $inhighlight, $outshadow, $outhighlight, $channel = self::CHANNEL_ALL) {
    $im->levelImage($inshadow, $midtone, $inhighlight, $channel);
    $im->levelImage(-$outshadow, 1.0, 255 + (255 - $outhighlight), $channel);
}

This assumes that the parameters to levelImage for blackpoint and whitepoint are on a scale of 0-255. They might actually be 0-65535 on your system. If that's they can it's easy enough to adjust it. You can also check what value your setup uses with $im->getQuantumRange(). It will return an array with a string version and a long version of the quantum. From there it should be easy enough to normalize the values or just use the new range.

See the documentation: The first value is the black point (shadow) input value, the middle is a gamma (which I'm guessing is the same as Photoshop's midpoint), and the last is the white point (highlight) input value.

The output values are fixed at the quantum values of the image type, there's no need to specify them.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!