Abstract - CAE Users

advertisement
IMAGE ENHANCEMENT USING LOGARITHMIC
IMAGE PROCESSNING (LIP) TECHNIQUE
By
Benjamin J. Weisenbeck
And
Oiki Wong
Department of Electrical and Computer Engineering
ECE 533: Digital Image Processing
Dec 14, 2004
Table of Contents
1. Abstract…….……………………………………….………………………………..1
2. Introduction .…………………………………………………………………………1
3. Theory.……………………………………………………………………………….2
4. Implementation………………….…………………………………………………...4
5. Simulations And Result
I.
 and …...………………………………………………………………...6
II.
Window Sizing……………………...………………………………..…..10
III.
LIP vs. Histogram Equalization ………………………………………….11
IV.
Noise…………………………………………...…………………………14
6. Conclusion……………………………………………………………………….......18
Appendix I …………………………………………………………………………........I
Appendix II…………………………………….………………………………………..II
Appendix III
1.
GUI Files………………………………………..…………………….........III
2.
User Defined Functions……………………………………………………IX
Appendix IV – References…………………………………………………………...XIII
Appendix V – Individual Responsibility Chart………………………………………XIV
1
Section 1: Abstract
This project implements an image enhancement algorithm that is based on a logarithmic image
processing model proposed by Deng [2]. This algorithm is a new implementation of Lee’s image
enhancement algorithm and is based on a mathematical structure for logarithmic image
processing developed by Jourlin and Pinoli [5]. This technique is capable of simultaneously
enhancing both the overall contrast and the sharpness of the image. We will investigate the
effects of each parameter on the enhanced image and compare the results obtained by this
method with the traditional histogram processing method for both clean and noisy images.
Section 2: Introduction
Traditionally, an over- (under-) exposed image is processed by the method of histogram
equalization. This method works by performing a transformation that spreads out the histogram
of the original image so that the levels of the equalized image will span a fuller range [3].
However, this method is not always the best method for image enhancement [Gonzalez &
Woods, pp 100-102], especially for color images where equalizing all three components, R, G,
and B, may create color distortion. Therefore, linear or non-linear contrast and dynamic range
stretching is used. Deng [2] has proposed a logarithmic based image-processing algorithm:
log( f (i, j ))   log( a (i, j ))   [log( f (i, j ))  log( a (i, j ))]
(2.1)
where f (i, j ) and f (i, j ) are the normalized enhanced and the normalized original images.
a (i, j ) is the arithmetic mean of an (n x n) window of the original image.  and  are parameters
that govern the dynamic ranges and contrast.
This image-processing algorithm can effectively enhance details in the very dark or very bright
areas of an image, which can be useful for enhancing an underexposed or overexposed image.
This algorithm can also be used to adjust the sharpness of an image.
The organization of this report is as follows: Section 3 will describe the theory behind Deng’s
algorithm. Section 4 briefly describes our implementation of the algorithm and the user interface
of our program. Finally, we will simulate the algorithm in section 5-I, investigate window sizing
in 5-II, compare between histogram equalization in 5-III and finally, look at noise effect in 5-IV.
1
Section 3: Theory
The logarithmic image processing technique proposed by Deng [2] is a new implementation of
Lee’s image enhancement algorithm. Lee's original algorithm [1] is as follows:
F   A(i, j )   [ F (i, j )  A(i, j )]
(3.2)
where F (i, j ) and F (i, j ) are the enhanced and original images and A(i,j) is the arithmetic mean
of an (n x n) window of the original image. We define the following 3 operations:
fg
M
f g
f - g = M
M g
f + g= f g
(3.3)
(3.4)

f 

 x f = M  M 1  
(3.5)
 M
where f =M-F, the complement transform of pixel brightness, F. M is the glare limit of the gray
scale range. Appendix II contains the proof which shows that with equations (3-3) through (3-5),
Lee’s equation can be re-written as equation (2.1).
To see the effects of  and , start with (2.1) written as:
log( f (i, j ))  (   ) log( a (i, j ))   log( f (i, j ))
(3.6)
If  = 0, the enhancement is simply a power function of the (n x n) window-averaged image, and
the result is dynamic range stretching. If  > 1, the range of the bright areas is stretched. If  <
1, it stretches the range of the dark area. When  < 0, it produces a negative transformation.
On the other hand, if  = 0, the result is a linear function of the difference of the log of the
original image with its (n x n) window-averaged image.
log( f (i, j ))   [log( f (i, j ))  log( a (i, j ))]
(3.7)
Therefore the logarithmic difference is linearly amplified. Equation (3.7) looks similar to highboost filtering where a blurred version of the image is subtracted from its own and multiplied by
a constant to produce a sharpened image in the logarithmic space. However, the inverse-log is
not linear, therefore this enlarges the difference between an individual pixel and its neighbors,
and the result is crisped edges.
The contrast between neighborhood pixels can be measured with the following equation:
c(f,g)=Max(f,g)
-
Min(f,g)
Appendix I will show that (3.8) is equivalent to the following:
2
(3.8)
c(f,g)=P(f
-
where P(f)=f
P(f) = 0 - f
g),
(3.9)
if f  0,
if f  0;
The enhancement of contrast can be analyzed by means of average contrast C(i,j) between a
pixel at f(i,j) and its 8 neighbor (for a 3 x 3 window). Given the definition of contrast above [1],
we can define C(i,j):
C(i,j)=
1
x
8
Σ
Σ P(f(i,j) - f(k,l)
Along with complement transform, we can see that the average contrast of a pixel in the
processed image is:
C”(i,j)  β
x
C(i,j)
Therefore, we can see that if  > 1, the larger the, the larger the difference so that the image is
sharper and as  < 1, the resulting image is blurred.
3
Section 4: Implementation
In order to create a user-friendly environment, this project incorporates MATLAB’s Graphical
User Interface (GUI) capability. To run this program, first open MATLAB and select the
directory the program is stored in and then type “guide” in the command window and then figure
4.1 will pop up:
After you open the file, “trial.fig” and click on
the “run” button, the figure shown in 4.2 will
show up. Here you can type in the name of the
image file in the lower left corner and click
“Load Image." When you first load the image,
all 3 windows will contain the original image.
Enter the window sizes to specify the desired
averaging window. α and β values can be
directly typed into the box or the slide bars
can be used to adjust these values. At the end,
click “Execute”. The original image is
displayed in the left-most window, the
enhanced image will be in the middle and the
image enhanced using histogram equalization
will be on the right.
Original
Image
Figure 4.1: GUIDE Window
Enhanced
Using
Proposed
Algorithm
Corresponding
Histogram
Figure 4.2: Program Window
4
Enhanced
Using
Histogram
Equalization
Figure 4.3 shows a demonstration using a window size of 3 x 3, α and β are 2 and 3 respectively.
If you hit the “Recursive” button, the program will take the center image as the “original image”
and enhance it using the corresponding window sizes, α and β. This function can sometimes be
useful.
Figure 4.3: Interface Window
As you vary the different parameters, you will be able to see the changes in pictures and their
corresponding histograms. This enables the user to “tune” each parameter to obtain the best
enhancement possible.
As for color images, they are broken down to their 3 components: R, G and B. The algorithm
will enhance each of these components and then reassemble them at the end.
5
Section 5: Simulations & Result
I. α and β
In section 3, we briefly described the effects of α and β. In this section, we will simulate these
effects. We saw that if  = 0, the expression becomes:
log( f (i, j ))   [log( f (i, j ))  log( a (i, j ))]
and this can also be written as

f 
f (i, j )   
(5.1)
a
For smooth areas where the average is close to the original, the expression is close to 1.
Therefore, when translated back to pixel brightness, F, the region is dark. Whenever there is an
edge, however, the entire expression depends on β. The result is that the edge will stand out of
the background as illustrated here:
Figure 5.1.1:  = 0, β=2
The bigger the β, the crisper it looks:
6
Figure 5.1.2: β = 3,
When β = 0, the result is simply an averaged image multiplied by a constant. We have explained
in section 3 how  stretches the dynamic ranges and this is illustrated below:
Figure 5.1.3:  < 0 = Negative Transformation
7
Figure 5.1.3:  < 1 = Brings out dark areas
Figure 5.1.3:  > 1 = Brings out bright areas
8
Figure 5.1.4: X-Ray Hand
The above figure shows an X-rayed hand. The image on the left is over-shadowed by the
appearance of the skin. With both parameters working together, the one on the right appears to
create a clearer image of the skeleton. All the joints are sharpened because we have brought out
the brighter part of the image, which is the bone rather than the shadows of the skin.
Figure 5.1.5: X-ray Spine
9
The above figure shows an X-ray image of a spine. Inside the circled areas, we can clearly see a
lot more detail in the enhanced image.
II. Window Sizing
As explained in section 3, the logarithmic image processing algorithm that we have implemented
makes use of the average value of an n x n window centered at each pixel. By varying the size of
this window, different results can be achieved. Our experimental results have shown that a 3x3
window will usually create the most effective results.
Original Image
Enhanced Image using a 3x3 window
Using a larger window size will generate an image with sharper edges which may be desirable
for edge detection applications. However, as the images below show, spurious features and
undesired noise can also be generated. Furthermore, some of the detail of the original image is
lost as the window size increases. Larger window sizes also have a disadvantage in that the
algorithm becomes much more computationally time consuming.
Enhanced Image using a 5x5 window
Enhanced Image using a 7x7 window
10
Enhanced Image using a 9x9 window
Our results have shown that a 3x3 window size generally yields the best result. For this reason,
along with the additional computation time required for larger window sizes, the other examples
shown in this report all use a 3x3 window.
III. LIP vs. Histogram Equalization
Histogram equalization is generally very useful for enhancing the contrast of images that have
low contrast and narrow histograms. However histogram equalization may not be suitable for
revealing the dark details in images with
broad spectrums. Our experimental results
show that by tuning the α and β
parameters, logarithmic image processing
techniques can produce better results than
histogram equalization for such images.
For the set of images in Figure 5.3.1, it can
be seen that logarithmic image processing
reveals many details in the image, while
histogram equalization has very little
effect.
Fig. 5.3.1(a) Original Image
11
5.3.1(b) LIP
5.3.1(c) Histogram Equalization
Our results also seemed to show that logarithmic image processing produces better results for
color images. While histogram equalization may increase the contrast of an image, the colors are
often lost or distorted as can be noted in figure 5.3.1(c). By varying the LIP parameters, it is
possible to achieve enhanced contrast while keeping the colors of the original image. An
example of this is seen in Figure 5.3.2. For this image, histogram equalization brings out many of
the hidden details of the original; however the result is a nearly black and white image.
Logarithmic image processing reveals the hidden details while also preserving more of the
original colors.
Fig. 5.3.2(a) Original
Fig. 5.3.2(b) LIP
Fig. 5.3.2(c) Histogram Equalization
12
The images in Figure 5.3.3 show an example in
which histogram equalization distorts the
original colors of the image. In this case,
histogram equalization has generated regions of
purple and blue that were not present in the
original. It is clear that logarithmic image
processing generated a much better result. The
contrast is enhanced and at the same time, the
colors of the original image are much better
preserved.
Overall,
logarithmic
image
processing created a result that is much more
aesthetically pleasing.
Fig. 5.3.3(a) Original
Fig. 5.3.3(b) LIP
Fig. 5.3.3(c) Histogram Equalization
It should be noted that for each of the comparisons above, that particular values of α and β were
chosen in order to achieve the greatest enhancement of each image. Since it is difficult to predict
which parameter values will work well for a particular image, LIP may hold the greatest
potential for applications such as real-time medical image enhancement, in which α and β can be
adjusted by the user to meet specific requirements. Once the right values have been found,
13
logarithmic image processing is clearly capable of performance that is superior to histogram
equalization.
Below shows that this LIP algorithm can have a color enrichment effect. Notice that even though
the original image is fine with respect to its detail perceptibility, we can see that it has certain
discoloration. By altering α, LIP algorithm can deepen the color and make it more stand out. The
color in the resulting image gives the image more depth.
Fig. 5.4.1(a) Original
Fig. 5.4.2(b) LIP
IV. Noise
Images often times are corrupted with noise such as salt & pepper and Gaussian noise. To see
what kind of effect noise has on this algorithm, we express a noisy image F(ij)=B(i,j)+noise,
where B is a noiseless image. The sharpness of the enhancement can be expressed as


 F (i, j ) 

noise 

  1 
 , therefore, the image is non-linearly enhanced. If the pixel value
 B(i, j ) 
 B(i, j ) 
B(i,j) is small, which corresponds to darker areas, the noise is greatly enhanced. In this situation,
β is best set at 0 which in turns creates virtually no image sharpening. An image of Barbara
showered with noise and its corresponding histogram are shown below.
14
Figure 5.4.1: Noisy Barbara, its histogram
The pixels at the extreme ends of the histogram are partly contributed by the noise. Using the
proposed algorithm using α=1.3 and β=0, we produced the following image:
15
Figure 5.4.2: Enhanced Image and Its Histogram, α=1.3 and β=0
By using α >1, the dynamic range of the bright areas is stretched, therefore the histogram is
shifted towards the left. Since β is 0, the noise is not enhanced. Another result using α=0.8 is
shown in figure 5.3. This time α < 1, so the image as a whole is brighter and the histogram is
shifted to the right. Figure 5.4 shows the result using histogram equalization
Figure 5.4.3: Enhanced Image and Its Histogram, α=0.8 and β=0
16
Figure 5.4.4: Result of Histogram Equalization
The histogram in figure 5.4 covers the entire [0, 255] gray scale in a fairly even way. It is also
worth noting that histograms of the enhanced images, using our proposed algorithm, seem to be
denser while those obtained using histogram equalization are more sparse.
Basically, histogram equalization cannot deal with noisy images. Due to the added noise, we
have to set β=0 to avoid noise enhancement. The result is an image that is not sharpened, but
blurred to a certain degree due to the averaging window.
Another observation is that because of the averaging window, the noise is smoothened. Since
noise can be better suppressed by means of Weiner filter or Wavelet De-noising technique, it is
suggested that image first be de-noised using one of those techniques and then enhanced with
this algorithm.
17
Section 6: Conclusion
Our implementation and experimentation with the logarithmic image processing method
proposed by Deng [2] has shown that in many cases it is capable of producing enhanced images
that are superior to those produced by more traditional enhancement methods. We discovered
that the α parameter can be used to control the contrast of the enhanced image. By adjusting this
value, either dark or bright details of the image can be enhanced. The β parameter can be varied
to control the sharpness of the enhanced image. This flexibility is not available with many
traditional methods such as histogram equalization. We found that, by selecting appropriate
values for these constants, logarithmic image processing can usually produce better results than
histogram equalization. Our results show that this is true for many different classes of images.
This algorithm can be used to enhance dark or light regions of interest in black and white
images; it can enhance the contrast of color images with minimal distortion of the colors; and it
can even perform well with noisy images because the β value can be adjusted to reduce the noise.
The flexibility inherent in this logarithmic image-processing algorithm makes it a very effective
technique for a wide variety of applications.
18
Appendix I
Equation 3.8:
c(f,g)=Max(f,g)
- Min(f,g)
Equation 3.9:
c(f,g)=P(f -
g),
where P(f)=f if f  0, and P(f)=0 - f if f  0;
Claim: Equation 3.8 is equivalent to equation 3.9
Proof:
Define:
f - g= M
f g
M g
c(f,g) = f - g if f > g  By Eq 3.8
if f > g, P(f because M
g) = f -
g = c(f,g) By Eq 3.9
f g
>0
M g
c(f,g) = g - f if g > f  By Eq 3.8
P(f -
g)= 0 - (f - g) = M
because if g > f, M
g f
= g - f = c(f,g)  By Eq 3.9
Mf
f g
<0
M g
II
Appendix II
Equation 2.1:
log( f '(i, j ))   log(a (i, j ))   [log( f (i, j ))  log(a (i, j ))]
Given:
f
M
f’(i,j)= x a(i,j) +  x
f  1
[f(i,j)
- a(i,j)]
Define:
f 

 x f = M  M 1  
 M
f g
f - g= M
M g
Proofs:
log( f ')  log{ x
f

+ g = f+g -
a(i,j) +  x [f(i,j) - a(i,j)]},


f a 
 a (i, j ) 

Let : A  M 1 
 , B  M 1 

M 

 M a
( M  A)( M  B ) 

log( f ')  log  M  A  M  B 

M


AB 

 log  M 

M 

 M AB 
 log 1   2 
 M M 
 AB 
 log  2 
M 

 2  a (i, j )  
f a 
 M 1 
 1 

M   M a


 log

M2










f (i, j )  a(i, j ) 
 a (i, j ) 
 log 1 

  log 1 
M 
M  a (i, j ) 



  log(a (i, j ))    log( M  f (i, j ))  log( M  a (i, j )) 
  log(a (i, j ))   log( Mf (i, j ))  log( Ma (i, j )) 
  log(a (i, j ))   log( M )  log( f (i, j ))  log( M )  log(a (i, j )) 
  log(a (i, j ))   log( f (i, j ))  log(a (i, j )) 
II
fg
M
Appendix III: Codes
1.GUI file
function varargout = trial(varargin)
% TRIAL M-file for trial.fig
% TRIAL, by itself, creates a new TRIAL or raises the
existing
% singleton*.
%
% H = TRIAL returns the handle to a new TRIAL or
the handle to
% the existing singleton*.
%
%
TRIAL('CALLBACK',hObject,eventData,handles,...)
calls the local
% function named CALLBACK in TRIAL.M with the
given input arguments.
%
% TRIAL('Property','Value',...) creates a new TRIAL
or raises the
% existing singleton*. Starting from the left, property
value pairs are
% applied to the GUI before trial_OpeningFunction
gets called. An
% unrecognized property name or invalid value makes
property application
% stop. All inputs are passed to trial_OpeningFcn via
varargin.
%
% *See GUI Options on GUIDE's Tools menu.
Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State,
varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before trial is made visible.
function trial_OpeningFcn(hObject, eventdata, handles,
varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
% varargin command line arguments to trial (see
VARARGIN)
% Choose default command line output for trial
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% Copyright 2002-2003 The MathWorks, Inc.
% UIWAIT makes trial wait for user response (see
UIRESUME)
% uiwait(handles.figure1);
% Edit the above text to modify the response to help trial
% Last Modified by GUIDE v2.5 27-Nov-2004 15:51:07
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @trial_OpeningFcn, ...
'gui_OutputFcn', @trial_OutputFcn, ...
'gui_LayoutFcn', [] , ...
% --- Outputs from this function are returned to the
command line.
function varargout = trial_OutputFcn(hObject, eventdata,
handles)
% varargout cell array for returning output args (see
VARARGOUT);
% hObject handle to figure
III
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
% handles structure with handles and user data (see
GUIDATA)
global image
image=get(handles.image, 'String');
% Get default command line output from handles
global A, global map
structure
[A, map]=imread(image);
varargout{1} = handles.output;
global info
info=imfinfo(image);
global type
% --- Executes during object creation, after setting all properties. type=info.ColorType;
function image_CreateFcn(hObject, eventdata, handles)
% hObject handle to image (see GCBO)
if strcmp('indexed', type )==1;
% eventdata reserved - to be defined in a future version of MATLAB
A=ind2rgb(A, map);
% handles empty - handles not created until after all CreateFcnselse
called
end
axes(handles.HistoMod), plot(0), title('Histogram of
% Hint: edit controls usually have a white background on Windows.
Enhanced Image' );
%
See ISPC and COMPUTER.
axes(handles.histeqhist), plot(0), title('Histogram
if ispc
Equalization Histogram' );
set(hObject,'BackgroundColor','white');
axes(handles.Orihist), plot(0), title('Original Histogram'
else
);
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundCol
global dim
or'));
dim=ndims(A);
end
if dim==3;
axes(handles.Original), imagesc(A), title('Original'),
axis image, axis off;
function image_Callback(hObject, eventdata, handles)
axes(handles.Modify), imagesc(A), title('Original'),
% hObject handle to image (see GCBO)
axis image, axis off;
% eventdata reserved - to be defined in a future version of MATLAB
axes(handles.histoeq), imagesc(A), title('Original'),
% handles structure with handles and user data (see GUIDATA)axis image, axis off;
% Hints: get(hObject,'String') returns contents of image as text elseif dim==2;
%
str2double(get(hObject,'String')) returns contents of image asaxes(handles.Original),
a
colormap('gray'),
double
imagesc(A), title('Original'), axis image, axis off;
% image=get(handles.image, 'String');
axes(handles.Modify), colormap('gray'), imagesc(A),
% A=imread(char(image));
title('Original'), axis image, axis off;
% axes(handles.Original), imagesc(A), title('Original');
axes(handles.histoeq), colormap('gray'), imagesc(A),
%
title('Original'), axis image, axis off;
% axes(handles.Modify), imagesc(A), title('Original');
end
% --- Executes on button press in Load.
function Load_Callback(hObject, eventdata, handles)
% hObject handle to Load (see GCBO)
% eventdata reserved - to be defined in a future version of
MATLAB
IV
% --- Executes on slider movement.
function alpha_Callback(hObject, eventdata, handles)
% hObject handle to alpha (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
set(handles.betaText, 'String', num2str(beta_slider))
% --- Executes during object creation, after setting all
properties.
function beta_CreateFcn(hObject, eventdata, handles)
% hObject handle to beta (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles empty - handles not created until after all
CreateFcns called
% handles structure with handles and user data (see
GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
%
get(hObject,'Min') and get(hObject,'Max') to
determine range of slider
alpha_slider=get(handles.alpha, 'value');
set(handles.alphaText, 'String', num2str(alpha_slider))
% Hint: slider controls usually have a light gray
background, change
%
'usewhitebg' to 0 to use default. See ISPC and
COMPUTER.
usewhitebg = 1;
if usewhitebg
set(hObject,'BackgroundColor',[.9 .9 .9]);
else
% --- Executes during object creation, after setting all
properties.
function alpha_CreateFcn(hObject, eventdata, handles)
% hObject handle to alpha (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles empty - handles not created until after all
CreateFcns called
set(hObject,'BackgroundColor',get(0,'defaultUicontrolB
ackgroundColor'));
end
% Hint: slider controls usually have a light gray
background, change
%
'usewhitebg' to 0 to use default. See ISPC and
COMPUTER.
usewhitebg = 1;
if usewhitebg
set(hObject,'BackgroundColor',[.9 .9 .9]);
else
function alphaText_Callback(hObject, eventdata,
handles)
% hObject handle to alphaText (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBa
ckgroundColor'));
end
% Hints: get(hObject,'String') returns contents of
alphaText as text
%
str2double(get(hObject,'String')) returns contents
of alphaText as a double
alpha_text=get(handles.alphaText, 'String');
set(handles.alpha, 'value', str2num(alpha_text));
% --- Executes on slider movement.
function beta_Callback(hObject, eventdata, handles)
% hObject handle to beta (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
% --- Executes during object creation, after setting all
properties.
function alphaText_CreateFcn(hObject, eventdata,
handles)
% hObject handle to alphaText (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% Hints: get(hObject,'Value') returns position of slider
%
get(hObject,'Min') and get(hObject,'Max') to
determine range of slider
beta_slider=get(handles.beta, 'value');
V
% handles empty - handles not created until after all
CreateFcns called
end
% Hint: edit controls usually have a white background on
Windows.
%
See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
function winsize1_Callback(hObject, eventdata,
handles)
% hObject handle to winsize1 (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBa
ckgroundColor'));
end
% Hints: get(hObject,'String') returns contents of
winsize1 as text
%
str2double(get(hObject,'String')) returns contents
of winsize1 as a double
function betaText_Callback(hObject, eventdata, handles)
% hObject handle to betaText (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
% --- Executes during object creation, after setting all
properties.
function winsize1_CreateFcn(hObject, eventdata,
handles)
% hObject handle to winsize1 (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles empty - handles not created until after all
CreateFcns called
% Hints: get(hObject,'String') returns contents of
betaText as text
%
str2double(get(hObject,'String')) returns contents
of betaText as a double
beta_text=get(handles.betaText, 'String');
set(handles.beta, 'value', str2num(beta_text));
% Hint: edit controls usually have a white background
on Windows.
%
See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
% --- Executes during object creation, after setting all
properties.
function betaText_CreateFcn(hObject, eventdata,
handles)
% hObject handle to betaText (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles empty - handles not created until after all
CreateFcns called
set(hObject,'BackgroundColor',get(0,'defaultUicontrolB
ackgroundColor'));
end
% Hint: edit controls usually have a white background on
Windows.
%
See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
function winsize2_Callback(hObject, eventdata,
handles)
% hObject handle to winsize2 (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBa
ckgroundColor'));
VI
% Hints: get(hObject,'String') returns contents of
winsize2 as text
%
str2double(get(hObject,'String')) returns contents
of winsize2 as a double
[Hr, Hg, Hb, message, B]=proj_trial(image,
alpha_slider, beta_slider, size1, size2);
global dim
if dim==3;
axes(handles.Original), imagesc(A), title('Original'),
axis image, axis off;
axes(handles.Modify), imagesc(B), title('Enhanced'),
axis image, axis off;
axes(handles.histoeq), imagesc(C), title('Enhanced
by Histogram Equalization'), axis image, axis off;
axes(handles.HistoMod), plot(Hr, 'r'), hold on,
plot(Hg, 'g'), hold on, plot(Hb, 'b'), title('Histogram of
Enhanced Image' ), hold off;
H1=imhist(C(:,:,1)./max(max(C(:,:,1))));
H2=imhist(C(:,:,2)./max(max(C(:,:,2))));
H3=imhist(C(:,:,3)./max(max(C(:,:,3))));
H4=imhist(A(:,:,1));
H5=imhist(A(:,:,2));
H6=imhist(A(:,:,3));
axes(handles.Orihist), plot(H4, 'r'), hold on, plot(H5,
'g'), hold on, plot(H6, 'b'), title('Original Histogram' ),
hold off;
axes(handles.histeqhist), plot(H1, 'r'), hold on,
plot(H2, 'g'), hold on, plot(H3, 'b'), title('Histogram
Equalization Histogram' ), hold off;
% --- Executes during object creation, after setting all
properties.
function winsize2_CreateFcn(hObject, eventdata,
handles)
% hObject handle to winsize2 (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles empty - handles not created until after all
CreateFcns called
% Hint: edit controls usually have a white background on
Windows.
%
See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBa
ckgroundColor'));
end
set(handles.message, 'string', message);
set(handles.Modify, 'UserData', B);
set(handles.histoeq, 'UserData', C);
elseif dim==2;
axes(handles.Original), colormap('gray'),
imagesc(A), title('Original'), axis image, axis off;
axes(handles.Modify), colormap('gray'), imagesc(B),
title('Enhanced'), axis image, axis off;
axes(handles.histoeq), colormap('gray'), imagesc(C),
title('Enhanced by Histogram Equalization'), axis
image, axis off;
H1=imhist(C./max(max(C)));
axes(handles.HistoMod), plot(Hg), title('Histogram
of Enhanced Image' );
axes(handles.histeqhist), plot(H1), title('Histogram
Equalization Histogram' );
axes(handles.Orihist), plot(Hr), title('Original
Histogram' );
% --- Executes on button press in Execute.
function Execute_Callback(hObject, eventdata, handles)
% hObject handle to Execute (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
global image
global A, global map
global info
global type
C=histoeq(image);
alpha_slider=get(handles.alpha, 'value');
beta_slider=get(handles.beta, 'value');
size1=get(handles.winsize1, 'String');
size1=str2num(size1);
size2=get(handles.winsize2, 'String');
size2=str2num(size2);
set(handles.message, 'string', message);
set(handles.Modify, 'UserData', B);
set(handles.histoeq, 'UserData', C);
VII
end
H3=imhist(C(:,:,3)./max(max(C(:,:,3))));
H4=imhist(A(:,:,1));
H5=imhist(A(:,:,2));
H6=imhist(A(:,:,3));
axes(handles.Orihist), plot(H4, 'r'), hold on, plot(H5,
'g'), hold on, plot(H6, 'b'), title('Original Histogram' ),
hold off, %axis image, axis off;
% --- Executes on button press in Again.
function Again_Callback(hObject, eventdata, handles)
% hObject handle to Again (see GCBO)
% eventdata reserved - to be defined in a future version
of MATLAB
% handles structure with handles and user data (see
GUIDATA)
image3=get(handles.Modify, 'UserData');
image2=get(handles.histoeq, 'UserData');
image=get(handles.image, 'String');
global A, global map
global info
global type
axes(handles.histeqhist), plot(H1, 'r'), hold on,
plot(H2, 'g'), hold on, plot(H3, 'b'), title('Histogram
Equalization Histogram' ), hold off, %axis image, axis
off;
set(handles.message, 'string', message);
set(handles.Modify, 'UserData', B);
set(handles.histoeq, 'UserData', C);
elseif dim==2;
C=histoeq_two(image2);
alpha_slider=get(handles.alpha, 'value');
beta_slider=get(handles.beta, 'value');
size1=get(handles.winsize1, 'String');
size1=str2num(size1);
size2=get(handles.winsize2, 'String');
size2=str2num(size2);
[Hr, Hg, Hb, message, B]=proj_two(image3,
alpha_slider, beta_slider, size1, size2);
global dim
if dim==3;
axes(handles.Modify), colormap('gray'), imagesc(B),
title('Enhanced'), axis image, axis off;
axes(handles.histoeq), colormap('gray'), imagesc(C),
title('Enhanced by Histogram Equalization'), axis
image, axis off;
H1=imhist(C./max(max(C)));
axes(handles.HistoMod), plot(Hg), title('Histogram
of Enhanced Image' );
axes(handles.histeqhist), plot(H1), title('Histogram
Equalization Histogram' );
H2=imhist(A);
axes(handles.Orihist), plot(H2), title('Original
Histogram' );
axes(handles.Modify), imagesc(B), title('Enhanced'),
axis image, axis off;
axes(handles.histoeq), imagesc(C), title('Enhanced by
Histogram Equalization'), axis image, axis off;
axes(handles.HistoMod), plot(Hr, 'r'), hold on, plot(Hg,
'g'), hold on, plot(Hb, 'b'), title('Histogram of Enhanced
Image' ), hold off, %axis image, axis off;
H1=imhist(C(:,:,1)./max(max(C(:,:,1))));
H2=imhist(C(:,:,2)./max(max(C(:,:,2))));
set(handles.message, 'string', message);
set(handles.Modify, 'UserData', B);
set(handles.histoeq, 'UserData', C);
end
VIII
2. User Define Functions:
function [Hr, Hg, Hb, message, im]=proj_trial(image,
alpha, beta, size1, size2);
[Image, map]=imread(image);
info=imfinfo(image);
type=info.ColorType;
if strcmp('indexed', type )==1;
Image=ind2rgb(Image, map);
else
end
end
end
end
if k>0;
message=char('Beta is too large.');
else
message=char('Have a nice day!');
end
Hr=imhist(F./255);
Hg=imhist(f./255);
Hb=0;
im=f;
check=class(Image);
switch check;
case{'uint8'};
M=2^8-1;
case{'uint16'};
M=2^16-1;
case{'double'};
M=1;
elseif dimension==3;
R=Image(:,:,1);
R=double(R);
[rowR, colR]=size(R);
R_bar=R./M;
log_R_bar=log10(R_bar);
aR_bar=imfilter(R_bar, w, 'symmetric');
log_aR_bar=log10(aR_bar);
end
win_size=ones(size1, size2);
F=double(Image);
w=(1/size1/size2).*win_size;
alpha=alpha;
beta=beta;
dimension=ndims(Image);
log_R_bar_prime=alpha.*log_aR_bar+beta.*(log_R_ba
r-log_aR_bar);
R_bar_prime=10.^log_R_bar_prime;
r=R_bar_prime.*M;
if dimension==2;
[row, col]=size(F);
f_bar=F./M;
log_f_bar=log10(f_bar);
a_bar=imfilter(f_bar, w, 'symmetric');
log_a_bar=log10(a_bar);
log_f_bar_prime=alpha.*log_a_bar+beta.*(log_f_barlog_a_bar);
f_bar_prime=10.^log_f_bar_prime;
f=f_bar_prime.*M;
G=Image(:,:,2);
G=double(G);
[rowG, colG]=size(G);
G_bar=G./M;
log_G_bar=log10(G_bar);
aG_bar=imfilter(G_bar, w, 'symmetric');
log_aG_bar=log10(aG_bar);
log_G_bar_prime=alpha.*log_aG_bar+beta.*(log_G_b
ar-log_aG_bar);
G_bar_prime=10.^log_G_bar_prime;
g=G_bar_prime.*M;
k=0;
for i=1:row;
for j=1:col;
if f(i,j)>M;
k=k+1;
else
k=k;
B=Image(:,:,3);
B=double(B);
[rowG, colG]=size(G);
B_bar=B./M;
IX
log_B_bar=log10(B_bar);
aB_bar=imfilter(B_bar, w, 'symmetric');
log_aB_bar=log10(aB_bar);
else
l=l;
end
end
end
end
if l>0;
message=char('Beta is too large.');
else
message=char('Have a nice day!');
end
Hr=imhist(R_bar_prime);
Hg=imhist(G_bar_prime);
Hb=imhist(B_bar_prime);
im=f;
end
log_B_bar_prime=alpha.*log_aB_bar+beta.*(log_B_barlog_aB_bar);
B_bar_prime=10.^log_B_bar_prime;
b=B_bar_prime.*M;
f=cat(3, r,g,b);
f=f./max(max(max(f)));
l=0;
for k=1:3;
for i=1:rowG;
for j=1:colG;
if f(i,j,k)>M;
l=l+1;
function [Hr, Hg, Hb, message, im]=proj_two(image,
alpha, beta, size1, size2);
else
k=k;
end
end
end
if k>0;
message=char('Beta is too large.');
else
message=char('Have a nice day!');
end
Hr=imhist(F./255);
Hg=imhist(f./255);
Hb=0;
im=f;
win_size=ones(size1, size2);
F=double(image);
w=(1/size1/size2).*win_size;
alpha=alpha;
beta=beta;
dimension=ndims(image);
if dimension==2;
[row, col]=size(F);
f_bar=F./max(max(F));
log_f_bar=log10(f_bar);
a_bar=imfilter(f_bar, w, 'symmetric');
log_a_bar=log10(a_bar);
log_f_bar_prime=alpha.*log_a_bar+beta.*(log_f_barlog_a_bar);
f_bar_prime=10.^log_f_bar_prime;
f=f_bar_prime.*max(max(F));
A=max(max(F));
k=0;
for i=1:row;
for j=1:col;
if f(i,j)>A;
k=k+1;
elseif dimension==3;
R=image(:,:,1);
R=double(R);
R_bar=R./max(max(R));
log_R_bar=log10(R_bar);
aR_bar=imfilter(R_bar, w, 'symmetric');
log_aR_bar=log10(aR_bar);
log_R_bar_prime=alpha.*log_aR_bar+beta.*(log_R_barlog_aR_bar);
R_bar_prime=10.^log_R_bar_prime;
X
r=R_bar_prime.*max(max(R));
f=cat(3, r,g,b);
f=f./max(max(max(f)));
A=max(max(max(f)));
l=0;
for k=1:3;
for i=1:rowG;
for j=1:colG;
if f(i,j,k)>A;
k=k+1;
else
k=k;
end
end
end
end
if k>0;
message=char('Beta is too large.');
else
message=char('Have a nice day!');
end
Hr=imhist(R_bar_prime);
Hg=imhist(G_bar_prime);
Hb=imhist(B_bar_prime);
im=f;
end
G=image(:,:,2);
G=double(G);
[rowG, colG]=size(G);
G_bar=G./max(max(G));
log_G_bar=log10(G_bar);
aG_bar=imfilter(G_bar, w, 'symmetric');
log_aG_bar=log10(aG_bar);
log_G_bar_prime=alpha.*log_aG_bar+beta.*(log_G_barlog_aG_bar);
G_bar_prime=10.^log_G_bar_prime;
g=G_bar_prime.*max(max(G));
B=image(:,:,3);
B=double(B);
B_bar=B./max(max(B));
log_B_bar=log10(B_bar);
aB_bar=imfilter(B_bar, w, 'symmetric');
log_aB_bar=log10(aB_bar);
log_B_bar_prime=alpha.*log_aB_bar+beta.*(log_B_barlog_aB_bar);
B_bar_prime=10.^log_B_bar_prime;
b=B_bar_prime.*max(max(B));
function H=histoeq(image);
[Image, map]=imread(image);
info=imfinfo(image);
type=info.ColorType;
if strcmp('indexed', type )==1;
Image=ind2rgb(Image, map);
else
end
elseif dimension==3;
Image=Image./max(max(max(Image)));
R=Image(:,:,1);
G=Image(:,:,2);
B=Image(:,:,3);
r=histeq(R);
g=histeq(G);
b=histeq(B);
Image=double(Image);
dimension=ndims(Image);
if dimension==2;
Image=Image./max(max(Image));
H=histeq(Image);
H=cat(3, r,g,b);
end
XI
function H=histoeq_two(image);
R=Image(:,:,1);
G=Image(:,:,2);
B=Image(:,:,3);
Image=double(image);
dimension=ndims(Image);
if dimension==2;
Image=Image./max(max(Image));
H=histeq(Image);
elseif dimension==3;
Image=Image./max(max(max(Image)));
r=histeq(R);
g=histeq(G);
b=histeq(B);
H=cat(3, r,g,b);
end
XII
Appendix IV: References
[1]
J.S. Lee, “Digital Image Enhancement and Noise Filtering by Use of Local Statistics,”
IEEE Trans. Pattern Anal. Machine Intell., vol. PAMI-2, pp165-168, Mar. 1980
[2]
G. Deng, L.W. Cahill, G.R. Tobin, “The Study of Logarithmic Image Processing Model
and Its Application to Image Enhancement,” IEEE Transaction on Image Processing, vol 4,
pp 506-512, April 1995.
[3]
Digital Image Processing, R.C.Gonzalez, and R.E Woods Addison-Wesley Pub. Co., NY.
(2nd Edition) 2002
[4] Yingzi Du, “MATLAB GUI Tutorial”, University of Stuttgart, 2004.
< http://matlabdb.mathematik.uni-stuttgart.de/download.jsp?MC_ID=5&MP_ID=252>
[5]
M. Jourlin and J.C. Pinoli, “A model for logarithmic image processing.” J. Microscopy,
vol. 149, pp. 21-35, Jan. 1988
XIII
Appendix V: Individual Responsibility Chart
Task
Brain Storm, Literature
Research
Coding
Image Testing
Report
Power Point Slides
Presentation
Overall
Oiki Wong
50%
Benjamin J. Weisenbeck
50%
65%
70%
70%
70%
50%
62.5%
35%
30%
30%
30%
50%
37.5%
Signatures:
Benjamin J. Weisenbeck
______________________________
Oiki Wong
______________________________
XIV
Download