Local enhancement using Statistical Parameters form the histogram
In image processing domain there is main concern is how to retrieve
information from the images? Image enhancement and image filtering used to
serve the purpose but they also have some side effect such as filtering may
enhance the image but make your image blurry or sometimes it remove or make
less visible the image important information such as edges present in the image.
So how to avoid this issue in image processing after research and critical review
of previous work we have found local enhancement. Now the Question is what does
it mean by Local enhancement of the images?
Local Enhancement in simple words means that it essentially
takes consideration the local properties of the image by moving kernel throughout
the image pixel to pixel at every step where kernel moves on the image
histogram of the point in the kernel is calculated and the perform histogram equalization
transfer. This is the simple definition of the L.E process but real question is
this technique stand alone will serve the purpose? Answer is no. only local
enhancement will not serve the purpose as we need to make enhancement process
so efficient so it can decide where to perform operation of enhancement or not
also while performing operation it will decide the size of kernel for convolution
operation.
So here are the Few things which tells us more about the
Local enhancement process and its background knowledge then we can come up with
the new method that have the same properties that we have just mentioned
earlier.
Few things should know before coming towards the main methodology:
Local Histogram Processing it also known as Global
Transformation where function is designed by considering the pixel values distribution
in the entire image. But on the other hands Global transformation is not feasible
for enhancing over small region of the image for instant where the number of pixels
may have negligible influence on designing the Global transformation function. If
we are implementing on non-overlapping region shift, the processed image
usually has an unwanted checkerboard effect
Results:
Now keeping that simple definitions and Local histogram process
we implemented the Local enhancement using Statistical Parameters form the
histogram which can have better results as it works only on the region where
enhancement required and also preserve the image where no enhancement required
Local enhancement can be based on statistical properties of
the gray levels in a block instead of using full histogram
Examples Statistical parameters are
- Mean which gives average intensity of the image pixel values
- Variance and its Square root the Standard Deviation gives the deviation of intensities on average from the mean values (measure of contrast)
ReadMe File:
%%%%%%%%%%Local enhancement using statistical parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Description:
All code written in the function named "myThirdAssignment()" this function contains 5 parameters such as:myThirdAssignment('ImageFileName',size,k0,k1,k2). if user enter size 3 it will take it 3X3 and so on user can enter any size or any type of image as an input to the function. Argument check implemented in program so it allows user to enter just any image name (any size) or any other value of his/her choice but if not then it assign remaining parameters default values. Also Implementing both checks, one on mean and other on standard deviation. All lines of code commented so user can easily check or update the code.
How to Run the program on Matlab Command Line:
There is a simple way of running this code in the Matlab just writing this command using values of your choice:
myThirdAssignment('sampleImage.png');
or
myThirdAssignment('sampleImage.png',size);
or
myThirdAssignment('sampleImage.png',size,k0);
or
myThirdAssignment('sampleImage.png',size,k0,k1);
or
myThirdAssignment('sampleImage.png',size,k0,k1,k2);
Default Valeus Used (if not given by user):
size=5, K0=0.4, K1=0.02, K2=0.4.
Note: you need to pass image otherwise you will get error that says 'please Enter Image file'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%END OF DOC%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Tool for implementing the code:
Tool required for implementing the Code is MATLAB R2013a and onward will be sufficient for this project file compilation.
Project .m file Code (you can just copy and past in the matlab using .m file):
%%%%%%%Start of the Function%%%%%%%%%%%%
%%%%Local enhancement using statistical parameters%%
function[] = myThirdAssignment(filename,sizeoffiler,prob)
%%%%% Checking if the file exist or not inserted by user %%%%%%%
assert(exist(filename)~=0, sprintf('%s does not exist', filename));
%%%%%%% checking for the type for the image provided [fExt] %%%
[fPath, fName, fExt] = fileparts(filename);
%%%% Check for arguments/parameters passed by user using nargin %%%
switch (nargin)
case 1 %%%IF ONE ARGUMENT GIVEN%%%%%%%%%
RGB=imread(filename); %%%FILE READING%%%%
[m n c]=size(RGB);%GETTING ORIGNAL IMAGE SIZE SUCH AS ROWS AND COLS%
if c>1
I=double(rgb2gray(RGB)); %%%%CONVERTING IMAGE TO GRAYSCALE THEN DOUBLE%%%%%
imshow(I,[]);title('Original Image'); %%%%SHOWING ORIGNAL IMAGE
else
I=double(RGB);
imshow(I,[]);title('Original Image'); %%%%SHOWING ORIGNAL IMAGE %%%%%%%%%%
end
temp=I; %%%%%%%%%%%%%%SAVING ORIGNAL IMAGE INTO TEMP%%%%
%%%%%%%% DEFULT VALUES ASSIGNMENT %%%%%%%%%%%%%%
sizeoffiler=11;
prob=0.4;
%%%%%%%%%Appling noise to the image%%%%%%%%%%%%
J = imnoise(I,'salt & pepper',prob);
imshow(J,[]);title('Noisy Image'); %%%%SHOWING ORIGNAL IMAGE %%%%%%%%%%
%%% ENHANCEMENT PROCESSOR %%%%%%%%%
for i=1:m %%%%%%Rows%%%%%%%%%%%
for j=1:n %%%%%%%%Col%%%%%%%%
%%%%%%%%%%% Condition for indexing out of bound%%%%%%%%%%%%%
if(i+sizeoffiler<m && j+sizeoffiler<n)
%%%%%%%%% Creating Sxy (Sub image) from the Given Image %%%%%%%%%%%%
S=I(i:(i+sizeoffiler-1),j:(j+sizeoffiler-1));
%%%%% Computnig mean and standard deviation of Sxy%%%%%%%%%
msxy=mean2(S);
sdxy=std2(S);
%%%%%%%%%%%%%%%Defining ranges for different transformation functions%%%%%%
if(msxy<= K0*MG && (K1*SD <= sdxy && sdxy<=K2*SD))
%%%%%%%%%%%Computing location for enanced pixel placement in image and Center of Sxy and multiply by 2 and store enhanced E.f(x,y) on the location of Given image%%%%%%%%%%
mi=floor(sizeoffiler/2+i);
mj=floor(sizeoffiler/2+j);
I(mi,mj)=2*(S(ceil(sizeoffiler/2),ceil(sizeoffiler/2)));
end %%%%%%%%%nested condition end%%%%%%%%%%
end %%%%%%%%%%%%%%%%%%END IF outer %%%%%%%%%%%%
end %%%%%%%%%%%%%END of inner loop
end %%%%%%%%%%%%%%%%%%%%End of outer loop %%%%%%%%%%%%%%%%%
%%%%%%%%%% Image showing atfer enhancement and saving orignal image and enhanced image in the working directory%%%%%%%%%%%%%%%
warning('off', 'Images:initSize:adjustingMag');
figure;
imshow(I,[]);title('After Enhancement');
ImageGray = mat2gray(temp);
imwrite(ImageGray,'Orignalimage.bmp');
ImageGray1 = mat2gray(I);
imwrite(ImageGray1,'Enhanced_image.jpg');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%End Case 1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 2 %%%IF 2 ARGUMENT GIVEN%%%%%%%%%
RGB=imread(filename); %%%FILE READING%%%%
[m n c]=size(RGB); %%%%%%%%%%%%%%%%%%%%%%%GETTING ORIGNAL IMAGE SIZE SUCH AS ROWS AND COLS%%%%
if c>1
I=double(rgb2gray(RGB)); %%%%CONVERTING IMAGE TO GRAYSCALE THEN DOUBLE%%%%%
imshow(I,[]);title('Original Image'); %%%%SHOWING ORIGNAL IMAGE %%%%%%%%%%
else
I=double(RGB);
imshow(I,[]);title('Original Image'); %%%%SHOWING ORIGNAL IMAGE %%%%%%%%%%
end
temp=I; %%%%%%%%%%%%%%SAVING ORIGNAL IMAGE INTO TEMP%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DEFULT VALUES ASSIGNMENT %%%%%%%%%%%%%%
prob=0.4;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Appling noise to the image%%%%%%%%%%%%
J = imnoise(I,'salt & pepper',prob);
imshow(J,[]);title('Noisy Image'); %%%%SHOWING ORIGNAL IMAGE %%%%%%%%%%
%%%%%%%%%%%%%% ENHANCEMENT PROCESSOR %%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:m %%%%%%Rows%%%%%%%%%%%%%%%%
for j=1:n %%%%%%%%Col%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%% Condition for indexing out of bound%%%%%%%%%%%%%
if(i+sizeoffiler<m && j+sizeoffiler<n)
%%%%%%%%%%%%%%%%%%%%%%%%%% Creating Sxy (Sub image) from the Given Image %%%%%%%%%%%%
S=I(i:(i+sizeoffiler-1),j:(j+sizeoffiler-1));
%%%%%%%%%%%%%%%%%%%%%% Computnig mean and standard deviation of Sxy%%%%%%%%%
msxy=mean2(S);
sdxy=std2(S);
%%%%%%%%%%%%%%%Defining ranges for different transformation functions%%%%%%
if(msxy<= K0*MG && (K1*SD <= sdxy && sdxy<=K2*SD))
%%%%%%%%%%%Computing Center of Sxy and multiply by 2 and store enhanced E.f(x,y) on the location of Given image%%%%%%%%%%
mi=floor(sizeoffiler/2+i);
mj=floor(sizeoffiler/2+j);
I(mi,mj)=2*(S(ceil(sizeoffiler/2),ceil(sizeoffiler/2)));
end %%%%%%%%%nested condition end%%%%%%%%%%
end %%%%%%%%%%%%%%%%%%END IF outer %%%%%%%%%%%%
end %%%%%%%%%%%%%END of inner loop
end %%%%%%%%%%%%%%%%%%%%End of outer loop %%%%%%%%%%%%%%%%%
%%%%%%%%%% Image showing atfer enhancement and saving orignal image and enhanced image in the working directory%%%%%%%%%%%%%%%
warning('off', 'Images:initSize:adjustingMag');
figure;
imshow(I,[]);title('After Enhancement');
ImageGray = mat2gray(temp);
imwrite(ImageGray,'Orignalimage.bmp');
ImageGray1 = mat2gray(I);
imwrite(ImageGray1,'Enhanced_image.jpg');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%End Case 2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case 3 %%%IF 3 ARGUMENT GIVEN%%%%%%%%%
RGB=imread(filename); %%%FILE READING%%%%
[m n c]=size(RGB); %%%%%%%%%%%%%%%%%%%%%%%GETTING ORIGNAL IMAGE SIZE SUCH AS ROWS AND COLS%%%%
if c>1
I=double(rgb2gray(RGB)); %%%%CONVERTING IMAGE TO GRAYSCALE THEN DOUBLE%%%%%
imshow(I,[]);title('Original Image'); %%%%SHOWING ORIGNAL IMAGE %%%%%%%%%%
else
I=double(RGB);
imshow(I,[]);title('Original Image'); %%%%SHOWING ORIGNAL IMAGE %%%%%%%%%%
end
temp=I; %%%%%%%%%%%%%%SAVING ORIGNAL IMAGE INTO TEMP%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%Appling noise to the image%%%%%%%%%%%%
J = imnoise(I,'salt & pepper',prob);
imshow(J,[]);title('Noisy Image'); %%%%SHOWING ORIGNAL IMAGE %%%%%%%%%%
%%%%%%%%%%%%%% ENHANCEMENT PROCESSOR %%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:m %%%%%%Rows%%%%%%%%%%%%%%%%
for j=1:n %%%%%%%%Col%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%% Condition for indexing out of bound%%%%%%%%%%%%%
if(i+sizeoffiler<m && j+sizeoffiler<n)
%%%%%%%%%%%%%%%%%%%%%%%%%% Creating Sxy (Sub image) from the Given Image %%%%%%%%%%%%
S=I(i:(i+sizeoffiler-1),j:(j+sizeoffiler-1));
%%%%%%%%%%%%%%%%%%%%%% Computnig mean and standard deviation of Sxy%%%%%%%%%
msxy=mean2(S);
sdxy=std2(S);
%%%%%%%%%%%%%%%Defining ranges for different transformation functions%%%%%%
if(msxy<= K0*MG && (K1*SD <= sdxy && sdxy<=K2*SD))
%%%%%%%%%%%Computing Center of Sxy and multiply by 2 and store enhanced E.f(x,y) on the location of Given image%%%%%%%%%%
mi=floor(sizeoffiler/2+i);
mj=floor(sizeoffiler/2+j);
I(mi,mj)=2*(S(ceil(sizeoffiler/2),ceil(sizeoffiler/2)));
end %%%%%%%%%nested condition end%%%%%%%%%%
end %%%%%%%%%%%%%%%%%%END IF outer %%%%%%%%%%%%
end %%%%%%%%%%%%%END of inner loop
end %%%%%%%%%%%%%%%%%%%%End of outer loop %%%%%%%%%%%%%%%%%
%%%%%%%%%% Image showing atfer enhancement and saving orignal image and enhanced image in the working directory%%%%%%%%%%%%%%%
warning('off', 'Images:initSize:adjustingMag');
figure;
imshow(I,[]);title('After Enhancement');
ImageGray = mat2gray(temp);
imwrite(ImageGray,'Orignalimage.bmp');
ImageGray1 = mat2gray(I);
imwrite(ImageGray1,'Enhanced_image.jpg');
otherwise
disp('please Enter Image file');
end
%%%%%%%%%%%%%%%%%%END of parameter/arguments checking%%%%%%%%%%%%%%%%%%
end
%%%%%%%%%%END of program%%%%%%%%%%%%%%%%%%%%%%%%%
Used Statistical Parameters:
Post a Comment