Lecture 2 - Image Histograms

  • Upload
    hardnut

  • View
    230

  • Download
    0

Embed Size (px)

Citation preview

  • 7/28/2019 Lecture 2 - Image Histograms

    1/17

    Image histograms

    Week 2

  • 7/28/2019 Lecture 2 - Image Histograms

    2/17

    Histogram

    A histogram is simply a graph that samples a population and

    shows a count of each characteristic of interest.

    In an image processing context, this histogram is a graphshowing the number of pixels in an image at each differentintensity value found in that image.

    For an 8-bit grayscale image there are 256 different possibleintensities.

    Color histograms are three separate histograms, one each forthe Red, Green and Blue channels.

  • 7/28/2019 Lecture 2 - Image Histograms

    3/17

    HISTOGRAMS: Thresholding

    Histograms information can be used to decide what value of

    threshold to use when converting a grayscale image to a

    binary one by thresholding.

    If the image is suitable for thresholding then the histogram

    will be bi-modal--- i.e. the pixel intensities will be clustered

    around two well-separated values.

    A suitable threshold for separating these two groups will be

    found somewhere in between the two peaks in the histogram.

    If the distribution is not like this then it is unlikely that a goodsegmentation can be produced by thresholding.

  • 7/28/2019 Lecture 2 - Image Histograms

    4/17

    Intensity histogram for the input image

    One peak represents the object pixels, one

    represents the background.

  • 7/28/2019 Lecture 2 - Image Histograms

    5/17

    Thresholding

    It is clear that a threshold value of around 120

    should segment the picture nicely,

  • 7/28/2019 Lecture 2 - Image Histograms

    6/17

    Thresholding (Continue)

    using thresholds of 80 using thresholds of 120

  • 7/28/2019 Lecture 2 - Image Histograms

    7/17

    Contrast stretching Vs Histogram equalization

    The histogram is used and altered by many imageenhancement operators.

    Two operators which are closely connected to the

    histogram are contrast stretching and histogramequalization. They are based on the assumptionthat an image has to use the full intensity rangeto display the maximum contrast.

    Contrast stretching takes an image in which theintensity values don't span the full intensity rangeand stretches its values linearly.

  • 7/28/2019 Lecture 2 - Image Histograms

    8/17

    Contrast stretching

    Contrast stretching (often called normalization) is a simpleimage enhancement technique that attempts to improve the

    contrast in an image by `stretching' the range of intensity

    values it contains to span a desired range of values, e.g. the

    the full range of pixel values that the image type concerned

    allows.

    For 8-bit gray level images the lower and upper limits might be 0 and 255.

    Call the lower and the upper limits a and b respectively.

    The simplest sort of normalization then scans the image to find the lowest and

    highest pixel values currently present in the image. Call these cand d.

    Then each pixel P is scaled using the following function:

  • 7/28/2019 Lecture 2 - Image Histograms

    9/17

    Contrast stretching

    each pixel P is scaled using the following function:

    Scaling_factor : 255 / (High Low)

    Image(i, j) = [ image(i, j) Low ] x Scaling_factor

    Low and High are the lowest and highest intensity in the image.

  • 7/28/2019 Lecture 2 - Image Histograms

    10/17

    Contrast stretching

    the intensity histogram forms a tight, narrow cluster between the gray level intensity

    values of 79 - 136, as shown in

    After contrast stretching, using a simple linear interpolation between

    c = 79 and d = 136, we obtain

  • 7/28/2019 Lecture 2 - Image Histograms

    11/17

    Contrast stretching

    most of the pixels have rather high intensity values Contrast stretching, clearly improved contrast

  • 7/28/2019 Lecture 2 - Image Histograms

    12/17

    Contrast stretching

    clc

    clear all

    a =imread('sample.bmp');

    a=rgb2gray(a);

    figure(1);

    imshow(a);

    [m n]=size(a);

    r2=max(max(a)) %this function is used for finding the max value of a pixel in an image

    r1=min(min(a)) %this function is used for finding the min value of a pixel in an image

    s1=0; % this is the min and max of an image i.e. 0-255 gray levels

    s2=255;

    for i=1:m %here we use 2 for loops for traversing the image in x & y coordinate

    for j=1:n

    s(i,j) = (a(i,j)-r1)* (255/(r2 - r1));

    end end

    figure(2);

    imshow(s);

  • 7/28/2019 Lecture 2 - Image Histograms

    13/17

    Histogram equalization The idea of histogram equalization is that the pixels should be

    distributed evenly over the whole intensity range, i.e. the aim isto transform the image so that the output image has aflat

    histogram.

  • 7/28/2019 Lecture 2 - Image Histograms

    14/17

    Histogram equalization

    The 8-bit greyscale image shown has the following values:

    Pixel values that have a zero count are excluded for the sake of brevity.

  • 7/28/2019 Lecture 2 - Image Histograms

    15/17

    Histogram equalization

    the minimum value in the subimage is 52 and the maximum value is 154. The cdf of

    64 for value 154 coincides with the number of pixels in the image. The cdf must benormalized to [0, 255] . The general histogram equalization formula is:

    Where cdfmin is the minimum value of the cumulative distribution function (in this case 1),M N gives the image's number of pixels (for the example above 64, where M is width and

    N the height) and L is the number of grey levels used (in most cases, like this one, 256).

    The equalization formula for this particular example is:

    For example, the cdf of 78 is 46. (The value of 78 is used in the bottom row of the 7th column.)

    The normalized value becomes

  • 7/28/2019 Lecture 2 - Image Histograms

    16/17

    Histogram equalization

    Notice that the minimum value (52) is now 0 and the maximum value (154) is now 255

  • 7/28/2019 Lecture 2 - Image Histograms

    17/17

    Histogram equalization