Photoshop's RGB levels with ImageMagick

纵然是瞬间 提交于 2019-12-04 15:13:20

问题


I'm attempting to convert some effects created in Photoshop into code for use with php/imagemagick. Right now I'm specifically interested in how to recreate Photoshop's RGB levels feature. I'm not really familiar with the Photoshop interface, but this is the info that I am given:

RGB Level Adjust
  Input levels: Shadow 0, Midtone 0.92, Highlight 255
  Output levels: Shadow 0, Highlight 255

What exaclty are the input levels vs. the output levels? How would I translate this into ImageMagick? Below you can see what I have tried, but it does not correctly render the desired effect (converting Photoshop's 0-255 scale to 0-65535):

$im->levelImage(0, 0.92, 65535);
$im->levelImage(0, 1, 65535);

This was mostly a stab in the dark since the parameter names don't line up and for output levels the number of parameters don't even match. Basically I don't understand exactly what is going on when photoshop applies the adjustment. I think that's my biggest hurdle right now. Once I get that, I'll need to find corresponding effects in ImageMagick.

Can anyone shed some light on what's going on in Photoshop and how to replicate that with ImageMagick?


回答1:


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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/10707738/photoshops-rgb-levels-with-imagemagick

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