Trying to "Enhance Contrast" similar to Fiji

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
pski
Posts: 10
Joined: 2016-07-27T13:05:07-07:00
Authentication code: 1151

Trying to "Enhance Contrast" similar to Fiji

Post 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
Last edited by pski on 2016-07-27T13:53:28-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Trying to "Enhance Contrast" similar to Fiji

Post 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.
snibgo's IM pages: im.snibgo.com
pski
Posts: 10
Joined: 2016-07-27T13:05:07-07:00
Authentication code: 1151

Re: Trying to "Enhance Contrast" similar to Fiji

Post 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
pski
Posts: 10
Joined: 2016-07-27T13:05:07-07:00
Authentication code: 1151

Re: Trying to "Enhance Contrast" similar to Fiji

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Trying to "Enhance Contrast" similar to Fiji

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trying to "Enhance Contrast" similar to Fiji

Post 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!
pski
Posts: 10
Joined: 2016-07-27T13:05:07-07:00
Authentication code: 1151

Re: Trying to "Enhance Contrast" similar to Fiji

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Trying to "Enhance Contrast" similar to Fiji

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trying to "Enhance Contrast" similar to Fiji

Post 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.
pski
Posts: 10
Joined: 2016-07-27T13:05:07-07:00
Authentication code: 1151

Re: Trying to "Enhance Contrast" similar to Fiji

Post 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.
Post Reply