View 16-bit histogram


(Morgan Hardwood) #1

Hello @David_Tschumperle et al.

I’m trying to view an RGB histogram of a 16-bit RGB image, where the bin is 1px wide.
I found this page which seems to have exactly what I’m after:
http://gmic.eu/tutorial/convert_raw.shtml (skip to the Histograms section).
However, these two section do not work correctly:

gmic image.jpg -o histogram:name-of-file-for-histogram.miff
gmic name-of-file-for-histogram.miff -o histogram.png

The PNG and MIFF look like plain copies of the photo.
This command is supposed to show a RGB histogram, but it just shows the photo:

gmic name-of-file-for-histogram.miff

I’m using G’MIC-2.2.1, ImageMagick-6.9.9.40

Sample files:
https://filebin.net/x87qbq92plc11aue

Full log:

$ gmic _ASC4145-sRGB.tif -o histogram:h1.miff
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input all frames of TIFF file '_ASC4145-sRGB.tif' at position 0 (1 image 3892x2608x1x3).
[gmic]-1./ Output image [0] as histogram file 'h1.miff' (1 image 3892x2608x1x3).
[gmic]-1./ End G'MIC interpreter.
$ gmic h1.miff
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input file 'h1.miff' at position 0 (1 image 3892x2608x1x3).
[gmic]-1./ Display image [0] = 'h1.miff'.
[0] = 'h1.miff':
  size = (3892,2608,1,3) [116 Mio of floats].
  data = (34781,34223,33261,33712,33734,33858,33886,33838,33917,33838,33873,33602,(...),0,0,0,0,0,0,0,0,0,0,0,0).
  min = 0, max = 65535, mean = 24912.6, std = 12583.9, coords_min = (3779,721,0,0), coords_max = (3838,804,0,0).
[gmic]-1./ End G'MIC interpreter.
$ gmic h1.miff -o h1.png
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input file 'h1.miff' at position 0 (1 image 3892x2608x1x3).
[gmic]-1./ Output image [0] as png file 'h1.png' (1 image 3892x2608x1x3).
[gmic]-1./ End G'MIC interpreter.
$ gmic h1.png
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ Input file 'h1.png' at position 0 (1 image 3892x2608x1x3).
[gmic]-1./ Display image [0] = 'h1.png'.
[0] = 'h1.png':
  size = (3892,2608,1,3) [116 Mio of floats].
  data = (34781,34223,33261,33712,33734,33858,33886,33838,33917,33838,33873,33602,(...),0,0,0,0,0,0,0,0,0,0,0,0).
  min = 0, max = 65535, mean = 24912.6, std = 12583.9, coords_min = (3779,721,0,0), coords_max = (3838,804,0,0).
[gmic]-1./ End G'MIC interpreter.

Is it a bug, or am I doing something wrong?


(Alan Gibson) #2

I can’t comment on GMIC aspects.

As you have ImageMagick, you can do the job directly:

convert image.jpg histogram:out.png

And then any program will display the histogram, out.png. You can write to miff if you want…

convert image.jpg histogram:out.miff

… but miff is an IM internal format, so IM reads and writes it quickly, but other software can’t read it.


(Morgan Hardwood) #3

@snibgo

ImageMagick’s histogram: is essentially 8-bit, or one with 256-bit bins when viewing a 16-bit image.


(Alan Gibson) #4

Yes, IM’s built-in “histogram:” always uses 256 bins, and counts are quantized to 1/256. This seems to be what GMIC is using. I wrote a process module for IM to get as many buckets as desired, Process modules: mkhisto.


(David Tschumperlé) #5

The page you mention is very old and not up to date. Actually, what was doing the suggested command is using ImageMagick to convert the image into an histogram view.
This is not necessarily anymore, as G’MIC can handle the drawing of histograms by itself.

This should work as expected:

$ gmic _ASC4145-sRGB.tif split c histogram 65536,0,65535 append c display_graph 800,600,1

But it seems your image has very high occurrences of pixels with green=0 and blue=0, so the graph is not very visible . Cutting the values helps a little bit:

$ gmic _ASC4145-sRGB.tif split c histogram 65536,0,65535 append c cut 0,3000 display_graph 800,600,1

Command display_histogram may be also useful here :

$ gmic _ASC4145-sRGB.tif display_histogram 800,600,65536,0,65535,1,"cut(i\,0\,3000)"

which gives:


(Morgan Hardwood) #6

Thank you @snibgo

Thank you @David_Tschumperle , that’s exactly what I’m after, and simple too.
How would I have the output saved to a PNG file 65535px wide?

gmic _ASC4145-sRGB.tif display_histogram 65535,1080,65535,0,65535,1,"cut(i\,0\,2400)"

(Morgan Hardwood) #7

Appending -o foo.png worked!


(David Tschumperlé) #8

Yes, and you probably want to remove the axis too :

$ gmic _ASC4145-sRGB.tif display_histogram 65536,600,65536,0,65535,0,"cut(i,0,3000)"

(and there is 65536 values in 16bits, not 65535 :wink: )


(Morgan Hardwood) #9

Fantastic, thanks again!


(Morgan Hardwood) #10

One last plot twist.
I uploaded _ASC4145embed-sRGB.tif to the same filebin. This is the same file, saved using the same ICC profile, but it was embedded directly in RT as opposed to the first file which used an ICC file from disk (I don’t know the code specifics, see RawTherapee’s issue #4478).
In the embed file, the vertical value peak is around 600 (not counting the spike at the end of the histogram), while in the sRGB file it’s around 2300.
Is there a magical command to auto-scale the y axis (and ignore the spike), or to make it log not linear?