Histogram specification?

Hello,

which software tool provides histogram specification? I have series of images which differ in appearance and I would like to make them all look alike to a reference image. I did this manually with imageJ and a plugin from the imaging book by Burger & Burge. But I am looking for an implementation in a program to avoid the manual work.

Hermann-Josef

Moin!

Histogrammar was once very adaptable, but I fear that it has not been developed during the last decade :frowning: More info here: GUILLERMO LUIJK >> TUTORIALS >> HISTOGRAMMAR TUTORIAL
and here GUILLERMO LUIJK >> TUTORIALS

MfG
Claes in Lund, Schweden

@Claes Thank you for the hint. I looked through the pages but did not find something like what I am looking for.

Here is an example, of what I got in a very first try with imageJ and the plugin for histogram specification:

On the left is the image to be changed in such a way to match the middle image in colours. At right is the result. It is not perfect but promising.

Hermann-Josef

I think what you are looking for is the CLUT from after-before layers filter from g’mic:

Hopefully histogram matching across multiple images finds its way into RawTherapee one day:
Histogram matching across selection of shots · Issue #4852 · Beep6581/RawTherapee · GitHub

@Tobias @Morgan_Hardwood Thanks for the replies.

I looked into the G’MIC CLUT filter. It requires two identical images, which I do not have.

So I guess I will have to write a macro for imageJ using the plugin from Burger & Burge and apply it to a series of images for a given reference image. Since the plugin always asks for input of the reference image, it may turn out that this will not be completely automatic but requires user input for each image. I will have to see …

Best wishes

Hermann-Josef

Perhaps @David_Tschumperle can explain how to use the filter.

When tweaking image A to match the histogram of image B, the result is best when the images show the same amounts of the subject. For example, your first image includes more of a yellow plate and a white plate than the second image, and these will have an adverse effect.

If you first crop both images to match subjects, the result of matching the histograms is better.

I don’t have a method of automatically doing the crops.

@snibgo Yes, the more similar the images are, the better the result will be. But this will not always be possible. I was quite pleased with this first result. I had matched the histograms of the channels independently.

I suspect that histogram matching will be faster and better than tweaking each image with masks etc.

Best wishes

Hermann-Josef

Would you get any more ideas from this:
https://helpx.adobe.com/photoshop/using/matching-replacing-mixing-colors.html
or this

MfG
Claes in Lund, Schweden

Here is the first and second input manually cropped, and the first of these with histogram adjusted to the second. The result is fairly good. It will never be perfect because, for example, the child’s arm occupies a larger area in the second image.

Automatic cropping could be fairly simple. For example, crop the first image to 80%, and search for that in the second. Some arithmetic gives us the areas that overlap, and those areas are the crops we can use.

And that wouldn’t be perfect either. In the manual crop, the second image is taller because the camera has changed position. This is reasonable because I wanted to include the same amount of the yellow plate. Doing that automatically might be difficult.

I used the following script to do the work. Windows BAT syntax:

%IMG7%magick ^
  childSpoon.jpeg ^
  -crop 3x1@ +repage ^
  -gravity Center ^
  -crop 95%%x100%%+0+0 +repage ^
  childspoon_x.png

%IMG7%magick ^
  childspoon_x-0.png ^
  -crop 395x242+1+74 +repage ^
  childspoon_x-0c.png

%IMG7%magick ^
  childspoon_x-1.png ^
  -crop 415x261+9+83 +repage ^
  childspoon_x-1c.png

call %PICTBAT%matchHisto ^
  childspoon_x-0c.png childspoon_x-1c.png childspoon_x-outc.png

%IMG7%magick ^
  childspoon_x-0c.png childspoon_x-1c.png childspoon_x-outc.png ^
  -bordercolor Black -border 10 ^
  +append ^
  childspoon-outc.jpg

The matchHisto.bat script is shown at Process modules.

I should have said: in my script, “childSpoon.jpeg” is the image posted in the OP.

I might add: the method is perfect, in the sense that the resulting histograms match. But for perceptual perfection, we want isolated elements to match: the background in the two images should match, the visible part of the child’s face in the two images should match, the jug in the two images should match, and so on. Unless all the elements occupy the same area in both inputs, this won’t happen.

The match-histogram method uses statistics from entire images to calculate the CLUT. But that’s not really what we want.

Another, more complex, approach is to crop small matching areas from both inputs: the wall, the jug, the face, and so on, so we collect statistics from these small areas. Then match the histograms based on those small areas. This gives as many images as there are areas, so we blend these using some 2D method: Shepards, or triangulation and barymetric distances, or whatever.

darktable has a color mapping module with histogram mapping and LUT, and also a deflickering option to match exposure from photo to photo (intended to be used for timelapses, but it should do the trick).

https://www.darktable.org/usermanual/en/modules.html#exposure

https://www.darktable.org/usermanual/en/effect_group.html#color_mapping

You can try this script: Gimp Script: Histogram Match - Rob A's (Im)personal Blog.

It may need to be updated to work in current Company version.

@snibgo Thanks a lot for your detailed instructions. I understand the principle of your approach. But it will take a while till I understand exactly what the script is doing.

@anon41087856 and @sguyader thanks for pointing out which other tools may help me.

Hermann-Josef

Another thought: here’s a gain-and-bias result:

This tweaks the RGB channels, giving each a multiplier and addition to make the mean and standard deviations match the target. This is simpler than the match-histogram method, and the result is fairly good. When the range of input colours is small, it is more reliable than match-histogram, so might be better for a method that chops one image into tiles, finds the tiles in the other input, matches pairwise, then blends the results.

My command was:

call %PICTBAT%imgGainBias ^
  childspoon_x-0c.png childspoon_x-1c.png childspoon_gb.jpg

… where imgGainBias is at Gain and bias.

2 Likes

@snibgo Thank you for this alternative solution.

Hermann-Josef

Hi @Claes , is this that Histogrammar you mention ? :thinking:

Ciao, Gabriele!

Unfortunately: no :frowning:

Have fun!
Claes in Lund, Svezia

:slightly_frowning_face:I’m searching an FOOS for a Rawdigger alternative… Do you have any hints?