equalizeImage or -equalize
equalizeImage or -equalize
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
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
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: equalizeImage or -equalize
We do not know exactly what Photoshop does. ImageMagick allows you to do an -equalize on each channel separately.
or all channels together
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.
Code: Select all
convert image -channel rgb -equalize result
Code: Select all
convert image -equalize result
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
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.
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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: equalizeImage or -equalize
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.
@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.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: equalizeImage or -equalize
Here is a test example using Photoshop and ImageMagick.
Input:
Photoshop equalize:
ImageMagick equalize channels together:
ImageMagick equalize channels separately:
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.
Input:
Photoshop equalize:
ImageMagick equalize channels together:
Code: Select all
convert boats3.png -equalize boats3_IM_equalize.png
ImageMagick equalize channels separately:
Code: Select all
convert boats3.png -channel rgb -equalize boats3_IM_equalize_rgb.png
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
In addition to Fred's input, I am sending my test inputs/results
1) Source image 2) Photoshop Equalize result on above image 3) IM equalize result on source image 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.
1) Source image 2) Photoshop Equalize result on above image 3) IM equalize result on source image 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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: equalizeImage or -equalize
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
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: equalizeImage or -equalize
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".
@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".
snibgo's IM pages: im.snibgo.com
Re: equalizeImage or -equalize
@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. 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.
@Snibgo - My server's Image Magick version is "6.7.8-9", you can see below screen for this. 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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: equalizeImage or -equalize
v6.7.8-9 is very old. I suggest you upgrade (but I doubt that will make any difference here).
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?
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.mjamal wrote:exec("convert source.jpg -equalize IM-equalize.jpg");
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?
snibgo's IM pages: im.snibgo.com
Re: equalizeImage or -equalize
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.
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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: equalizeImage or -equalize
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?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.
snibgo's IM pages: im.snibgo.com
Re: equalizeImage or -equalize
Applied to the entire image
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: equalizeImage or -equalize
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.
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.
snibgo's IM pages: im.snibgo.com
Re: equalizeImage or -equalize
We are using PHP's imagick library equalizeimage function from below link
http://us3.php.net/manual/en/imagick.equalizeimage.php.
http://us3.php.net/manual/en/imagick.equalizeimage.php.