Skip to content
0

Image Enhancement

 

A) Threshold Of An Image
B) Contrast Stretching Of An Image
C) Brightness Adjustment of an Image Circle
D) Gray Level Slicing

(A) Threshold Of An Image

Code:-

clear all;
clc;
close all;
a=imread(‘grayscale.jpg’);
a=double(a);
b=a;
[row col]=size(a);
T=input('Enter Threshold value: - ');
for x=1:1:row
               for y=1:1:col
                        if a(x, y)<=T
                        b(x, y)=0;
                        else b(x, y)=255;
                        end
                end
end
subplot(2,2,1)
imshow(uint8(a));
title('Original Image')
subplot(2,2,2)
imshow(uint8(b));
title ('Thresholded Image');

 

Output For Thresholding

 

 

 

 

 

 

 
 

 

 

 

 

 (B)Contrast Stretching Of An Image

Code:-

clear all;
clc;
close all;
a=imread('D:\final print\dip speech\images1.jpg');
a=double(a);
b=a
[row col]=size(a);
r1=input('Enter Lower value: - ');
r2=input('Enter Upper value: - ');
A=input('Enter Slope 1 : - ');
B=input('Enter Slope 2 : - ');
C=input('Enter slope 3 : - ');
s1=A*r1;
s2=B*(r2-r1)+s1;
for x=1:1:row
               for y=1:1:col
                        if a(x,y)<r1
                            b(x,y)=s1;
                        elseif  a(x,y)>r1 &&  a(x,y)<r2
                        b(x,y)=B*(a(x,y)-r1)+s1;
                        else b(x,y)=C*(a(x,y)-r2)+s2;
                        end
                end
end
subplot(2,2,1)
imshow(uint8(a));
title('Original Image')
subplot(2,2,2)
imshow(uint8(b));
title ('Contrast Stretched');

Output For Contrast Stretching

(C)Brightness Adjustment of an Image

Code:-

clear all;
clc;
close all;
a=imread('D:\final print\dip speech\images2.jpg');
a=double((a));
b=a
[row col]=size(a);
bt=input('Enter level of brightness to increase: ');
for x=1:row
               for y=1:col
                        b(x,y)=a(x,y)+bt;
                end
end
subplot(1,2,1)
imshow(uint8(a));
title('Original Image')
subplot(1,2,2)
imshow(uint8(b));
title ('Brightness Adjusted image');

Output Of An Brightness Adjustment

(D) Gray Level Slicing

Code:-

clear all;
clc;
close all;
a=imread('D:\final print\dip speech\images3jpg');
b=a
[row col]=size(a);
r1=input('enter range 1: ');
r2=input('enter range 2: ');
for x=1:row
               for y=1:col
                        if a(x,y)>=r1 && a(x,y)<=r2
                            b(x,y)=255;
                            c(x,y)=255;
                        else
                            b(x,y)=a(x,y);
                            c(x,y)=0;
                        end
                end
end
subplot(3,3,1)
imshow(uint8(a));
title('Original Image')
subplot(3,3,2)
imshow(uint8(b));
title('Gray sliced image with background');
subplot(3,3,3)
imshow(uint8(c));
title('Gray sliced image without background');

Output Of An Gray Level Slicing

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!