# Difference between Contrast and Intensity of an Image

I wanted to generate Gray Scale wedge image of 10 Levels in MATLAB and then increase and decrease its Intensity. By high intensity, I mean mapping increasing the level of gray scale intensity in an image from lower value to higher values.

The examples I have tried were performed on a Gray Scale wedge image of 10 levels:

0   28   57   85  113  142  170  198  227  255


I was using the function imadjust. For increasing the intensity levels I used:

 imadjust(grayStepImage, [.35 .75], [0.7 0.8])


The output:

179  179  179  179  184  192  199  204  204  204


and the result in image form:

Similarly, for lowering the intensity I used

imadjust(grayStepImage, [.35 .75], [0.1 0.39])


Original and modified levels are:

0   28   57   85  113  142  170  198  227  255

26   26   26   26   43   64   84   99   99   99


and the result in image form:

Was I actually increasing/lowering intensity of the image? How do those operations relate to the case of increasing and decreasing the contrast of an image?

What I know about contrast is,

Contrast is defined as the separation between the darkest and brightest areas of the image. Increase contrast and you increase the separation between dark and bright, making shadows darker and highlights brighter.

Does that mean, if I want to increase the contrast of an image I should increase the high intensity levels of an image to much higher and lower intensity level to much lower?

I am confused with contrast and the intensity as they seem opposite to each other. Kindly help me out.

• There are many definitions of contrast. I think the simplest contrast adjustment is just a multiplication by a contrast factor $c$: $x'=255\cdot\left[ (x/255-0.5)\cdot c + 0.5\right]$. – Libor Oct 6 '12 at 10:49
• More elaborate methods take also pixel neighborhood into account. These include adaptive histogram equalization and processing in contrast domain. – Libor Oct 6 '12 at 10:56
• The documentation says that - "Note If high_out < low_out, the output image is reversed, as in a photographic negative." You have 0.39 < 0.1, that causes the wierd effect in second call. – Andrey Rubshtein Oct 6 '12 at 11:01

On intensity

Simply said, it's hard to talk about "intensity" of an image. Every pixel has its intensity (for greyscale images, they are usual allowed range is [0, 255]), but the concept of image intensity does not exist. If you are doing some kind of image analysis, you could be interested in a parameter describing image intensities, e.g. mean intensity (like @geometrikal said) or distribution of image levels (which is related to contrast).

On contrast

If you presume an idealized situation where a greyscale image contains only pixels of two intensity values, one for background pixels and one for object pixels, the contrast of the object would be the difference of those values. What it means on the displayed image --> the higher the contrast, the easier it is to spot (find, locate) the object on the image (for the human eye). Again, you would usually talk about contrast of an object in an image, it's hard to talk about contrast of an image where it is not possible to define an object.

As an example, let's look at several 1-D signals (you can produce images similar to your examples from these):

1)   0   0   0   0  20  20   0   0

2)   0   0   0   0 255 255   0   0

3) 200 200 200 200 255 255 200 200

4) 200 200 200 200   0   0 200 200


I'll assume that the two pixels different from the rest in each example are object pixels, and the rest are background. We have several cases here (and I could make more):

1. brighter object on dark background, all intensity values are low (i.e. the image is rather dark), contrast is low
2. bright object on dark background, most pixels have low intensity, contrast is high (it's a black-white image)
3. bright object on darker background, all intensity values are high (i.e. the image is bright), contrast is low (but higher then in the 1st example)
4. dark object on bright background, most pixels have high intensity, contrast is high (but not as high as in the 2nd example)

Here's another example supporting the fact that the contrast is usually an attribute describing an object, either in relation to itself or to the surrounding. Another important fact to notice from this example is that contrast generally describes the difference between the intensity levels, but the precise definition depends on the application (purpose for the measurement). Let me paraphrase the contrast definition used in hierarchical image segmentation from P. Soille, L. Najman: On morphological hierarchical representations for image processing and spatial data clustering as an example:

The internal contrast of a connected component (object) corresponds to the largest intensity difference between two adjacent pixels belonging to this connected component. The external contrast is defined as the smallest intensity difference between a pixel of the considered connected component and an adjacent pixel not belonging to the considered component.

Of course, a different application could use a different measurement for contrast.

On imadjust

I don't usually work in MATLAB, but from the documentation, it is used to map intensity range (intensity levels in given range) of an input image, to an intensity range specified for the output image. The default, no-parameter call, will increase contrast of the image. But, you can get a brighter/darker image with imadjust with either increasing or decreasing the object contrast. Let me demonstrate this on my 3rd example:

imadjust(I3, [0.8; 1.0], [0.0; 1.0])


should output 0 0 0 0 255 255 0 0. You would get a white object on black background. In general, the image is darker (lower intensity), but contrast is higher (black-white).

imadjust(I3, [0.8; 1.0], [0.0; 0.2])


should output 0 0 0 0 51 51 0 0. Fairly dark object on a black background. The image is darker (lower intensity) and the contrast of the object did not change.

imadjust(I3, [0.8; 1.0], [0.85; 0.9])


should output 216 216 216 229 229 216 216. Very bright object on bright background. The image is brighter (higher intensity), and the contrast of the object decreased (object intensity levels are more similar to the intensity levels of the background).

You get the actual ranges the function is working with by multiplying them with the maximum gray level (255). For example, a range [0.2; 0.8] is actually intensity range [51; 204].

One more thing to take care of is that the function clips the values outside the first intensity range, and maps them to the new low if they're smaller or new high if they're larger then the range. All of my examples actually include this: the first range starts from 0.8 which maps to intensity 204, but the intensity of 200 from the input image is mapped to the output low in all the images.

So, it's actually just a simple scaling of image intensities (with cut-offs). Also, the default call to imadjust with only an image as an input parameter should increase contrast. I'd say that imadjust(I2) wouldn't do anything (there's a maximum contrast in my second example).

On contrast enhancement

Quote from P. Soille: Morphological Image Analysis:

Image contrast enhancement refers to accentuation or sharpening of image features so as to make a graphic display more useful for visualization or analysis of the image by the human eye.

He also emphasizes: with enhanced contrast image analysis by visual (human) inspection is easier. In idealized images like in my examples, a computer wouldn't gain much in term of image analysis difficulty.

E.g. for object extraction by thresholding, it would just mean different thresholds should be used to extract the object from the background. But, a human examiner would spot the object much easier on high-contrast images. This all changes some in real images (objects don't have uniform gray levels), so contrast enhancement becomes useful in image analysis.

There are several methods of contrast enhancement:

• point-based techniques, where the local neighborhood is not important. They are based on the analysis of grey levels through the whole image
• neighborhood based techniques, where local neighborhood of the pixel is important. Examples are white and black top-hat operators, and toogle contrast operator.
• transform based techniques, where the filtering is done on a transformed image before using the inverse transform (e.g. filtering in the frequency domain after Fourier transform).

In term of greyscale image, the intensity of the pixel corresponds to it's brightness. The greater the intensity, the greater the brightness. This also means that increasing intensity can be viewed as brightening the image (while decreasing intensity can be viewed as darkening the image).

I would describe the process of uniformly brightening the image as increasing intensity while leaving the contrast unchanged in the whole image. This actually means adding a constant value to all the pixels.

Now, as the pixel intensity values have a predefined range, typically [0..255], this means that the maximum intensity exists. This inevitably means that some pixels (that were different from each other before) will become white (i.e. intensity 255).

This "naturally" happens when you take a photo aimed towards something very bright -- sun or other light. Away from the light, you might see some details, but at the position of the light/sun and around it, you will get only white pixels meaning that the intensity (amount of light when the image was taken) "hit" its maximum (displayable/storable) value.

The only way you wouldn't lose details by this operation would be if the original pixel intensities belong to only a part of possible intensity range, e.g. if original pixels are in the range [10, 150], the image could be brightened by up to 105 intensity levels before you start to loose details.

As imgadjust is meant to preform intensity scaling, it can do much more than just brighten/darken image. If you wanted to emulate brightening effect with imadjust, you could write something like:

imadjust(I, [0.0; x], [1.0-x; 1.0])


where x is any number between 0 and 1 (e.g. x=0.5 would brighten a [0..255] image by 127).

That said, this is an overkill for such a simple operation. I'm sure matlab has a elementary operation that adds a scalar to all elements of a matrix, so you could just use that :)

• @Effected I'm a girl, not a sir :) Sorry, I've made a mistake in my answer and corrected it. As for what you did in the question, e.g. first image, params [.35 .75], [0.7 0.8]. All intensities from the input img lower or equal to 89=0.35*255 will map to 179=0.7*255, all intensities hihger than or equal to 191=0.75*255 will map to 204=0.8*255, while the intensity values in the range [89,204] will (linearly) map to the range [179,204]. Ask if you have any further questions – penelope Oct 24 '12 at 18:13
• @Effected Also, as I said, it's hard to talk about "image intensity". You can talk about "pixel intensity", but as a global measure, nothing really describes the whole image intensity. E.g. if you have pixel intensities in range [0, 127] in input img and you map them to [128, 255] (params: [0, 0.5], [0.5, 1]) you've increased avg intensity, but contrast stayed the same. If you map the same levels to [0, 255] ([0, 0.5], [0,1]) you've increased avg intensity and contrast. If you map them to, say, [204, 255] ([0, 0.5], [0.8,1]) -- higher avg intensity, lower contrast. – penelope Oct 24 '12 at 18:26
• Somebody downvoted my answer yesterday... whoever it is (I hope you see it): could I maybe get an explanation in the comments? I'd like to update or correct my answer if there's something wrong in it. – penelope Nov 8 '12 at 9:11

An intuitive explanation

Imagine that you are outside, at daytime, and there is a heavy fog. The Intensity is high, because the sun shines. But you cannot see anything because of the fog. The Contrast is low. All of the rays of light that reach you, have almost the same energy amount, due to the fog. You cannot decipher the details because your eye has some quantization of gray levels, and they look almost alike to you.

Now, you are outside at night-time, there is no fog, and the moon shines. The Intensity is low, because there is no direct radiation from the sun. The Contrast is high, but you fail to see the objects (expect the moon) clearly, because of the low total Intensity. Now you cannot decipher the details because your eye is not sensitive enough for that amount of energy.

Another, more mathematical way to think about it: Consider the two following Gaussian functions, each has mean and standard deviation. Let's assume that they represent histograms of images.

Intensity is the mean value, Contrast is the standard deviation.

In the image above, the red distribution has more intensity - its center is located more to the right. The blue distribution has more contrast, it is wider.

 I am confused with contrast and the intensity as they seem opposite to each other


They are not opposite, the are orthogonal. There can be 4 possibilities:

• High Intensity, High Contrast - Example : Sunny day
• High Intensity, Low Contrast - Example : Sunny day with fog
• Low Intensity, High Contrast - Example : A moon in the night
• Low Intensity, Low Contrast - Example : A dark room
• So does that mean, if the intensity is high there will be less darker values of pixels ? – Sufiyan Ghori Oct 23 '12 at 18:56
• @Effected, if the intensity is high, the average value of the pixels will be higher. Please see the updated answer. – Andrey Rubshtein Oct 23 '12 at 20:35

The value of a pixel is its intensity.

The intensity of an image could refer to a global measure of that image, such as mean pixel intensity. A relative measure of image intensity could be how bright (mean pixel intensity) the image appears compared to another image. Intensity of an image could also be how bright the image is compared to how bright the display is capable of producing.

I would define an image that has high contrast as one where the distribution of the pixel intensities is skewed towards both the low intensity (e.g. 0) and high intensity (e.g. 255) extremes of the intensity range. The imadjust command does this.

e.g.

Lena, mean intensity 0.48 - (0,1):

Lena histogram:

Lena after imadjust(I,[0.15 0.85],[0 1]), mean intensity 0.48 - (0,1):