Page 1 of 2

equalizeImage or -equalize

Posted: 2018-07-30T22:53:35-07:00
by mjamal
Hello Team,

Can anyone please suggest on Imagick equalizeImage function or image magick -equalize. I have used both the methods but it did not giving me 100% same result as photoshop "image/adjustments/equalize" effect.

Please let me know what I need to do for making same result.

Thanks

Re: equalizeImage or -equalize

Posted: 2018-07-30T23:33:07-07:00
by fmw42
We do not know exactly what Photoshop does. ImageMagick allows you to do an -equalize on each channel separately.

Code: Select all

convert image -channel rgb -equalize result
or all channels together

Code: Select all

convert image -equalize result
You will have to check those against Photoshop.

Imagick does not seem to have the equivalent of the first method, only the second. See http://us3.php.net/manual/en/imagick.equalizeimage.php.

However, you can separate channels, then equalizeImage on each channel separately, then recombine the separated channels back into an RGB image.

Re: equalizeImage or -equalize

Posted: 2018-07-31T04:39:43-07:00
by mjamal
Hello Fred,

We have checked both the mentioned processes but didn't got the exact result as photoshop. May be we are not following you correctly.
Can you please advice about separating the channels and provide us few code examples for this.

Re: equalizeImage or -equalize

Posted: 2018-07-31T06:10:57-07:00
by snibgo
Equalizing is complex arithmetically, and rounding may produce slightly different results.

@mjamal: I suggest you post a link to your input image, and the output from Photoshop, and state any settings you have used. Then we can try to understand differences between PS and IM.

Re: equalizeImage or -equalize

Posted: 2018-07-31T09:19:25-07:00
by fmw42
Here is a test example using Photoshop and ImageMagick.

Input:
Image

Photoshop equalize:
Image


ImageMagick equalize channels together:

Code: Select all

convert boats3.png -equalize boats3_IM_equalize.png
Image


ImageMagick equalize channels separately:

Code: Select all

convert boats3.png -channel rgb -equalize boats3_IM_equalize_rgb.png
Image




As you can see the IM equalize channels together if very close to that of Photoshop. There is slight difference in brightness.

As user snigbo has said, there may be difference in the approach and the histogram number of gray levels as well as precision. ImageMagick use floating point precision. I believe Photoshop is only 8-bit precise, but I could be wrong.

I believe there are two approaches to histogram equalization. The first is to shift colors to different bins to make the bins nearly equal in count. The other uses a look up table generated from the cumulative histogram. The number of bins in the latter makes a difference.

Re: equalizeImage or -equalize

Posted: 2018-08-01T02:45:46-07:00
by mjamal
In addition to Fred's input, I am sending my test inputs/results

1) Source image
source.jpg
source.jpg (136.25 KiB) Viewed 10226 times
2) Photoshop Equalize result on above image
photoshop.jpg
photoshop.jpg (298.85 KiB) Viewed 10226 times
3) IM equalize result on source image
IM-equalize.jpg
IM-equalize.jpg (287.01 KiB) Viewed 10226 times
Few additional observations/results
1) When we applied Brightness 16 (From Image >> Adjustment >> Brightness/Contrast in photoshop) to the IM result image in #3 above, we got exactly same result as photoshop result in #2.
2) In IM (#3), we added additional step for brightness 16 using HALD CLUT image (after applying brighness 16 to HALD16 image), we got exactly same result as photoshop in #2
3) In IM (#3), we tried to add brightness 16 using IM function, we didn't get the same result as photoshop #2

So adding brightness 16 using HALD16 image (haldClutImage function), worked and gives us same result as photoshop but with other source images, this trick didn't work. So adding brightness 16 is not a working solution for all the images but may give direction for finding working solution.

Re: equalizeImage or -equalize

Posted: 2018-08-01T09:12:36-07:00
by fmw42
Have you tried just creating a HALD image from ImageMagick, taking it to Photoshop, applying the PS equalize and save to PNG, then bringing that back to ImageMagick and just applying the processed HALD image with your input image using -hald-clut. Do not do any IM equalize, just use the Photoshop equalized HALD image with your input in IM

Re: equalizeImage or -equalize

Posted: 2018-08-01T10:16:13-07:00
by snibgo
I don't think equalizing a hald:16 will change much.

@mrjamal: What version of IM did you use?

Please show the exact command you used to make IM-equalize.jpg. It wasn't simply "magick source.jpg -equalize IM-equalize.jpg".

Re: equalizeImage or -equalize

Posted: 2018-08-01T21:55:31-07:00
by mjamal
@Fred, I already checked the equalize effect with the HALD 16 and it was not giving any changes for the source file.

@Snibgo - My server's Image Magick version is "6.7.8-9", you can see below screen for this.
imagickPHPINFO.png
imagickPHPINFO.png (49.48 KiB) Viewed 10160 times
Also I have checked with the below couple of codes and both are giving the same output result as we already mentioned above (IM-equalize.jpg).

Code 1:
exec("convert source.jpg -equalize IM-equalize.jpg");

Code 2:
$imagick = new \Imagick(realpath('source.jpg'));
$imagick->equalizeImage();
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();

Please advice us how we can close the result with result from Photoshop.

Re: equalizeImage or -equalize

Posted: 2018-08-02T04:44:05-07:00
by snibgo
v6.7.8-9 is very old. I suggest you upgrade (but I doubt that will make any difference here).
mjamal wrote:exec("convert source.jpg -equalize IM-equalize.jpg");
Your IM-equalize.jpg has an ICC colour profile. Your source.jpg does not. So that command did not make that output from that input.

I can't replicate the Photoshop result in IM. I've varied the number of buckets (eg 32) and the source for the histogram statistics (eg "-grayscale Brightnes"). These make small differences, but something more major is happening.

When you made the Photoshop equalization, I assume you didn't base this on a selected area within the image?

Re: equalizeImage or -equalize

Posted: 2018-08-02T07:02:28-07:00
by mjamal
snibgo, did get it about ICC colour profile. We have used the attached source files only to produce the attached results.
Please note, we are PHP developers having basic knowledge about photoshop. We don't have much knowledge about the terms like ICC colour profile, number of buckets, histogram statistics etc.

Also while applying the equalize effect on image, we did it on complete image and not on the selected portion of the image.

One more thing
When we tested the equalize effect on source image in GIMP image processing software, we get the exact result as IM.

Re: equalizeImage or -equalize

Posted: 2018-08-02T07:27:21-07:00
by snibgo
mjamal wrote:Also while applying the equalize effect on image, we did it on complete image and not on the selected portion of the image.
That doesn't quite answer my query. If you have selected a portion, the statistics can be gathered from just that portion then the equalisation applied to just that portion, or applied to the entire image. Is that what you did?

Re: equalizeImage or -equalize

Posted: 2018-08-02T08:11:13-07:00
by mjamal
Applied to the entire image

Re: equalizeImage or -equalize

Posted: 2018-08-02T08:39:32-07:00
by snibgo
So, you selected a portion, gathered statistics from that portion, and applied the result to the entire image. Yes?

Then that's the problem. IM gathers statistics from the entire image.

We can make IM gather stats from just a portion, and apply those to the entire image, if we want.

Re: equalizeImage or -equalize

Posted: 2018-08-02T08:45:10-07:00
by mjamal
We are using PHP's imagick library equalizeimage function from below link
http://us3.php.net/manual/en/imagick.equalizeimage.php.