18 Jul 2007
12 May 2009
WHAT IS HISTOGRAMMARHistogrammar is a free software designed with the idea of being able to represent the most possible detailed image's histogram.
Any 16-bit image has a total of 65536 available levels on each channel; however Photoshop and most tools represent this histogram summarized typically in just 256 possible values. This means that under each of the vertical lines of that PS histogram plot there are as many as 256 different real levels present in the image.
This kind of representation will suffice in most cases, but if we want to perform a deeper analysis we need to use a more detailed image histogram.
Below there is an example of a real histogram represented in the usual range where levels for each channel are restricted to a range of 256 possible values, and what we would obtain if we start to zoom a specific area of this plot thanks to a 16-bit histogram.
Fig. 1 Classic histogram summarized in 256 levels.
Fig. 2 Zoomed view (16x) of the highlights area.
Fig. 3 Zoomed view (128x) of the right end of the highlights area.
The expanded views allow for instance fo find out that there are some few levels in the red channel than blew in the capture, and this could not be detected in the summarized version.
In addition to this Histogrammar allows for a logarithmic scale histogram representation, being this very useful in the analysis of the effective captured dynamic range of the scene along an f-stops axis.
It also provides the ability to plot RAW histograms when the RAW data have been extracted using the appropiate DCRAW commands that we will study.
OPEN AN IMAGE FILEThe first thing to do in Histogrammar to calculate an image's histogram is to open it with the button with a row of dots. Histogrammar's supported formats are in principle TIFF (both 8 and 16-bit), JPEG and BMP.
The usual reason to use this kind of tool is to analyse 16-bit TIFF image files; however it is totally possible to opern 8-bit files as indicated. In any case the histogram will always be represented in terms of a 16-bit image, so we should not surprise when opening an 8-bit image and seeing that all levels appear separated by empty gaps of 255 holes in the histogram. To have a cleaner representation of this type of histograms is not a problem thanks to the X-axis scaling options that we will discuss later.
Histogrammar makes use of the 16-bit graphic library designed by Pierre E. Gougelet, which can handle a large list of graphic formats including some RAW formats from the main camera vendors. In this way, and although success is not guaranteed, we can try to open image formats different to those already exposed just by typing in the open dialog box the required file extension (*.cr2, *.nef, *.gif, *.*,...), what will show all files that did not appear the first time.
In the case of RAW files the library itself will perform a basic RAW development which must be considered with caution as we actually don't know anything about the used parameters. These could be different to those we use in our regular RAW developer, so the result could differ noticeably from expected.
Fig. 4 Open an image file in Histogrammar.
Once the image has been selected in a few seconds Histogrammar will display the histogram and all options that were not enabled until now will become active.
LINEAR vs LOGARITHMIC MODEAs commented, Histogrammar can represent the histogram both in linear (the usual we are accustomed to see in almost all graphic applications) and logarithmic mode.
To switch between these two modes we must press the 'Linear → Log' or 'Log → Linear' option according to the present mode.
WHAT IS A LOGARITHMIC HISTOGRAM
A logarithmic histogram is the one that displays a series of vertical and equally spaced divisions corresponding to each of the different f-stops of the analysed image. The X axis of a logarithmic histogram does not display a linear range of levels but logarithmic, where each of the divisions we mentioned represents a level twice as high as the preceeding one and half of the next division.
Following next there is the correspondence between the linear levels from the previous histogram and its logarithmic scale version. We can see how the whole second half of the linear histogram corresponds only to the highest f-stop of the logarithmic histogram, the next quater corresponds to the second f-stop, and so forth.
Fig. 5 Correspondence of levels between linear (up) and logarithmic (down) histograms.
In a logarithmic histogram, the 0 level has no place so all black pixels on each channel are excluded from the plot. Strictly speaking they would correspond to the minus infinite f-stop (if you don't see this clear just try to calculate the logarithm of zero).
Also blown pixels are discarded, as although they concentrate in the maximum (level 65535 on a 16-bit range, level 255 on an 8-bit range), they do it simply because there are no higher levels where values could be codified, having reached the sensor saturation. In terms of the luminosity of the real scene these blown pixels would belong to f-stops above the maximum the sensor was able to capture with the exposure parameters used for the shot.
A total of 16 f-stops are calculated (in the example above only the upper 8 were displayed for simplicity), as this is the maximum number of f-stops which can be codified with 16 bits. It is important however to interpret with care the meaning of the lowest f-stops, as our camera in general will not be able to capture a dynamic range beyond the 8 upper f-stops.
That means that any level falling into the lowest f-stops will be there, rather than for being this its real luminance position in the zone system of the scene, because of the presence of noise in the shadows that finally propiciated the level being codified in that place, instead of appearing as pure black.
It makes sense however to calculate so many f-stops as for the case of images obtained by blending different shots with different exposure values, we will be able to exceed the physical limits of the dynamic range of the sensor. In this way we will be able to correctly capture more diaphragms than those we can achieve in a single shot.
WHEN A LOGARITHMIC HISTOGRAM MAKES SENSE
The main advantage of a logarithmic histogram is to stablish a straight connection between the light distribution calculated in f-stops over that histogram, and the real light distribution present in the captured scene. To make that matching happen there is only one condition: to have an histogram calculated over a linear format image.
If this premise is true, for sensor linearity we can be sure that the f-stops distribution showed by Histogrammar will correspond precisely to the luminous information found in each diaphragm of the real scene at shooting time.
Commercial RAW developers do not allow to develop images in linear format. To be able to do that we can just simply use the free RAW developer DCRAW, which is by default a linear developer.
We can use Histogrammar to calculate the histogram in logarithmic mode from a non linear format image (i.e. the kind of image format we are used to handle, with a gamma correction curve applied), but the result will not make much sense as it will not reflect the f-stops distribution of the scene.
We can also calculate the linear mode histogram from a linear format image, but we should be aware to correctly interpret the result as in a linear image levels are severely concentrated to the shadows.
For the rest of the tutorial I made use of the data from the following scene, deliberately chosen for having a high contrast:
Fig. 6 Scene analysed using Histogrammar.
With a linear format developing of that image we can obtain the following logarithmic mode histogram, which will thus show the real light distribution of the place:
Fig. 7 Logarithmic histogram of linear image (show the real dynamic range of the scene).
So as the linear mode histogram, knowing in this case that most of the information will locate in the shadows due to the absence of gamma correction.
Fig. 8 Linear histogram of linear image.
Linear images as this one display very dark if the visualization tool does not take into account that there is no gamma correction applied. This is not a problem at all when calculating the histogram. On the contrary, the information remains unaltered and its linear condition is what makes the result of the logarithmic histogram perfectly match the real light distribution of the captured scene.
Looking at the logaritmic histogram we can check that the dynamic range of the captured scene was nearly 13 f-stops of real dynamic range, each vertical division corresponding to one diaphragm.
You may wonder how is that possible if the Canon 350D can hardly capture 8 f-stops of dynamic range in one single shot. The answer is that the displayed image was made by blending 3 different shots separated 3 f-stops using the technique commented in Zero noise photography. This is the kind of images that make 16 f-stops logarithmic plots make sense as was already commented.
If we apply the usual gamma corrected developing we would obtain a classical linear mode histogram we are used to, because of the expansion of shades towards the lights according to the correction applied:
Fig. 9 Linear histogram of gamma corrected image.
MOTIVATION FOR A LOGARITHMIC HISTOGRAM
The main motivation to introduce a logarithmic mode in Histogrammar was that surprisingly, there is no other existing tool performing this. And I consider it very interesting for being a 100% photographic concept.
Even those presumably logarithmic histograms displayed in our cameras, with vertical divisions that make you think of f-stops, are not really logarithmic. To check this it is enough to make a test altering exposure in one f-stop steps and checking that the histogram does not move forward/backwards in a constant amount in each change. We can also check how black areas of the histogram concentrate in the origin of the X axis, which is a conceptual mistake in a strictly logarithmic representation as we commented before.
VISUALIZATION CONTROLSHistogrammar has a series of visualization controls to set up the graphic output representation to our needs. We will divide them in three blocks: the slide bar, the display options and the zoom levels:
Fig. 10 Visualization controls: slide bar, display options and zoom levels.
We can move along the whole histogram making use of it. At any time, above the histogram plot we will see the maximum value represented on the Y axis of the present visualization, so as the sector currently displayed and the levels or f-stops to which it corresponds according to the active mode.
The relative position of the slide bar will give us an idea of the area of the histogram displayed now, and its thickness represents the portion of the total histogram visible range.
Special attention deserve the zoom controls both in the X and Y axis:
Just to comment that the slide bar, both zoom controls, so as the drawing of the f-stops limits and the labelling of the graphics can be set independently for the linear and logarithmic mode. So when we switch the display mode the program will bring back the region of the histogram displayed, the level of zoom in the X and Y axis that had been set for that mode, so as the drawing of the f-stops borders and their labels.
STATISTICS ABOUT THE ANALYSED IMAGEAt the same time as each pixel's levels are analysed to build the histograms, some statistical analyse is done about the information contained in the image file that is displayed in the status windows once calculations end.
Taking the sample image the information provided is as follows:
being these the different sections:
The 'gap std dev' and 'ampl std dev' parameters are measuring this, representing in % the standard deviation relative to the mean separation between filled levels in the histogram's X axis (gap), and the same for the amplitude distribution of the histogram (ampl). Ideally both % values should be as low as possible, 0% in an completely regular distribution of levels both in the X and Y axis of the histogram.
However we must say that these are purely numerical figures that should never condition the best subjective possible result for our image, so they are simply orientative.
When the analysed image is 8-bit, although the histogram plot is represented on a 16-bit basis, the statistical calculated values take as a reference the 8-bit image. So a JPEG file acoounting 200 different non empty levels in the histogram will be qualified with a 200/256=78% filled levels ratio.
GRAPHIC SNAPSHOT OF THE HISTOGRAMAt any time the 'Snapshot' option can be used to dump into the Clipboard a copy of the plot currently being displayed that could then be pasted on any other graphic application.
With the 'Save GIF' option the dump will be performed to an output GIF file using the same saving path as the one from the analysed image. The name of the output file will be indicated on screen and will include the name of the image file.
In general the output image will be 768 pixels wide, except on those cases in which we had set a level of zoom for the X axis so that the histogram becomes smaller than the total available width. So also 512 and 256 pixel graphics are also possible depending on the level of zoom.
REPRESENTATION OF THE IMAGE IN THE ZONE SYSTEMTaking advantage of the capabilities of Histogrammar to plot logarithmic histograms, I have added a new feature into it which is conceptually very related to photography and will delight anyone interested in the Zone System. It is the possibility of representing in 1 f-stop steps the different luminous areas of the image.
With the 'Zones' options four GIF files of the same size of the image under study will be generated, indicating in a greyscale to which f-stop belongs each of their pixels. Each of the three first files correspond to the RGB channels and the fourth displays the luminosity distribution.
With the 'A/D' control we can choose the type of plot:
I have to say however that this is an interpretation of Ansel Adams' zone system model but applied to the scene under capture, while he focused in the printed copy. So it is not strictly the real zone distribution he was talking about. I consider however that in the digital era, taking into account that we can do a very precise control of the luminosity levels on post process, it is much more interesting the concept of dynamic range of the scene, one of the main weak points of today's digital sensors.
We must say however that the Ansel Adams' zone system was oriented to the printed copy, which is where actually makes sense to talk about zones and not in the scene. The matching between f-stops in the scene and zones of zone system only happens in those situations that he used to call normal contrast, which are precisely the ones in which the photographer will want to achieve this one to one relation.
The auxiliar control 'Y/N' allows to choose if on the right side of every generated GIF file we want to display a greyscale bar indicating the different grey tones corresponding to each f-stop, that in the case of the Ansel Adams' mode will be labelled in the same way as he did.
The same as when we talked about the logarithmic histogram, to make this calculation make sense and obtain the real distribution of luminosity in the captured scene we must necessarily start from a linear format image file.
By making use of these feature for the sample image used in the tutorial we obtain the following distributions:
Fig. 11 Ansel Adams' zone system of the scene.
Fig. 12 16-bit zone system of the scene.
Noisy images can show certain grain in the transitions of the lower f-stops because of noise. Also there can be some grain in images where pixels with considerably different luminosity values share the same area.
This last is the case of the sample image, which is practically free of noise but has a very grainy texture on the floor with important luminosity changes, hence the grain appearing in the border limits between diaphragms. On the contrary this phenomenon does not show on the walls or on the ceiling.
In order to prevent this granulation to distract out attention from the zone analysis of the image, it is very effective to apply some median blur filter to the image, or a gaussian blur, followed by a posterization process to the same number of grey tones as we are working with.
PHOTOSHOP'S 15-BIT IMAGESIn a usual edition workflow today the image will eventually fall into Photoshop. PS, for reasons that are not very clear from Adobe, automatically "steals" from our images the least representative bit so Photoshop actually performs a 15-bit edition.
With this loss half of the total possible tone levels are discarded reducing from 65536 to 32768. In terms of dynamic range, and always talking about linear image files, this means we are losing a whole f-stop from the originally 16 available.
The amount of levels is still more than enough for any kind of post processing without posterization or similar problems for this reason in most cases, but the true is that is not a happy idea to work with half the precision without knowing very well why and specially without a warn.
With Histogrammar we can check this phenomenon, in fact I comment this here in case you get a surprise when analysing the histogram of one of your favourite pictures and you realise that where you expected to find a continuous histogram you actually find a comb shape histogram with levels alternatively empty.
Taking as an example the linear image used in this tutorial, we will compare the original histogram at a maximum degree of detail with the one we get after opening and saving it back from PS, both in 16-bit TIFF format:
Fig. 13 Original linear histogram.
Fig. 14 Linear histogram after open and save action in PS.
Looking at this maybe we should put the sentence "TIFF is a lossless format" under revision, and add a disclaimer "...unless you go to Photoshop!".
Strictly speaking Photoshop works in 15 bits plus one level. It uses a total number of 32769 levels: the even values from 0 to 32768, and the odd ones from 32769 to 65535. In practice this is equivalent to a 15-bit encoding.
If this content has been useful to you, please consider making a contribution to support this site. Keeping it means an important effort, so as considerable storage space and bandwidth in the server. It is a simple and totally secure operation.