# Left Shifting the Histogram (Histogram Shifting) or Making the Image Darker / Less Bright using MATLAB

Yes making your histogram to shift left & making the image more dark or reducing the brightness are one & the same thing. Very easy to perform & you just need to apply some very basic arithmetic operation on the image. The operations could be either subtraction or multiplication with a constant less than 1.

For this article, we have taken a 640x640 grayscale image which is kept in the Current Working Directory. After opening it in MATLAB we will perform the further operations.

Histogram Left Shifting by subtraction of a constant:
MATLAB Code & Explanation:
%Suppose we are subtracting a constant value of 20 from each element of the grayscale image
%In the results it will be clearly visible that the image has become darker or less bright & the
%histogram is shifted to left side, & there are no values in the histogram for the value range 235-255
% i.e., at last 20 values in the histogram is vanished.

% if the image is not in the current working directory you need to specify the full path.

imshow(x);
%for showing the original image

figure,imhist(x)
%for showing the histogram of original image

n=x-20;
%performing the arithmetic operation on each element of the image  & storing the result in new variable

figure,imhist(n)
%for showing the operated image

figure,imshow(n)
%for showing the histogram of operated image

Results of The above MATLAB code of Left Shifting the Histogram using subraction Original Unprocessed Image Histogram of Original Image Image After the arithmetic Operation (More Darker Than Original) Left Shifted Histogram after the subtraction operation on the image

Histogram Left Shifting By multiplication of a constant less than 1 (<1):
MATLAB Code & Explanation:

% if the image is not in the current working directory you need to specify the full path.

imshow(x);
%for showing the original image

figure,imhist(x)
%for showing the histogram of original image

n=x*0.85;
%performing the arithmetic operation on each element of the image  & storing the result in new variable

figure,imhist(n)
%for showing the operated image

figure,imshow(n)
%for showing the histogram of operated image

Results of The above MATLAB code of Left Shifting the Histogram using multiplication Original Unprocessed Image Histogram of Original Image Image After the arithmetic Operation (More Darker Than Original) Histogram of Processed Image
In both the cases, the left shifted histogram is roughly the shape of the original one.

#### 1 comment:

1. Thanks a lot it is really helpful!

Could you Please give a hand with histogram shifting in image processing? I will use it to embedded data into an imege