30
Audio/Videosignalverarbeitung, 2D Signal Processing Continuation window method: The effect of the separable and the circular symmetric window method can be seen in following picture:

Audio/Videosignalverarbeitung, D Signal Continuation...Audio/Videosignalverarbeitung, 2‐D Signal Processing Continuation window method: The effect of the separable and the circular

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

  • Audio/Videosignalverarbeitung, 

    2‐D Signal Processing

    Continuation window method:

    The effect of the separable and the circular symmetricwindow method can be seen in following picture:

  • From: Jae S. Lim: Two Dimensional Signal and ImageProcessing

    There are more practical window functions than therectangular window. The rectangular window often leads tonot enough stop band attenuation (the stop band is thefrequency range which we would like to remove, but withreal filters we only get a certain attenuation of thesefrequencies).  Hence improved windows leading to higherstop band attenuation are useful:

    The Hamming Window:

    wa( t )=(0.54+ 0.46cos (π tτ ), (t )< τ0 , o t h e r w i se )In Matlab/Octave:

    A Hamming Window in 1D with 21 taps is obtained with:t=‐1:0.1:1

    %t =%Columns 1 through 8:%‐1.0000 ‐0.9000 ‐0.8000 ‐0.7000 ‐0.6000 ‐0.5000 ‐0.4000 ‐0.3000%Columns 9 through 16:%‐0.2000 ‐0.1000 0.0000 0.1000 0.2000 0.3000 0.4000 0.5000%Columns 17 through 21:%0.6000 0.7000 0.8000 0.9000 1.0000hw=0.54+0.46*cos(pi*t);plot(hw)

  • A resulting separable 2‐D Window is then obtained with:hw2=hw'*hw;mesh(hw2)

  • Its contour plot is:

    contour(hw2)

    axis equal;

  • We see that it is not perfectly rotational symmetric, thecontour lines are not perfect circles.

    We can now produce a 2‐Dimensional frequency responseplot by writing a function “freqz2” in Matlab/Octave. Create afile freqz2.m with the following content:

    function H2=freqz2(x), 

    %2‐Dimensional frequency response of a 2D impulse response x 

    Nx=128; 

    Ny=128; 

    H2=fftshift(fft2(x,Ny,Nx)); 

    fscalex=2/Nx*(‐(Nx/2‐1):(Nx/2)); 

    fscaley=2/Ny*(‐(Ny/2‐1):(Ny/2)); 

  • mesh(fscalex,fscaley,20*log10(abs(H2)));

    In the Matlab/Octave command window then type

    freqz2(hw2);

    and we obtain the following 2‐D frequency response (themagnitude in dB):

    Here it can be seen even more, that the frequency responseis not rotational symmetric. In diagonal directions, theattenuation in the stop‐band improves much faster thanalong the axis. But for the image, there is usually no reason to

  • treat spacial frequencies along diagonal directions differentfrom the ones along the coordinate axis!

    To improve this, a rotational symmetric, non‐separable 2Dwindow is obtained with the following. First write a function„hamming“ and store it in the file „hamming.m:

    function hw=hamming(t); 

    %function to compute the Hamming window, for ‐1 

  • Its contour plot is:

    contour(hw2r);

    axis equal;

  • This is now rotational symmetric, its contour lines are perfectcircles (except for rounding at the grid)!

    The 2‐D magnitude frequency response with our self madefreqz2 function now is

    freqz2(hw2r);

  • Here we can now see that the magnitude of our frequencyresponse is (almost, except for some pixel grid influences)perfectly rotational symmetric!

  • Other  useful windows

    The Kaiser Window is:

    wa( t )=(I 0(α√1−(tτ )2)

    I 0(α ), (t )< τ

    0 , o t he r w i s e)

    These window functions can now be applied in the same wayas we saw for the rectangular window: separable along theaxis, or circular symmetric around zero.

    The following picture shows example frequency responses ofthese windows:

  •  

    From: Jae S. Lim: Two Dimensional Signal and ImageProcessing

  • Observe: we have a trade‐off between the width of the mainlobe and the stop band attenuation. This leads tocorresponding properties of the resulting filters. These arethe ideal filters multiplied with these window functions,hence the frequency response is the convolution of the idealfrequency response with the frequency response of thewindow function. This means the width of the main lobe ofthe frequency response of the window function determinesthe width of the transition band of our resulting filter. Thesize of the ripples of the frequency response of the windowdetermines the stop band attenuation of the resulting filter.

    The following shows an example of a resulting low pass filter:

  • From: Jae S. Lim: Two Dimensional Signal and ImageProcessing

    The next example shows a band pass filter:

  • From: Jae S. Lim: Two Dimensional Signal and ImageProcessing

  • Image Enhancement

    Gray scale modification: 

    The intensity distribution of the pixels of an image can beanalyzed using a so‐called Histogram, which is, in principle,the probability density function of the intensity (luminosity)in an image.

    We can change this distribution by applying functions whichmap intensities to (other) intensities. Example:

  • From: Jae S. Lim: Two Dimensional Signal and ImageProcessing

    The resulting histograms of original and modified picture canbe seen in the following picture:

  • From: Jae S. Lim: Two Dimensional Signal and ImageProcessing

    By using this mapping or function for the intensity, we nowobtain a new histogram or probability density function.

    Observe: The modified image has a broader histogram, wherealmost all intensities are used. This is useful to better use adisplay. The resulting modified picture appears with morecontrast (and brighter).

  • Matlab/Octave example for a histogram:

    pic=imread('IMGP1690.JPG');

    imshow(pic);

    G=pic(:,:,2);

    size(G)

    %ans =%2448 3264%reshape(G,1,““) turns the matrix G into a (row) vector (y dimension 1, xdimension open with „“)%hist(..,256) computes the histogram for 256 intensity bins:hist(reshape(G,1,""),256)

  • This is the histogram of our green component of our image.The horizontal axis is the intensity value, the vertical axis isthe number of pixels which have this intensity value. We seethat the most common intensity value is 255, which almost400000 pixels have. Since this is the biggest value, it showsthat this picture is partly over‐exposed.

  • Histogram Modification

    Goal: Make resulting histogram of the modified image flat,such that all intensities have equal probability. We choosethis goal because we hope to obtain a very “balanced” image,and because it is a simple mathematical formulation!

    Approach:

    Assume we have an image with a probability density function

    (pdf, histogram)  , with x being the intensity of the

    original, and a desired probability density function  ,with y the intensity in the modified image. Observe that weassume a continuous intensity distribution, not a discretedistribution for which we would get a histogram, because themathematical formulation becomes easier!

    Hence our goal is:

    A constant pdf (or histogram the discrete case), with theconstant c.

    What we now have is a (continuous) function or mapping gwhich maps the intensities x to y,

    With the desired property for the histogram. To reach thisgoal, we first need to know how g(x) affects the resulting

  • histogram. For probability density functions and a change ofvariables, it can be shown that

    (see also: Wikipedia, “Probability Density Function”). Thismeans that the area of an infinitesimal narrow rectangle of

    the histogram stays the same in both histograms.   is a very

    small distance on the x axis of the original image,   is thecorresponding distance for the histogram of the modifiedimage. In the discrete, histogram case, this means thenumber of pixels with a given intensity stays the same, theyjust appear at a different intensity. The height for a givenintensity in the histogram corresponds to the area of thenarrow bar (with width dx or dy resp.) at a given intensity.The area in the continuous case corresponds the countablenumber in the discrete case, for a given intensity.

    Now reformulate this basic equation (the constant area):

    Since we would like to have a constant histogram for theintensities y, we get:

  • Observe: Our histogram is given not as a mathematicalfunction but as a numerical function. Hence we need tocompute the integral numerically, and we obtain a sum (the

    integral becomes a sum, the   becomes a  . We take astarting point, and for histograms the 0 as starting point isuseful. Then we integrate up to an endpoint, which is thenour new variable. In this way we obtain the so calledcumulative histogram:

    At this point we can go from the continuous case back to thediscrete case. We replace our probability density function bythe histogram of our image, and the integral by a sum.

    The cumulative histogram is the sum of the histogram from

    intensity 0 up to intensity  . Observe that this way, we

  • obtain a monotonically increasing function  , which wenow can apply to the intensities of the original image. Theresulting image should now have the desired constanthistogram!

    Matlab/Octave Example:

    Take our example picture, compute the histogram, and assignit to a variable:

    pichist=hist(reshape(G,1,""),256);

    plot(pichist)

  • We can now compute the cumulative histogram from thisfunction,

    for x=1:256,

      cumhist(x)=sum(pichist(1:x));end

    plot(cumhist)

    To obtain our desired function g(x) we just need to normalizethis cumulative histogram:

    g=cumhist/cumhist(256)*255;

    plot(g)

  • Now we can use this function g to generate our histogramequalized image (the “+1” comes because Matlab/Octaveindices start with 1):

    Gheq=zeros(size(G));

    for y=1:2448,  for x=1:3264,    Gheq(y,x)=g(G(y,x)+1);  endend

    imshow(Gheq,[]);

  • This is now our histogram equalized image. Observe that wehave indeed a much more balanced picture, but we also seeartificial brightness steps in the sky area.

    Its new histogram is now

    hist(reshape(Gheq,1,""),256)

  • This is the histogram of our histogram equalized image. Weexpect a flat histogram, but it does not look flat. Instead wesee a spacing between histogram lines, not all brightnesslevels are used. This makes the density of pixels constant.

    The number of pixels over a certain brightness range  Δ y isconstant! This can also be seen if we plot the histogram withwider bins, averaging out the gaps between the lines. E.g.reducing the number of bins from 256 to 30 results in

    hist(reshape(Gheq,1,""),30)

  • This histogram now is practically flat, except for some“noise”, and the peak resulting from the over‐exposed areas.

    Observe: The formulation we used to obtain our function g isbased on continuous values. In our images we have usuallydiscrete values of our intensities, for instance between 0 and255 if we have 8 bit for the intensity. Hence we also getdiscrete histograms, with a certain width of an intensity bin.In the original this width is usually 1 (integer). If we have areasonably dense histogram, the result will indeed be amainly flat histogram (the eye basically averages thehistogram), but if we have a sparse histogram (more distancebetween intensities), we will see the number of pixels at a

  • given intensity to indeed stay constant, and hence appearuneven after histogram equalization. But observe that even inthis case, the areas around a given intensity stays the same(e.g. number of pixels times the distance to the nextintensity).

    To compute the corresponding continuous histograms, wecan imagine to use dither with a width of an intensity bin forall the intensities. This would distribute the intensities over abin, so that it is no longer concentrated in a peak. We wouldtake a line from the histogram and turn it into a bar of awidth, such that it covers any empty area besides the line. Forthe modified image, we usually obtain unequal widths for theintensity bins. For the wider bin, this means the intensitiesare distributed over a wider area, and hence the height in the(now continuous) histogram would be correspondingly lower.Our formulation is derived from continuous histograms (ormore precisely probability density functions), hence weobtain the constant histogram for the continuous version.This means we get a truly constant histogram only for ourmodified image including this dither!

    Comment: This histogram equalization works very well, butsometime too good, because it shows some detail too clear,and a can appear unnatural. A more natural choice for thegoal for the histogram might be a gauss like distribution. Thiscan be obtained with the same approach as above, by justchanging the constant c to a function of y, hence c(y) (orbetter: c(y(x)) for our formulation).