# How to measure an image's contrast?

I'm studying Fourier optics and Interferometry and I intend to determine the contrast of an image using computer software. My teacher of Experimental Physics didn't tell me how to do it, and so, I'm requesting some attention from physicists that have already done this kind of analysis.

The contrast can be expressed as:

$$K=\frac{I_{max}-I_{min}}{I_{max}+I_{min}}$$

Consider the following interference spectrum where the object is an soldering iron:

I think it should be possible to measure the contrast, knowing the color of the pixels and their distribution in a certain region.

I know that intensity is proportional to the brightness of the regions. For example, to determine a quantity proportional to $I_{max}$, I just need to study the bright stripes of the image, and the dark ones for $I_{min}$.

My problem here is which software I should use? And is the previous method good to achieve my objective?

-

Whatever software you use (e.g. ImageJ), you must convert the image from sRGB colorspace to a linear colorspace first. To convert to linear RGB using ImageJ, you should convert the image to 32 bit first, divide by 255 and then run the math macro:

if(v<0.040445) v = v/12.92; if(v>0.04044) v = pow((v+0.055)/1.055,2.4)

and then multiply by 255 again.

The gray values of the pixels will then be proportional to the light intensity at the corresponding photo-sites.

-
Why would you pick this particular conversion? You don't know how the image file was created, neither does the OP, so there is no way to reconstruct the actual physical contrast from the image data. – CuriousOne Mar 13 at 0:59
@CuriousOne In principle any arbitrary conversion could have been used, but if the image was meant to be displayed on a computer screen then it is quite likely that it had been converted to sRGB. Given some arbitrary nonlinear transform, you can attempt to find the transform back to linear colorspace by considering out of focus areas of the picture. Some high contrast transition from brightness v1 to v2 will due to blurring be displayed as a brightness profile that changes from v1 to v2 gradually. In linear colorspace these functions from different areas are related via a scaling transform. – Count Iblis Mar 13 at 4:42
This allows you to deduce the transform to linear colorspace that will make the brightness profiles across blurred high contrast areas satisfy the scaling relations that they should satisfy. – Count Iblis Mar 13 at 4:45
The way Apple calibrates their screens is different from the way it's being done on PCs and if you use the color picker tool, it gives you multiple choices. One can pick the "native values", "srgb", "generic rgb" or "Adobe rgb". Moreover, I can calibrate my screen both on the Mac and the PC with a large number of options to optimize color reproduction. The same is true for digital cameras which sometimes have a dozen or more image calibration constants. There is not "one" way of encoding an image and every time you transcode for a different format you are likely to encounter another one. – CuriousOne Mar 13 at 5:05

ImageJ contains all of the tools you will require, is widely used, and is free. You can even add your own processing modules to extend its capabilities.

Usually the camera used will have to be taken into account when converting pixel brightness into intensities; for scientific work we usually use linear CCD cameras, where the vendor has done the calibrations for us.

Otherwise refer to the ImageJ tutorial for advice.

-

You could use Matlab: load the image into an matrix, and then find the maximum and minimum entries of the matrix. Plug these into your equation to find the contrast.

Alternatively, for higher accuracy, you could take the lowest and highest (say) 100 values and take the average of those to give you your Imin and Imax, respectively.

-