Page 1 of 1
Trying to "Enhance Contrast" similar to Fiji
Posted: 2016-07-27T13:11:14-07:00
by pski
I've been trying to figure out what sort of image manipulation would be required to get the same effect as the Fiji "Enhance Contrast" functionality (this can be found under Process -> Enhance Contrast). The values I'm specifically interested in, within Fiji, are 0.4 for the saturated pixels and "Equalize histogram" checked. What I thought would be the equivalent command would be:
Code: Select all
convert in.jpg -modulate 100,40 -equalize out.jpg
But it generally is resulting in something that isn't the same... I've tried variations of contrast stretching and saturation, so any help would be awesome. This is a comparison, the left is the Fiji output and the right is the image magick output:
http://screencast.com/t/9Br08lJz0
Re: Trying to "Enhance Contrast" similar to Fiji
Posted: 2016-07-27T13:44:50-07:00
by snibgo
I've never heard of Fiji and have no idea what its "Enhance Contrast" does. Perhaps if you provided a before and after pair of images, we might guess.
Re: Trying to "Enhance Contrast" similar to Fiji
Posted: 2016-07-27T13:51:21-07:00
by pski
My apologies, Fiji (Fiji is just ImageJ [one of those recursive names]) is a free image manipulation software that wraps ImageJ. Specifically here's the documentation on it:
http://imagejdocu.tudor.lu/doku.php?id= ... e_contrast (I'm doing the histogram equalization approach) and "Saturated Pixels" value of "0.4".
Here's the before and after (left and right accordingly):
http://screencast.com/t/PcdVGf8Yaxsk
Re: Trying to "Enhance Contrast" similar to Fiji
Posted: 2016-07-27T13:57:03-07:00
by pski
And as I re-read that, the "Saturated Pixels" is ignored when Equalize Histogram is checked... So I'm trying to figure out the difference between their implementation and ImageMagick's equalize approach.
Re: Trying to "Enhance Contrast" similar to Fiji
Posted: 2016-07-27T14:22:10-07:00
by snibgo
By "before and after pair of images" I mean the actual files. Then we could download them, and experiment, and see which of the usual methods comes closest.
The doc says "Hold the alt key down to use the standard histogram equalization algorithm." Have you tried that, and compared the result to IM's "-equalize"?
If it's open source, I suppose you could find the code it is running.
IM's "-equalize" calculates the histogram, and equalizes it. The doc suggests their method takes the square-root of the histogram before equalising it. You can't do that with "-equalize", but my pages show how to (a) create a histogram and (b) equalize it, so it would be easy to insert a square-root.
Re: Trying to "Enhance Contrast" similar to Fiji
Posted: 2016-07-27T14:28:12-07:00
by fmw42
It is always better to provide separate input and output images, so others can use your same input for testing.
According to your documentation, saturated pixels values are ignored when doing histogram equalization. So there should be no difference in IM -equalize. However, I do see a difference between ImageJ result and IM -equalize. So I do not know what they are doing differently, if saturate pixels is ignored. IM does not have that feature in its -equalize.
If I hold the alt key while processing, then I get something similar in IM to ImageJ, though not a perfect match.
What is your IM version and platform? Please always provide that information!
Re: Trying to "Enhance Contrast" similar to Fiji
Posted: 2016-07-27T14:49:19-07:00
by pski
I'm using: ImageMagick 6.8.9-8 Q16 x64 on Windows 10 (64-bit)
Here's the original:
https://www.dropbox.com/s/wpf9towx1mcba ... 6.tif?dl=0
Here's the output from Fiji (not holding the alt key):
https://www.dropbox.com/s/w3eb26srzawbf ... d.tif?dl=0
And you're right, it's very similar when holding the alt key. And like I noticed (after re-reading the documentation) the "Saturate Pixels" is ignored when using the equalize option.
Re: Trying to "Enhance Contrast" similar to Fiji
Posted: 2016-07-27T15:27:18-07:00
by snibgo
Their documentation is accurate. I get a very similar result by calculating the histogram, taking the square root, cumulating it, and using that as a clut on the input.
Code: Select all
%IMDEV%convert ^
subtracted_32_depth_16.tif ^
( +clone ^
-process 'mkhisto norm' ^
-evaluate Pow 0.5 ^
-process 'cumulhisto norm' ) ^
-clut ^
eh.png
My result is very similar but not identical (RMSE=6%). I don't know why they are not closer.
Re: Trying to "Enhance Contrast" similar to Fiji
Posted: 2016-07-27T17:14:01-07:00
by fmw42
I believe that IM uses the "intensity" (Y) value for the histogram when doing -equalize. Perhaps ImageJ combines the channels differently or uses the composite of the RGB channels to get the histogram.
Re: Trying to "Enhance Contrast" similar to Fiji
Posted: 2016-07-30T10:22:24-07:00
by pski
I greatly appreciate the help! I was able to get the similar result that was within 6% (which is 'good enough' for my purposes). Thank you guys! Apologize for not being more clear in the initial post.