Histogram Equalization cont.: Examples for histograms: and

Transcription

Histogram Equalization cont.: Examples for histograms: and
Histogram Equalization cont.:
Examples for histograms:
and corresponding cumulative histograms:
Example for a histogram after histogram
equalization, without dither:
Observe: For a constant dithered histogram, the
average intensity over a intensity bin needs to be
constant. The histogram with dither:
Example for a histogram stretching: The above
images of the histograms where a result of a
histogram stretching. The original picture (ignore
the picture content here) was much darker:
Example of an histogram equalization on above
image (in Photoshop: “Tonwertangleichung”):
Observe: This might not what we wanted for this
picture. The background structure become very
clear, but that is not the interesting part in this
case.
Another example is the following image (of
Maplewood, NJ):
Histogram equalization:
Observe: the darker area is indeed improved, but
we get artificial steps in the sky area. This shows
that we need the dither to avoid those artificial
steps.
Another possibility for image improvement:
Gamma Correction
For gamma correction, instead of using our
histogram to derive a maping for the intensities,
we take a pre-defined function. We look at the
pre-processing steps in the human eye. Webers
Law tells us that some logarithmic processing is
taking place. We can now also apply this
logarithmic processing to improve our image.
This allows us, for instance, to map a larger
dynamic intensity range to a smaller range. The
effect can be used to increase small intensity in
an image, to make them more visible, without
adding un-natural artifacts.
Take above image, but now apply this logarithmic
processing. We actually do something similar to a
logarithmic processing, which is using an
exponential function with an exponent smaller 1
(in Photoshop: gamma=2).
Observe: We indeed made the dark portions of
the image brighter and more visible, without
distorting the bright part of the image too much.
For instance, the artificial steps of the histogram
equalization are now avoided.
For the gamma correction we have a nonlinear
mapping of the intensity V of the form:
V o u t =V 1/i nγ (see Wikipedia, “Gamma Correction”). In
Photoshop a factor of 2 results in an exponent of
0.5 (in Photoshop: “Tonwertkorrektur”, slider for
middle intensity, similar also for the program
“Gimp”).
Matlab/Octave Example
pic=imread('IMGP1690.JPG');
G=pic(:,:,2);
size(G)
%ans =
%2448 3264
imshow(G,[0 255])
Gheq=zeros(size(G));
%re-normalization factor:
c=255/(255^(1/2));
Ggamma= c* G.^(1/2);
imshow(Ggamma,[0 255]);
Highpass Filtering and Unsharp Masking
Unsharp masking:
Unsharp masking originated in analog
photography. There an unsharp focused image
was converted into its negative, and then a
certain fraction of it added to the picture. This
resulted in a sharper looking image.
Mathematically, this can be written as:
g ( n1 , n2 ) =a f ( n1 , n 2 )−b f L ( n1 , n2 )
Where f is the original image and
f L is the
lowpass filtered or unsharp image. This can be
rewritten as:
g ( n1 , n2 ) =( a−b ) f L ( n1 , n 2 )+a f H ( n1 , n2 )
Where
f H= f − f
L
is the highpass part of the
image.
We can see in this way, the highpass part or the
higher frequencies in the image are emphasized
(both, a and b are positive, and a>b).
We can also write it as (mask as high pass part):
m a s k= f − f L
g= f +c⋅m a s k
g= f +c⋅( f − f L )
g= f ( 1+c ) −c⋅f
Such that a=1+c , b=c .
L
Octave/Matlab Example:
We use a 2D sine-window filter from
Lecture 12 for the unsharp image,
h=sin(pi/32*((1:32)-0.5));
h2=h'*h;
%unsharp image:
%We use a zoom into the upper left hand corner of the image:
G=G(1:300,1:400);
imshow(G);
filtG=conv2(G,h2);
%re-normalization of filtered image:
filtG=filtG/max(max(filtG))*255;
[rows,cols]=size(G);
%compute unsharp masked image a*f-b*filtG, for a=0.7, b=0.3,
%with shift compensation from convolution/filtering:
Gum=0.7*G-0.3*filtG(16+(1:rows),16+(1:cols));
max(max(Gum))
%ans = 123
imshow(Gum,[0 123])
The effective filter we used is:
delta=zeros(32,32);
delta(16,16)=1;
%normalized low pass filter (total energy=1):
h2n=h2/sqrt(sum(sum(h2.^2)))
%unshar masking is 0.7 original -0.3 low pass filtered, resulting in
%total filter:
htotal=0.7*delta -0.3*h2n;
%Look at the impulse response:
mesh(htotal);