#1 2024-06-14 07:04:29

executive
Member
2017-08-16
1236

derivative quality

Greetings and salutations.

I've been messing around with some graphics scripts and Imagemagick, and I came across an interesting article about resizing images.

The gist of it is that human color perception plays an important part in the resize process. If you resize using linear interpolation, without accounting for gamma and colorspace models, you can sometimes end up with images which look drastically different from the original. The effect is more pronounced in dark images.
I stopped to think about how this could affect me. Where do I use resizing the most .... ahh, my online gallery. I wonder how my photo derivatives are being resized.

Simply by performing a color conversion before and after resizing, we can better preserve the quality.

Anyway, something to think about . Cheers.


https://imagemagick.org/Usage/resize/#resize_colorspace
http://www.ericbrasseur.org/gamma.html


https://eoimages.gsfc.nasa.gov/images/imagerecords/55000/55167/earth_lights.jpg

Last edited by executive (2024-06-14 07:42:23)

Offline

 

#2 2024-06-14 07:55:22

executive
Member
2017-08-16
1236

Re: derivative quality

Probably the most important part for us . (taken from the second link I posted)

PHP
Some explanation from Andrew Penry:


A lot of websites use php and gd2 to make thumbnails. GD2 uses the wrong scaling and the Dalai Lama image turns grey. Luckily gd has an imagegammacorrect function. Below is a commented sample of how to use it to do better scaling.

Cheers,
Andrew Penry
http://www.masterwebdesigners.com

Code:

<?php
header('Content-type: image/jpeg');

$filename = 'gamma_dalai_lama_gray_tft.jpg';
$percent = 0.5;
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;

// Init original and new images in "true" color
$orig = imagecreatefromjpeg($filename);
$new = imagecreatetruecolor($new_width, $new_height);

// Correct gamma of orginal from 2.2 to 1.0
imagegammacorrect($orig, 2.2, 1.0);
// Resample
imagecopyresampled($new, $orig, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// Correct gamma of new from 1.0 to 2.2
imagegammacorrect($new, 1.0, 2.2);

// Output
imagejpeg($new, null, 100);
?>

pass/fail image you can use for testing

http://www.ericbrasseur.org/gamma-1.0-or-2.2.png

Last edited by executive (2024-06-14 07:59:15)

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2025 · Contact