People who have played SLR cameras should know the image histogram (ImageHistogram). Simply put, it calculates the proportion of each color level in the total pixel to reflect the image exposure. People who have played SLR cameras should know the Image Histogram. Simply put, it calculates the proportion of each color level in the total pixel to reflect the Image exposure.
I am not going to explain the terms in detail. if you are interested, you can refer to the reference link at the end of the article. there are easy-to-understand explanations:
Let's first look for an example image (shot with Canon 550D ):
Let's take a look at how to use Imagick to implement the image histogram:
256, 'height' => 100, ); $image = new Imagick($file); $histogram = array_fill_keys(range(0, 255), 0); foreach ($image->getImageHistogram() as $pixel) { $rgb = $pixel->getColor(); $histogram[$rgb['r']] += $pixel->getColorCount(); $histogram[$rgb['g']] += $pixel->getColorCount(); $histogram[$rgb['b']] += $pixel->getColorCount(); } $max = max($histogram); $threshold = ($image->getImageWidth() * $image->getImageHeight()) / 256 * 12; if ($max > $threshold) { $max = $threshold; } $image = new Imagick(); $draw = new ImagickDraw(); $image->newImage($size['width'], $size['height'], 'white'); foreach ($histogram as $x => $count) { if ($count == 0) { continue; } $draw->setStrokeColor('black'); $height = min($count, $max) / $max * $size['height']; $draw->line($x, $size['height'], $x, $size['height'] - $height); $image->drawImage($draw); $draw->clear(); } $image->setImageFormat('png'); $image->writeImage('histogram.png'); ?>
Note: The reason why the $ threshold value is added to the code is that sometimes the values of certain levels may be very large. if not processed, the final generation effect will be affected. There is no reason why we should first divide 256 and then multiply 12. it's all determined by my head. you can also use other methods.
The final histogram is basically the same as that of Photoshop. here we will post the Photoshop:
Finally, if you are interested in photography, refer to: how to interpret the histogram of a digital camera.