Lec5 Image Enhancement

Preview:

Citation preview

  • 8/11/2019 Lec5 Image Enhancement

    1/104

    Digital Image Processing

    Lecture 3: Basic Image Processing

    Sibt ul Hussain

  • 8/11/2019 Lec5 Image Enhancement

    2/104

    Slides Credit: Andrew Zisserman

  • 8/11/2019 Lec5 Image Enhancement

    3/104

    Slides Credit: Andrew Zisserman

  • 8/11/2019 Lec5 Image Enhancement

    4/104

    Slides Credit: Andrew Zisserman

  • 8/11/2019 Lec5 Image Enhancement

    5/104

    Slides Credit: Andrew Zisserman

  • 8/11/2019 Lec5 Image Enhancement

    6/104

  • 8/11/2019 Lec5 Image Enhancement

    7/104

  • 8/11/2019 Lec5 Image Enhancement

    8/104

  • 8/11/2019 Lec5 Image Enhancement

    9/104

    An Image as 2D Function

  • 8/11/2019 Lec5 Image Enhancement

    10/104

    An Image as 2D Function

  • 8/11/2019 Lec5 Image Enhancement

    11/104

    An Image as 2D Function

  • 8/11/2019 Lec5 Image Enhancement

    12/104

    Key Stages in Digital Image Processing: A

    Traditional Linear View

    Image

    Acquisition

    Image

    Restoration

    or!"ological

    Processing

    Segmentation

    #$%ect

    Recognition

    Image&n"ancement

    Re!resentation

    ' Descri!tion

    Pro$lem Domain

    Colour Image

    Processing

    Image

    Com!ression

  • 8/11/2019 Lec5 Image Enhancement

    13/104

    Key Stages in Digital Image Processing: A

    Traditional Linear View

    Image

    Acquisition

    Image

    Restoration

    or!"ological

    Processing

    Segmentation

    #$%ect

    Recognition

    Image&n"ancement

    Re!resentation

    ' Descri!tion

    Pro$lem Domain

    Colour Image

    Processing

    Image

    Com!ression

  • 8/11/2019 Lec5 Image Enhancement

    14/104

    Key Stages in Digital Image Processing:

    Image &n"ancement

    Image

    Acquisition

    Image

    Restoration

    or!"ological

    Processing

    Segmentation

    #$%ect

    Recognition

    Image&n"ancement

    Re!resentation

    ' Descri!tion

    Pro$lem Domain

    Colour Image

    Processing

    Image

    Com!ression

    Processing an image so t"at t"e result ismore suita$le (or a !articular a!!lication) *s"ar!ening or de+$lurring an out o( (ocus image, "ig"lig"ting edges, im!ro-ingimage contrast, or $rig"tening an image, remo-ing noise.

    T"i $ id d i t"

  • 8/11/2019 Lec5 Image Enhancement

    15/104

    Key Stages in Digital Image Processing:

    Image Resotration

    Image

    Acquisition

    Image

    Restoration

    or!"ological

    Processing

    Segmentation

    #$%ect

    Recognition

    Image&n"ancement

    Re!resentation

    ' Descri!tion

    Pro$lem Domain

    Colour Image

    Processing

    Image

    Com!ression

    T"is may $e considered as re-ersing t"edamage done to an image $y a /nown cause) *remo-ing o( $lurcaused $y linear motion, remo-al o( o!tical distortions.

  • 8/11/2019 Lec5 Image Enhancement

    16/104

    Key Stages in Digital Image Processing:

    or!"ological Processing

    Image

    Acquisition

    Image

    Restoration

    or!"ological

    Processing

    Segmentation

    #$%ect

    Recognition

    Image&n"ancement

    Re!resentation

    ' Descri!tion

    Pro$lem Domain

    Colour Image

    Processing

    Image

    Com!ression

  • 8/11/2019 Lec5 Image Enhancement

    17/104

    Key Stages in Digital Image Processing:

    Segmentation

    Image

    Acquisition

    Image

    Restoration

    or!"ological

    Processing

    Segmentation

    #$%ect

    Recognition

    Image&n"ancement

    Re!resentation

    ' Descri!tion

    Pro$lem Domain

    Colour Image

    Processing

    Image

    Com!ression

  • 8/11/2019 Lec5 Image Enhancement

    18/104

    Key Stages in Digital Image Processing:

    Re!resentation ' Descri!tion

    Image

    Acquisition

    Image

    Restoration

    or!"ological

    Processing

    Segmentation

    #$%ect

    Recognition

    Image&n"ancement

    Re!resentation

    ' Descri!tion

    Pro$lem Domain

    Colour Image

    Processing

    Image

    Com!ression

  • 8/11/2019 Lec5 Image Enhancement

    19/104

    Key Stages in Digital Image Processing:

    #$%ect Recognition

    Image

    Acquisition

    Image

    Restoration

    or!"ological

    Processing

    Segmentation

    #$%ect

    Recognition

    Image&n"ancement

    Re!resentation

    ' Descri!tion

    Pro$lem Domain

    Colour Image

    Processing

    Image

    Com!ression

  • 8/11/2019 Lec5 Image Enhancement

    20/104

    Key Stages in Digital Image Processing:

    Image Com!ression

    Image

    Acquisition

    Image

    Restoration

    or!"ological

    Processing

    Segmentation

    Re!resentation

    ' Descri!tion

    Image&n"ancement

    #$%ect

    Recognition

    Pro$lem Domain

    Colour Image

    Processing

    Image

    Com!ression

  • 8/11/2019 Lec5 Image Enhancement

    21/104

    Key Stages in Digital Image Processing:

    Color Image Processing

    Image

    Acquisition

    Image

    Restoration

    or!"ological

    Processing

    Segmentation

    Re!resentation

    ' Descri!tion

    Image&n"ancement

    #$%ect

    Recognition

    Pro$lem Domain

    Color Image

    Processing

    Image

    Com!ression

  • 8/11/2019 Lec5 Image Enhancement

    22/104

    An Image as 2D Function

  • 8/11/2019 Lec5 Image Enhancement

    23/104

    Sampling

    Digitization of Coordinate Values

  • 8/11/2019 Lec5 Image Enhancement

    24/104

    Quantization

  • 8/11/2019 Lec5 Image Enhancement

    25/104

  • 8/11/2019 Lec5 Image Enhancement

    26/104

    Image Formation

    Sampling: Digitization of the coordinate values,

    Depends on effective number of digital sensors.

    Defines the spatial resolution of image.

    Quantization: Digitization of the amplitude values

    Defined in number of bits, usually 8 bits are used

    to record 256 different shades or light variations.

  • 8/11/2019 Lec5 Image Enhancement

    27/104

    Types of image

    Binary: Each pixel is black or white, so only one bit is needed

    per pixel.

    GrayScale: Each pixel is a shade of gray normally from black

    (0) to white (255) so 8 bits per pixel.

    Colour: Each pixel is a colour described by the mix of red,

    green or blue (RGB). Each channel has a range of 0-255, so

    24bits in total.

    Indexed: Most colour images only use a subset of the possible

    colours, for reduction of storage a colour map is used.

  • 8/11/2019 Lec5 Image Enhancement

    28/104

    Binary Image

  • 8/11/2019 Lec5 Image Enhancement

    29/104

    Gray Scale Image

    White = 255 Black = 0

    >> w=imread(tire.tif); figure ,imshow(w), pixval on

  • 8/11/2019 Lec5 Image Enhancement

    30/104

    RGB Image

    >> pep=imread('peppers.png'); figure(1) ,imshow(pep); pixval on;

    >> r=pep(:,:,1);g=pep(:,:,2); b=pep(:,:,3);figure(2),imshow(r),pixval on

  • 8/11/2019 Lec5 Image Enhancement

    31/104

    Indexed Image

  • 8/11/2019 Lec5 Image Enhancement

    32/104

    Image Size

    Image files tend to be large

    e.g. 512 x 512 gray scale image requires 256

    Kbytes = 512 x 512 x 8bits. For an RGB color image this will be 768

    Kbytes= 256 x 3

  • 8/11/2019 Lec5 Image Enhancement

    33/104

    General Commands

    imread: Read an image

    figure: creates a figure on the screen.

    imshow(g): which displays the matrix g as an image.

    pixval on: turns on the pixel values in our figure.

    impixel(i,j): the command returns the value of the pixel (i,j)

    iminfo: Information about the image.

  • 8/11/2019 Lec5 Image Enhancement

    34/104

  • 8/11/2019 Lec5 Image Enhancement

    35/104

    Image Enhancement

    Image is composed of informative pattern modified bynon-informative variations.

    Goal : Enhance informative pattern based on image data.

    Examples: noise filtering,contrast adjustment, gamma

    correction, etc. Two types of image enhancement methods

    Spatial domain (local) methods: operate directly onimage pixels.

    Frequency domain (global) methods: operate in atransformed domain.

    We will mainly deal with spatial domain methods.

  • 8/11/2019 Lec5 Image Enhancement

    36/104

    Spatial Domain Methods

    f(x,y)

    g(x,y)

    g(x,y)

    f(x,y)

    Point

    Processing

    Area/MaskProcessing

  • 8/11/2019 Lec5 Image Enhancement

    37/104

    Point Processing

    Simplest yet contain powerful processing methods

    for image enhancement.

    Arithmetic operations

    Histogram based methods

    Histogram Stretching

    Histogram Equalization

  • 8/11/2019 Lec5 Image Enhancement

    38/104

    Point Processing Transformations

    Convert a given pixel value to a new pixel value based on

    some predefined function.

  • 8/11/2019 Lec5 Image Enhancement

    39/104

    Identity Transformation

  • 8/11/2019 Lec5 Image Enhancement

    40/104

    1. Arithmetic Operations

    Apply simple function y= f(x) to each pixel gray value, those

    include

    Additions and subtractions:

    Multiplication by a constant:

    Where C is a constant

    Note: Clipping will be required to keep the values in the range.

  • 8/11/2019 Lec5 Image Enhancement

    41/104

    Addition and Subtraction

    dd dSb

  • 8/11/2019 Lec5 Image Enhancement

    42/104

    Addition and Subtraction

    Adding a constant lighten the image.

    Subtracting makes it darker.

    Add dSb

  • 8/11/2019 Lec5 Image Enhancement

    43/104

    Addition and Subtraction

    >> im=imread('blocks.tif');

    >> im = double(im) + 128;

    >> im = min(im, 255); figure, imshow(im,[])

    >> im=imread('block.jpg');

    >> im = double(im) - 128;

    >> im = max(im, 0); figure, imshow(im,[])

    OR

    >> im=imread('blocks.tif'); im=imadd(im,128),imshow(im);

    >> im=imread('block.jpg'); im=imsubtract(im,128),

    M lili i dDiii

  • 8/11/2019 Lec5 Image Enhancement

    44/104

    Multiplication and Division

    Multiplication implies scaling.

    Lightens if C > 1; Darkens if C < 1;

    M ltiliti dDiii

  • 8/11/2019 Lec5 Image Enhancement

    45/104

    Multiplication and Division

    I C l t

  • 8/11/2019 Lec5 Image Enhancement

    46/104

    Image Complements

    Sliti

  • 8/11/2019 Lec5 Image Enhancement

    47/104

    Solarization

    Sliti

  • 8/11/2019 Lec5 Image Enhancement

    48/104

    Solarization

    Complementing dark Pixels. Complementing light Pixels.

  • 8/11/2019 Lec5 Image Enhancement

    49/104

  • 8/11/2019 Lec5 Image Enhancement

    50/104

    SomeExamples

  • 8/11/2019 Lec5 Image Enhancement

    51/104

    Some Examples

    Multiplication

    SomeExamples

  • 8/11/2019 Lec5 Image Enhancement

    52/104

    Some Examples

    Division

    Credits:0aris Pa!asai/a+0anusc"

    odesy

    SlicingTransformations

  • 8/11/2019 Lec5 Image Enhancement

    53/104

    Slicing Transformations

    Stretch grayle!el ranges "here "e desire more information (slope # $)%&ompress grayle!el ranges that are of little interest (' slope $)%

    SlicingTransformations

  • 8/11/2019 Lec5 Image Enhancement

    54/104

    Slicing Transformations

    Add

  • 8/11/2019 Lec5 Image Enhancement

    55/104

    Image Addition Useful for combining information between twoimages

    ImageAveraging

  • 8/11/2019 Lec5 Image Enhancement

    56/104

    Image Averaging Image quality can be improved by averaging a

    number of images together (very useful inastronomy applications).

    1 23

    43 13 233

    images must $e

    registered5

    I Sb i

  • 8/11/2019 Lec5 Image Enhancement

    57/104

    Image Subtraction

    Useful for change detection.

    I Sbt ti ( td)

  • 8/11/2019 Lec5 Image Enhancement

    58/104

    Image Subtraction (contd)

    edical a!!lication)

    iodine medium in%ected

    into t"e $loodstream

    di((erence en"anced

    Image

  • 8/11/2019 Lec5 Image Enhancement

    59/104

    gMultiplication/Division

    Suppose a sensor introduces some shading in the form:g(x,y)=f(x,y) h(x,y)

    We can estimate h(x,y) and remove shading by division.

    original s"ade !attern s"ade correction

    C ti !!!

  • 8/11/2019 Lec5 Image Enhancement

    60/104

    Caution !!!

    Arithmetic operation can produce pixel values outside of the

    range [0 255].

    You should convert values back to the range [0 255] to ensure

    that the image is displayed properly.

    How would you do the following mapping?

    [fmin fmax][ 0 255]

    PowerLaw()Transformations

  • 8/11/2019 Lec5 Image Enhancement

    61/104

    Power Law ( ) Transformations

    PowerLaw()Transformations

  • 8/11/2019 Lec5 Image Enhancement

    62/104

    Power Law ( ) Transformations

    Image Histograms

  • 8/11/2019 Lec5 Image Enhancement

    63/104

    ge stog s

    An image histogram is a plot of the grayle!el fre*+encies (i%e%, the n+mer of

    pixelsinthe image that ha!e that gray le!el)%

    Image Histograms (Cont.)

  • 8/11/2019 Lec5 Image Enhancement

    64/104

    g g ( )

    Divide frequencies by total number of pixels to represent as

    probabilities.

    Nnp kk /=

    Image Histograms

  • 8/11/2019 Lec5 Image Enhancement

    65/104

    g g Records the distribution of different pixel values e.g.

    Given a greyscale image, its histogram consists of a graph

    indicating the number of times each grey level occurs in

    the image.

    >> pep=imread('pout.tif'); figure(1) ,imhist(pep),axis tight;

    Image Histograms

  • 8/11/2019 Lec5 Image Enhancement

    66/104

    g g

    We can infer a lot about image appearance from its

    histogram.

    In adark image, the gray levels (and hence the histogram)

    would be clustered at the lower end.

    In auniformly bright image, the gray levels would beclustered at the upper end.

    In awell contrastedimage, the gray levels would be well

    spread out over much of the range:

    Image Histograms

  • 8/11/2019 Lec5 Image Enhancement

    67/104

    g g

    Image Histograms

  • 8/11/2019 Lec5 Image Enhancement

    68/104

    g g

    Given a poorly contrasted or a dark image we would

    like to improve its contrast or lighten it. We can do

    this by

    1.Histogram (Contrast) Stretching (Requires ManualInput)

    2.Histogram Equalization. (Automatic)

    1. Histogram Stretching

  • 8/11/2019 Lec5 Image Enhancement

    69/104

    g g

    1. Histogram Stretching

  • 8/11/2019 Lec5 Image Enhancement

    70/104

    g g

    2. Histogram Equalization

  • 8/11/2019 Lec5 Image Enhancement

    71/104

    We know that in a well contrasted image, the gray levels

    would bewell spread out over much of the range.

    In other words each gray level value (shade) from [0,

    255] will have equal occurrence probability in animage.

    Goal: The goal of histogram equalization is to apply a

    transformation function T(r) on the input image such that

    each gray level has equal occurrence probability.

    2. Histogram Equalization

  • 8/11/2019 Lec5 Image Enhancement

    72/104

    We know that in a well contrasted image, the gray levels

    would bewell spread out over much of the range.

    In other words each gray level value (shade) from [0,

    255] will have equal occurrence probability in animage.

    Goal: The goal of histogram equalization is to apply a

    transformation function T(r) on the input image such that

    each gray level has equal occurrence probability.

  • 8/11/2019 Lec5 Image Enhancement

    73/104

    2. Histogram Equalization

  • 8/11/2019 Lec5 Image Enhancement

    74/104

    The transformation function needs to satisfy two conditions.

    1.It must be a monotonic function.

    2.It must be within the following range

  • 8/11/2019 Lec5 Image Enhancement

    75/104

    2. Histogram Equalization

  • 8/11/2019 Lec5 Image Enhancement

    76/104

    In discrete case it is very simply, we simply map each

    gray level to its corresponding CDF value i.e.

    A gray level k will be mapped to sum of

    probabilities upto level k.

    where (L-1) is the total number of gray levelsand is the scaling factor used to map pixels

    back in the range [0, L-1].

    2. Histogram Equalization

  • 8/11/2019 Lec5 Image Enhancement

    77/104

    Example

    2. Histogram Equalization

  • 8/11/2019 Lec5 Image Enhancement

    78/104

    Example

    2. Histogram Equalization

  • 8/11/2019 Lec5 Image Enhancement

    79/104

    Example

    2. Histogram Equalization

  • 8/11/2019 Lec5 Image Enhancement

    80/104

    2. Histogram Equalization

  • 8/11/2019 Lec5 Image Enhancement

    81/104

    2. Histogram Equalization

  • 8/11/2019 Lec5 Image Enhancement

    82/104

    Histogram Matching

  • 8/11/2019 Lec5 Image Enhancement

    83/104

    Goal: The goal is to apply a transformation function T(r)

    on the input image such that its graylevels have

    distribution similar to the pre-specified one.

    !*6.

    6L+23

    Histogram Matching

  • 8/11/2019 Lec5 Image Enhancement

    84/104

    !*6.

    6L+23

    Step I Step II

    Step III

    Algorithm: Histogram Matching

  • 8/11/2019 Lec5 Image Enhancement

    85/104

    *+

    1.Equalize the input image to obtain equalized histograms=T(r).

    2.Find the transformation G(z) for the pre-specified histogram,

    and built alookuptable for mapping z G(z).3.For each value of s, find its closest G(z) value and respectively

    its corresponding z value.

    4.Finally map the s value to z.

    Histogram Matching:Example

  • 8/11/2019 Lec5 Image Enhancement

    86/104

    **

    Histogram Matching

  • 8/11/2019 Lec5 Image Enhancement

    87/104

    *,

  • 8/11/2019 Lec5 Image Enhancement

    88/104

    Histogram Matching

  • 8/11/2019 Lec5 Image Enhancement

    89/104

    ,1

  • 8/11/2019 Lec5 Image Enhancement

    90/104

    Histogram Matching

  • 8/11/2019 Lec5 Image Enhancement

    91/104

    ,)

    Histogram Matching

  • 8/11/2019 Lec5 Image Enhancement

    92/104

    ,-Note: Histogram matching is a trial and test method.

    Local Enhancement

  • 8/11/2019 Lec5 Image Enhancement

    93/104

    ,5

    Normally, transformation function based on thecontent of an entire image.

    Some cases it is necessary to enhance detailsover small areas (local neighbourhoods) in animage.

    The histogram processing techniques are easilyadaptable to local enhancement.

    Local Enhancement

  • 8/11/2019 Lec5 Image Enhancement

    94/104

    ,.

    Pi7el+to+!i7el translation 8ono-erla!!ing region

    Local Equalization

  • 8/11/2019 Lec5 Image Enhancement

    95/104

    ,+

    Local Equalization

  • 8/11/2019 Lec5 Image Enhancement

    96/104

    ,*

    Bit-plane slicing

  • 8/11/2019 Lec5 Image Enhancement

    97/104

    ,,

    Instead of highlighting gray-level ranges,highlighting the contribution made to totalimage appearance by specific bits might bedesired.

    Suppose that each pixel in an image isrepresented by 8 bits. Imagine that the image iscomposed of eight 1-bit planes, ranging from

    bit-plane 0, the least significant bit to bit-plane

    7, the most significant bit.

    2

    2

    9it+!lane 3*least signi(icant.

  • 8/11/2019 Lec5 Image Enhancement

    98/104

    100

    23223322

    2

    3

    3

    2

    23

    2

    9it+!lane

    *most signi(icant.

  • 8/11/2019 Lec5 Image Enhancement

    99/104

    Bit-plane Slicing

  • 8/11/2019 Lec5 Image Enhancement

    100/104

    102

  • 8/11/2019 Lec5 Image Enhancement

    101/104

    Lookup Tables Point operations can be done very efficiently using

  • 8/11/2019 Lec5 Image Enhancement

    102/104

    p y y g

    Lookup (LUT) tables.

    1.We pre-calculate the transformation function T(r)

    (mapping) value for each gray-scale value and

    store that in a table.

    2.We map each pixel value to its corresponding

    mapped value via a single look-up.

    Example: consider the division by 2 operations,

    the lookup table will look like.

  • 8/11/2019 Lec5 Image Enhancement

    103/104

    Spatial Domain Image Enhancement

  • 8/11/2019 Lec5 Image Enhancement

    104/104

    These methods can be categorized into two classes:

    1. Neighbourhood processing: To modify or change a pixel

    value we only need to know its local neighbour gray values.

    2. Point processing: works independently on each pixel i.echanges its value without knowledge of its surroundings.

Recommended