Open In App

MATLAB – Intensity Transformation Operations on Images

Improve
Improve
Like Article
Like
Save
Share
Report

Intensity transformations are among the simplest of all image processing techniques. Approaches whose results depend only on the intensity at a point are called point processing techniques or Intensity transformation techniques. Although intensity transformation and spatial filtering methods span a broad range of applications, most of the examples in this article are applications to image enhancement. In this article, you will learn how to apply Intensity transformation operations on images using MATLAB. 

In this article we will be going over the following intensity transformation functions:

  • Image Negatives
  • Log Transformations
  • Gamma Transformations

For the demonstration the following images would be used:

A greyscale image of a woman

 

A sample greyscale image

 

Image Negatives:

To find the negative of an image we will be using the negative transformation function which has the form:

S = L – 1 – r

Where S is the output pixel value, L is a number of unique intensities and is the intensity of the image in the range [0, L-1]. 

The reason why we subtracted 1 from L is that L is the number of unique intensities present in a color channel. Therefore, in the case of an 8-bit image, the value of L would be 256. But since the intensities/color values start from 0, we subtract 1 from L to adjust the range.

Example 1:

Matlab




% MATLAB code for Intensity Transformation
  img = imread('Sampleimage.jpg');
 
% In case of 8 Bit image
  L = 256;
 
% The below operation is equivalent to 255 - img
  s = (L - 1) - img;
  figure,imshow(s); title('Inverted Image')


Output:

 

 

The image colors got inverted such that all the blacks turned to whites and vice versa. Reversing the intensity levels of a digital image in this manner produces the equivalent of a photographic negative. This process gives us the complement of the image. 

Log Transformation:

A log transformation maps a narrow range of low-intensity values in the input into a wider range of output levels. The general form of log transformation is 

S = C * log( 1 + r)

Where S is the output pixel value, C is a constant and r is the intensity of the image in the range [0, L-1]. 

Example 2:

Matlab




% Matlab Code for Log Transformation
  img = imread('Sampleimage.jpg');
 
% Convert datatype to Double
% (for allowing fractional values)
  r = double(img);
 
% Constant determining the
% nature of the log curve
  C = 1;
 
% Performing log transformation
  S = C * log(1 + r);
  T = 255/(C * log(256));
 
% Converting the datatype back
% to integer for displaying
  B = uint8(T * S);
  figure,imshow(B); title('Log Transformation');


Output:

 

 

The resultant image is one that appears way more bright than the original. This method could be used to brighten images that are dominated by dark regions. The limitation of Log transformations is that they are very limited in usage. Such that the Log transformations can accomplish this compressing of intensity levels in an image, but the power-law transformations discussed later are much more versatile for this purpose.

Power Law Transformation:

Power law transformations have the form

S = crγ 

Where S is the output pixel value, and c and γ are positive constants. The above equation could also be written as

s = c(r + ε)γ

This type of transformation is generally used for gamma correction in Displays or in Images. This is done because our eyes perceive images in a gamma-shaped curve, whereas cameras capture images in a linear fashion. 

Example 3:

Matlab




% Matlab code for Power Law Transformation
 img = imread('Sampleimage.jpg');
 
% Convert datatype to Double
% (for allowing fractional values)
 r = double(img);
 
% The below value represents gamma
 G = 0.6;
 
% Applying the Power Law Transformation
 S = C * (r .^G);
 T = 255/(C * (255 .^G));
 
% Converting the datatype back
% to integer for displaying
 O = uint8(T * S);
 figure,imshow(O); title('Power Law Transformation');


Output:

 

 

The resultant images have a bit higher gamma than the original. The power law transformation is very useful, such that it can compress/spread values in higher as well as lower intensity levels. This makes it an ideal choice if wanting to gamma correct an image from variable sources. 



Last Updated : 02 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads