- HubPages»
- Technology»
- Computers & Software»
- Computer Science & Programming
Image Enhancement Techniques with Matlab code
Image Enhancement techniques that we will be looking at with matlab code:
- Image Negative
- Gray level slicing with and without background
- Bitplane Slicing with 3 and 7 bits
- Image Darkening or Lighting
- Thresholding
Matlab Code
% Name: Ritesh Kothari
% Program 2
clear all;
close all;
% Image Reading
pic = imread('C:\Sample Pictures\Koala.jpg');
rp = imresize(pic,[500,600]);
%Image Negation of an image block
rp(1:100,201:400,:) = 255 -
pic(1:100,201:400,:);
%Darkening of the Image Block
rp(101:200,1:200,:) =
rp(101:200,1:200,:) - 100;
%Thresholding of the image block
for i = 101:200
for j = 401:600
if rp(i,j,1)>128
rp(i,j,1) = 255;
else
rp(i,j,1)=0;
end
if rp(i,j,2)>128
rp(i,j,2) = 255;
else
rp(i,j,2)=0;
end
if rp(i,j,3)>128
rp(i,j,3) = 255;
else
rp(i,j,3)=0;
end
end
end
%Graylevel Slicing with Background
for i = 301:400
for j = 1:200
if rp(i,j,1)>100 &&
rp(i,j,1)<=200
rp(i,j,1)<=200
rp(i,j,1) = 255;
end
if rp(i,j,2)>100 &&
rp(i,j,2)<=200
rp(i,j,2)<=200
rp(i,j,2) = 255;
end
if rp(i,j,3)>100 &&
rp(i,j,3)<=200
rp(i,j,3)<=200
rp(i,j,3) = 255;
end
end
end
%Graylevel Slicing without Background
for i = 301:400
for j = 401:600
if rp(i,j,1)>100 &&
rp(i,j,1)<=200
rp(i,j,1)<=200
rp(i,j,1) = 255;
else
rp(i,j,1) = 0;
end
if rp(i,j,2)>100 &&
rp(i,j,2)<=200
rp(i,j,2)<=200
rp(i,j,2) = 255;
else
rp(i,j,1) = 0;
end
if rp(i,j,3)>100 &&
rp(i,j,3)<=200
rp(i,j,3)<=200
rp(i,j,3) = 255;
else
rp(i,j,1) = 0;
end
end
end
%Bit Plane Slicing for plane no.3
for i = 401:500
for j = 201:400
if bitget(rp(i,j,1),3)==1
rp(i,j,1) = 255;
else
rp(i,j,1) = 0;
end
if bitget(rp(i,j,2),3)==1
rp(i,j,2) = 255;
else
rp(i,j,2) = 0;
end
if bitget(rp(i,j,3),3)==1
rp(i,j,3) = 255;
else
rp(i,j,3) = 0;
end
end
end
% Bit Plane Slicing for plane no.7
for i = 201:300
for j = 201:400
if bitget(rp(i,j,1),7)==1
rp(i,j,1) = 255;
else
rp(i,j,1) = 0;
end
if bitget(rp(i,j,2),7)==1
rp(i,j,2) = 255;
else
rp(i,j,2) = 0;
end
if bitget(rp(i,j,3),7)==1
rp(i,j,3) = 255;
else
rp(i,j,3) = 0;
end
end
end
imshow(rp);
The above enhancement techniques have been used on a part of image and the whole image. Please check the image above and the corresponding matrix with it. For any difficulties kindly leave your comment.