Image Final Print

download Image Final Print

of 38

Transcript of Image Final Print

  • 8/2/2019 Image Final Print

    1/38

    INDEX

    Sr.No. Name of Experiment Date of

    Starting

    Date of

    Completion

    Signature

    1 Introduction of MATLAB ( Basic

    Commands)

    2 To see the effect of change in

    spatial resolution of Image

    (Resizing , Zooming, Rotation,

    Color map, Cropping)

    3 Effect of Brightness Operation onan Image

    4 Effect of adding and removing

    noise in an Image ( Salt & Pepper

    and Gaussian Noise ,Median and

    Wiener Filters)

    5 To prepare the Histogram of

    different Images, Changes in Gray

    level, Histogram Equalization

    6 To pass the Image through Lowpass and High Pass Filters and to

    see it s effect

    7 To pass the Image through Band

    pass and Band Reject Filters and to

    see it s effect

    8 To apply Edge, Pixel Detection

    operation on Images

    9 To see the Magnitude and Phase

    information of an Image using FFTand IFFT

    10 Mini Project Based on the

    knowledge of MATLAB in Image

    Processing

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

    INDEX

    FUNDAMENTALS OF IMAGE PROCESSING

  • 8/2/2019 Image Final Print

    2/38

    Experiment 1

    AIM: - Introduction of MATLAB (Basic Commands)

    MATLAB COMMANDS

    a= [1 2 3; 4 5 6; 7 8 9]

    a=

    1 2 3

    4 5 6

    7 8 9

    This forms 3 X 3 matrix labeled as a

    b=a

    b=

    1 4 7

    2 5 8

    3 6 9

    The transpose of matrix a is stored in matrix b

    c=b*a

    c=

    66 78 90

    78 93 108

    90 108 126

    Multiplies matrix b with a stores in c

    c = a*b

    c=

    14 32 50

    32 77 122

    50 122 194Multiplies matrix a with b stores in c

    a= [ 1 2 3 4 5]

    a = 1 2 3 4 5

    One dimensional array is defined as a

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    3/38

    b = a+3

    b =

    4 5 6 7 8

    3 is added to each element of a

    c = a+b

    c =

    5 7 9 11 13

    Both arrays a and b are added and stored in c

    eye(3)

    ans =

    1 0 0

    0 1 00 0 1

    Identical matrix formed

    eye(5)

    ans =

    1 0 0 0 0

    0 1 0 0 0

    0 0 1 0 0

    0 0 0 1 0

    0 0 0 0 1

    5 X 5 identical matrix formed

    zeros(3,4)

    ans =

    0 0 0 0

    0 0 0 0

    0 0 0 0

    3 x 4 matrix with all elements 0

    ones(3,4)

    ans =

    1 1 1 1

    1 1 1 1

    1 1 1 1

    3 x 4 matrix with all elements 1

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    4/38

    [eye(2);zeros(2)]

    ans =

    1 0

    0 1

    0 00 0

    Identical matrix is appended with the 2 X 2 zero matrix

    [eye(2),zeros(2)]

    ans =

    1 0 0 0

    0 1 0 0

    Identical matrix is appended with the 2 X 2 zero matrix and 2 X 4 matrix is

    formed

    a = [ 1 2 3;4 5 6;7 8 9]

    a =

    1 2 3

    4 5 6

    7 8 9

    3 X 3 matrix is formed as a

    a (2,1)a = 4

    This gives the value of 2nd row and 1st element

    a(1,2)

    a = 2

    This gives the value of 1st row and 2nd element

    c = [ a; 10 11 12]

    c =1 2 3

    4 5 6

    7 8 9

    10 11 12

    It appends a row in the matrix a

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    5/38

    [a; a; a]

    ans =

    1 2 3

    4 5 6

    7 8 91 2 3

    4 5 6

    7 8 9

    1 2 3

    4 5 6

    7 8 9

    This appends a to itself one after another and forms 9X3 matrix

    [ a,a; a,a]ans =

    1 2 3 1 2 3

    4 5 6 4 5 6

    7 8 9 7 8 9

    1 2 3 1 2 3

    4 5 6 4 5 6

    7 8 9 7 8 9

    This appends matrix a on the both directions and forms 6 X 6 matrix

    f = [ -0.5, 0.1, 0.5]

    f =

    -0.5000 0.1000 0.5000

    It defines a row matrix with non integer elements

    round(f)

    ans =

    -1 0 1

    It assigns the nearest integer value

    f = [ -0.4,0.1,0.5]

    f =

    -0.4000 0.1000 0.5000

    It defines a row matrix with non integer elements

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    6/38

    round(f)

    f =

    0 0 1

    It assigns the nearest integer value

    ceil (f)

    ans =

    0 1 1

    It assigns the highest integer value

    sum(f)

    ans =

    0.2000

    Sum of all elements stored in matrix

    fix(f)

    ans =

    0 0 0

    The integer value is stored and the decimal value discarded

    floor(f)

    ans =

    -1 0 0It stores the lower nearest integer value

    [ 1,2,3,4].*[1,2,3,4]

    ans =

    1 4 9 16

    It directly multiplies each elements of 1st matrix with 2nd matrix

    [1,2,3,4] + [ 1,2,3,4]

    ans =2 4 6 8

    It directly adds each elements of 1st matrix with 2nd matrix

    [1,2,3,4].^3

    ans =

    1 8 27 64

    It makes cube of each elements of row matrix

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    7/38

    [1,2,3,4]*3

    ans =

    3 6 9 12

    It multiplies each elements of row matrix with 3.

    pi

    ans =

    3.1416

    The value of p is displayed

    eps

    ans =

    2.2204 e-016

    The value of e is displayed

    who

    Your variables are:

    a b e g

    ans c f x

    Displays all variables used

    clear x

    Your variables are:a b e g

    ans c f

    Clears the variable x

    Clear all

    Clears all the variables

    x = -2: 1

    x =-2 -1 0 1

    It forms series of integer from 2 to 1 with unit diff.

    length(x)

    ans = 4

    It gives the length of the series

    t= 0:2:10

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    8/38

    t =

    0 2 4 6 8 10

    It gives series from 0 to 10 with difference of 2.

    a =magic(3)a =

    8 1 6

    3 5 7

    4 9 2

    Forms 3X3 matrix with each raw and column having same sum

    a (2,:)

    ans =

    3 5 7It displays 2nd raw with all elements

    a(:,3)

    ans =

    6

    7

    2

    It displays 2nd column with all elements

    a(2:3:,:)

    ans =

    3 5 7

    4 9 2

    It displays 2nd to 3rd raw with all elements

    b = rand(5)

    ans =

    0.9501 0.7621 0.6154 0.4057 0.0579

    0.2311 0.4565 0.7919 0.9355 0.3529

    0.6068 0.0185 0.9218 0.9169 0.8132

    0.4860 0.8214 0.7382 0.4103 0.0099

    0.8913 0.4447 0.1763 0.8963 0.1389

    Generates a random 5X5 matrix

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    9/38

    c = 100 * rand(3)

    c =

    20.2765 27.2188 74.6786

    19.8722 19.8814 44.509660.3792 1.5274 93.1815

    It multiplies each elements of random matrix with 100.

    [eye(2);zeros(2);zeros(2)]

    ans =

    0 0

    0 1

    0 0

    0 00 0

    0 0

    [eye(2);ones(2)]

    ans =

    1 0

    0 1

    1 1

    1 1

    [eye(2);ones(2);zeros(2)]

    ans=

    1 0

    0 1

    1 1

    1 1

    0 0

    0 0

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    10/38

    Experiment 2

    AIM:- To see the effect of change in spatial resolution of

    Image ( Resizing , Zooming, Rotation, Color map,Cropping, Movie)

    Code

    Clc;

    Clear all;

    Close all

    Subplot (3,2,1);

    a=Imread (('moon.tif')

    Imshow (a);

    Title ('Original Moon');

    Subplot (3,2,2);

    b=Imresize (a,[40 40]) % co ordinates are for y and x respectively

    Imshow (b);

    Title ('Moon represented using 40 x 40 Pixels');

    Subplot (3,2,3);

    c=imrotate (a,90);

    Imshow (c);Title ('Moon Rotated by 90 degrees in ACW Direction');

    Subplot (3,2,4);

    e=imcrop (a,[10 10 240 230]);

    Imshow (e);

    Title ('Cropped Moon');

    Subplot (3,2,5);

    imcontour (a,4);Title ('Contours of Moon');

    Subplot (3,2,6);

    load mri;

    immovie (D,map);

    Title ('A 27 frame MRI Image');

    figure;

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    11/38

    a=Imread (('moon.tif');

    image(a);

    Title ('Color mapped Moon');

    Color map(jet); % Different color mapping can be used viz Fire, cool etc

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    12/38

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    13/38

    MATLAB Functions UsedImread :Syntax

    A = Imread ((filename, fmt)

    [X, map] = Imread ((filename, fmt)Description

    A = Imread ((filename, fmt) reads a grayscale or color image from the file

    specified by the string filename, where the string fmt specifies the format of the

    file. Imread (returns the image data in the array.

    Class Support

    For most file formats, Imread (uses 8 or fewer bits per color plane to store

    pixels.

    Imshow:Syntax

    Imshow (I, n)

    Imshow (I, [low high])

    Description

    Imshow (I,n) displays the intensity image I with n discrete levels of gray. And

    by omitting n, Imshow uses 256 gray levels on 24-bit displays, or 64 gray levels

    on other systems.

    Imshow (I,[low high]) displays I as a grayscale intensity image, specifying the

    data range for I. The value low (and any value less than low) displays as black;the value high (and any value greater than high) displays as white.

    Class Support

    The input image can be of class logical, uint8, uint16, or double, and it must be

    non sparse.

    Imresize:

    Syntax

    B = imresize (A, m)

    B = imresize (A, m, method)Description

    B = imresize (A, m) returns an image B that is m times the size of A, using

    nearest-neighbor interpolation. A can be an indexed image, grayscale image,

    RGB, or binary image.

    B = imresize (A, m, method) returns an image that is m times the size of A

    using the interpolation method specified by method. Method is a string that can

    have one of values viz. Nearest-neighbor interpolation, bilinear interpolation,

    Bicubic interpolation.

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    14/38

    Class Support

    The input image A can be numeric or logical and it must be non sparse. The

    output image B is of the same class as the input image.

    Imrotate:Syntax

    B = imrotate (A, angle)

    B = imrotate (A, angle, method)

    Description

    B = imrotate (A, angle) rotates the image A by angle degrees in a

    counterclockwise direction, using the nearest-neighbor interpolation. To rotate

    the image clockwise, specify a negative angle.

    B = imrotate (A, angle, method) rotates the image A by angle degrees in acounterclockwise direction, using the interpolation method specified by method.

    method is a string that can have one of theseClass Support

    The input image A can be numeric or logical and it must be no sparse. The

    output image B is of the same class as the input image.

    imcrop:Syntax

    I2 = imcrop (I)X2 = imcrop(X, map)

    Description

    imcrop crops an image to a specified rectangle. In the syntaxes below, imcrop

    displays the input image and waits for you to specify the crop rectangle with the

    mouse.

    Class Support

    The input image A can be of class logical, uint8, uint16, or double. The output

    image B is of the same class as A. rect is always of class double.

    Color map:Syntax

    Color map (map)

    Cmap = color map

    Description

    A color map is an m-by-3 matrix of real numbers between 0.0 and 1.0. Each

    row is an RGB vector that defines one color. The kth row of the color map

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    15/38

    defines the kth color, where map(k,:) = [r(k) g(k) b(k)]) specifies the intensity of

    red, green, and blue.

    Specifying Color maps

    There are total eleven types which specifies color like autumn, hsv, pink, prism,

    summer and winter and some more. All these classification specifies its owndifferent intensity of color.

    Immovie:Syntax

    Mov = immovie(X,map)

    Mov = immovie(RGB)

    Description

    Mov = immovie(X,map) returns the movie structure array mov from the images

    in the multiframe indexed image X with the color map. As it creates the moviearray, it displays the movie frames on the screen.Class Support

    A true-color image can be uint8, uint16, or double. Mov is a MATLAB movie

    structure.

    Imcontour:Syntax

    Imcontour (I)

    Imcontour (I,n)Description

    Imcontour (I) draws a contour plot of the intensity image I, automatically

    setting up the axes so their orientation and aspect ratio match the image.

    Imcontour (I, n) draws a contour plot of the intensity image I, automatically

    setting up the axes so their orientation and aspect ratio match the image. n is the

    number of equally spaced contour levels in plot.

    Class Support

    The input image can be of class uint8, uint16, double, or logical.

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    16/38

    Experiment 3

    AIM: - Effect of Brightening Operation on an Image

    Code

    Clc;

    Clear all;

    Close all;

    a=Imread (('moon.tif');

    Imshow (a);

    Title ('Moon with Command Imshow ()');

    Imview (a);

    b=.5;

    brighten(b)Title ('Moon with Brightness by argument 0.5');

    b=-.5;

    figure;

    Imshow (a)

    brighten (b)

    Title ('Moon with Darkness by argument 0.5');

    whos

    imfinfo(moon.tif);

    Command Window

    Name Size Bytes Class

    a 537x358 192246 uint8 array

    b 1x1 8 double array

    Grand total is 192247 elements using 192254 bytes

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    17/38

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    18/38

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    19/38

    MATLAB Functions UsedBrighten :Syntax

    brighten (beta)

    brighten (h, beta)Description

    Brighten increases or decreases the color intensities in a Color map. The

    modified Color map is brighter if 0 < beta < 1 and darker if -1 < beta < 0.

    Brighten (beta) replaces the current Color map with a brighter or darker Color

    map of essentially the same colors. Brighten (beta), followed by brighten (-

    beta), where beta < 1, restores the original map.

    Brighten (h, beta) brightens all objects that are children of the figure having the

    handle h.

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    20/38

    Experiment 4

    AIM :- Effect of adding and removing noise in an Image

    ( Salt & Pepper and Gaussian Noise ,Median and WienerFilters)

    Code

    Clc;

    Clear all;

    Close all;

    a=Imread (('eight.tif');

    Subplot (3,2,1);

    Imshow (a);

    Title ('Original Image');

    Subplot (3,2,2);

    b1=Imnoise (a,'salt & pepper');

    Imshow (b1);

    Title ('Image with Salt and Pepper Noise');

    Subplot (3,2,3);

    b2=Imnoise (a,'gaussian');

    Imshow (b2);Title ('Image with Gaussian Noise');

    Subplot (3,2,4);

    c1=medfilt2(b1);

    Imshow (c1);

    Title ('Image passed through Median Filter');

    Subplot (3,2,5);

    c2=wiener2(b2);Imshow (c2);

    Title ('Image passed through Wiener Filter');

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    21/38

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    22/38

    MATLAB Functions UsedImnoise:Syntax

    j = Imnoise (I,type)

    J = Imnoise (I,type,parameters)Description

    j = Imnoise (I,type) adds noise of a given type to the intensity image I. Type is a

    string that can have one of these values.

    J = Imnoise (I,type,parameters) accepts an algorithm type plus additional

    modifying parameters particular to the type of algorithm chosen. If you omit

    these arguments, Imnoise uses default values for the parameters.

    Values Description

    'gaussian' Gaussian white noise

    'localvar' Zero-mean Gaussian white noise with an intensity-dependent variance

    'poisson' Poisson noise

    'salt & pepper' On and off pixels

    'speckle' Multiplicative noise

    Class Support

    I can be of class uint8, uint16, or double. The output image J is of the same

    class as I. If I has more than two dimensions it is treated as a multidimensional

    intensity image and not as an RGB image.

    Median Filter:Syntax

    B = medfilt2(A,[m n])

    B = medfilt2(A)

    Description

    Median filtering is a nonlinear operation often used in image processing to

    reduce "salt and pepper" noise. Median filtering is more effective than

    convolution when the goal is to simultaneously reduce noise and preserve

    edges.B = medfilt2(A,[m n]) performs median filtering of the matrix A in two

    dimensions. Each output pixel contains the median value in the m-by-n

    neighborhood around the corresponding pixel in the input image. medfilt2 pads

    the image with 0's on the edges, so the median values for the points within [m

    n]/2 of the edges might appear distorted.

    B = medfilt2(A) performs median filtering of the matrix A using the default 3-

    by-3 neighborhood.

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    23/38

    Class Support

    The input image A can be of class logical, uint8, uint16, or double (unless the

    'indexed' syntax is used, in which case A cannot be of class uint16). The output

    image B is of the same class as A.

    Wiener Filter:Syntax

    J = wiener2(I,[m n],noise)

    [J,noise] = wiener2(I,[m n])

    Description

    wiener2 lowpass-filters an intensity image that has been degraded by constant

    power additive noise. wiener2 uses a pixelwise adaptive Wiener method based

    on statistics estimated from a local neighborhood of each pixel.

    Class SupportThe input image I is a two-dimensional image of class uint8, uint16, or double.

    The output image J is of the same size and class as I.

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    24/38

    Experiment 5

    To prepare the Histogram of different Images, Changes in

    Gray level, Histogram Equalization

    Code

    Clc;

    Clear all;

    Close all;

    a=Imread (('cameraman.tif');

    Subplot (2,2,1);

    Imshow (a);Title ('Original Image');

    Subplot (2,2,2);

    Imhist (a);

    Title ('Histogram of Original Image');

    c=Histeq (a);

    Subplot (2,2,3);

    Imshow (c);

    Title ('Equalized Image');

    Subplot (2,2,4);

    Imhist (c);

    Title ('Histogram of Equalized Image');

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    25/38

    MATLAB Functions UsedImhist:Syntax

    Imhist (I, n)

    Imhist (X, map)Description

    Imhist (I) displays a histogram for the intensity image I above a grayscale color

    bar. The number of bins in the histogram is specified by the image type. If I is a

    grayscale image, Imhist uses a default value of 256 bins. If I is a binary image,

    Imhist uses 2 bins.

    Class Support

    The input image can be of class logical, uint8, uint16, or double.

    Histeq:Syntax

    J = histeq (I,hgram)

    J = histeq (I,n)

    Description

    Histeq enhances the contrast of images by transforming the values in an

    intensity image, or the values in the color map of an indexed image, so that the

    histogram of the output image approximately matches a specified histogram.

    Class SupportFor syntaxes that include an intensity image I as input, I can be of class uint8,

    uint16, or double, and the output image J has the same class as I.

    uint8:Syntax

    uint8 (a)Description

    uint8 (a) returns the stored integer value of fi object a as a built-in uint8. If the

    stored integer word length is too big for a uint8, or if the stored integer issigned, the returned value saturates to a uint8.

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    26/38

    Experiment 6

    Aim:- To pass the Image through Low pass and High Pass

    Filters and to see it s effect.

    Code

    Clc;

    Clear all;

    Close all;

    a = Imread ((G:\Pooja\Wallpapers\CARTOONS\10.jpg');

    Subplot (2,2,1)

    Imshow (a);

    Title ('Original Image');

    [X,map] = rgb2ind(a,209); %Keep it below 256 otherwise blackout

    %For Values between 0-25 approx also blackout

    Subplot (2,2,2);

    Imshow (X)

    Title ('Indexed Image');

    hl=(1/500)*ones(4,4);

    hh=[-2 -2 -2 ; -2 -20 -2; -2 -2 -2];cl=filter2(hl,X,'valid');

    Subplot (2,2,3);

    Imshow (cl);

    Title ('Image passed through LPF');

    ch=filter2(hh,X,'valid');

    Subplot (2,2,4);

    Imshow (ch);

    Title ('Image passed through HPF');

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    27/38

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    28/38

    MATLAB Functions Usedrgb2ind:

    Syntax

    X = rgb2ind(RGB, map)

    Description

    rgb2ind converts RGB images to indexed images using one of three different

    methods: uniform quantization, minimum variance quantization, and Color map

    mapping. For all these methods, rgb2ind also dithers the image unless you

    specify 'no dither' for dither option.

    filter2:

    Syntax

    Y = filter2(h, X)

    Description

    Filters the data in X with the two-dimensional FIR filter in the matrix h. It

    computes the result, Y, using two-dimensional correlation, and returns the

    central part of the correlation that is the same size as X.

    Y = filter2(h, X, shape) returns the part of Y specified by the shape parameter.

    shape is a string with one of these values:

    'full' Returns the full two-dimensional correlation. In this case, Y is larger than

    X.

    'same'(default) Returns the central part of the correlation. In this case, Y is the

    same size as X.

    'valid Returns only those parts of the correlation that are computed without

    zero-padded edges. In this case, Y is smaller than X.

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    29/38

    Experiment 7

    AIM:- To pass the Image through Band pass and Band

    Reject Filters and to see it s effect.

    Clc;

    Clear all ;

    Close all ;

    a = Imread (( 'G:\Pooja\Wallpapers\collection\abstract5.jpg' );

    Subplot (3,2,1)

    Imshow (a) ;

    Title ( 'Original Image' ) ;[X,map] = rgb2ind(a,209) ; %Keep it below 256 otherwise blackout

    %For Values between 0-25 approx also blackout

    Subplot (3,2,2) ;

    Imshow (X)

    Title ( ' Indexed Image' ) ;

    hl=(1/500)*ones(4,4) ;

    hh=[ -2 -2 -2 ; -2 30 -2; -2 -2 -2];

    cl=f ilter2(hl ,X, 'valid' ) ;

    Subplot (3,2,3) ;

    Imshow (cl ) ;

    Title ( ' Image passed through LPF' ) ;

    ch=f ilter2(hh,X, 'valid' ) ;

    Subplot (3,2,4) ;

    Imshow (ch) ;

    Title ( ' Image passed through HPF' ) ;

    Subplot (3,2,6) ;

    bp=f ilter2(hl ,ch, 'valid' ) ;

    Imshow (bp) ;

    Title ( ' Image passed through BRF' ) ;

    Subplot (3,2,5) ;

    b1 = bp;

    b2=0*b1;

    br=b2-b1;

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    30/38

    Imshow (br ) ;

    Title ( ' Image passed through BPF' ) ;

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    31/38

    Experiment 8

    AIM:- To apply Edge, Pixel Detection operation on

    Images.

    Code for Edge Detection in an Image

    Clc;

    Clear all;

    Close all;

    a=Imread (('moon.tif');

    Subplot (4,2,1);

    Imshow (a);Title ('Original Moon');

    b=edge(a,'prewitt');

    Subplot (4,2,2);

    Imshow (b);

    Title ('Moon Edges with Prewitt');

    c=edge(a,'canny');

    Subplot (4,2,3);

    Imshow (c);

    Title ('Moon Edges with Canny');

    e=edge(a, 'Zero cross');

    Subplot (4,2,4);

    Imshow (e);

    Title ('Moon Edges with Zero cross');

    f=edge(a, 'Zero cross');

    Subplot (4,2,5);Imshow (f);

    Title ('Moon Edges with Zero cross');

    g=edge(a, 'sobel');

    Subplot (4,2,6);

    Imshow (g);

    Title ('Moon Edges with Sobel');

    h=edge(a, 'roberts');

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    32/38

    Subplot (4,2,7);

    Imshow (h);

    Title ('Moon Edges with Roberts');

    i=edge(a,'log');Subplot (4,2,8);

    Imshow (i);

    Title ('Moon Edges with Laplacian');

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    33/38

    MATLAB Functions Usededge:

    1)Sobel Method

    Syntax

    BW = edge(I, 'Sobel')

    Description

    The Sobel method finds edges using the Sobel approximation to the derivative.

    It returns edges at those points where the gradient of I is maximum.

    Class Support

    I can be of class uint8, uint16, or double. BW is of class logical

    2)Prewitt Method

    SyntaxBW = edge(I,'prewitt')

    Description

    The Prewitt method finds edges using the Prewitt approximation to the

    derivative. It returns edges at those points where the gradient of I is maximum.

    Class Support

    I can be of class uint8, uint16, or double. BW is of class logical.

    3)Roberts Method

    Syntax

    BW = edge(I,'roberts')

    Description

    The Roberts method finds edges using the Roberts approximation to the

    derivative. It returns edges at those points where the gradient of I is maximum.

    Class Support

    I can be of class uint8, uint16, or double. BW is of class logical.

    4)Laplacian of Gaussian MethodSyntax

    BW = edge(I, 'log')

    Description

    The Laplacian of Gaussian method finds edges by looking for zero crossings

    after filtering I with a Laplacian of Gaussian filter.

    Class Support

    I can be of class uint8, uint16, or double. BW is of class logical.

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    34/38

    5)Zero-Cross Method

    Syntax

    BW = edge(I, 'Zero cross', thresh, h)

    Description

    The zero-cross method finds edges by looking for zero crossings after filtering Iwith a filter you specify

    Class Support

    I can be of class uint8, uint16, or double. BW is of class logical.

    6) Canny Method

    Syntax

    BW = edge (I, 'canny')

    Description

    The Canny method finds edges by looking for local maxima of the gradient of I.The gradient is calculated using the derivative of a Gaussian filter. The method

    uses two thresholds, to detect strong and weak edges, and includes the weak

    edges in the output only if they are connected to strong edges. This method is

    therefore less likely than the others to be fooled by noise, and more likely to

    detect true weak edges.

    Class Support

    I can be of class uint8, uint16, or double. BW is of class logical

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    35/38

    Experiment 9

    AIM:- To see the Magnitude and Phase information of an

    Image using FFT and IFFFT.

    Clc;

    Clear all;

    Close all;

    a = Imread ((moon.tif);

    Subplot (3,2,1);

    Imshow (a);Title (Original Image);

    Subplot (3,2,2);

    Imhist (a);

    Title (Histogram of Original Image);

    b=fft2(a);

    Subplot (3,2,3);

    Imshow (b);

    Title (FFT of an Image);

    c =ifft2(b);

    d=uint8(c);

    Subplot (3,2,4);

    Imshow (c1);

    Title (IFFT of an Original Image);

    Subplot (3,2,5);

    Imhist (d);Title ('Histogram of Restored Image');

    e=Histeq (d);

    Subplot (3,2,6);

    Imshow (e);

    Title ('Equalized Image');

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    36/38

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    37/38

    MATLAB Functions UsedFFT2:

    Syntax

    Y = fft2(X)

    DescriptionY = fft2(X) returns the two-dimensional discrete Fourier transform (DFT) of X,

    computed with a fast Fourier transform (FFT) algorithm. The result Y is the

    same size as X.

    Class Support

    fft2 supports inputs of data types double and single. If you call fft2 with the

    syntax y = fft2(X, ...), the output y has the same data type as the input X.

    IFFT2:

    SyntaxY = ifft2(X)

    Description

    Y = ifft2(X) returns the two-dimensional inverse discrete Fourier transform

    (DFT) of X, computed with a fast Fourier transform (FFT) algorithm. The result

    Y is the same size as X.

    Class Support

    ifft2 supports inputs of data types double and single. If you call ifft2 with the

    syntax y = ifft2(X, ...), the output y has the same data type as the input X.

    __________________________________________________________________________________FUNDAMENTALS OF IMAGE PROCESSING

    (8th SEMESTER E.C.)R. K. College of Engineering & Technology, Rajkot

  • 8/2/2019 Image Final Print

    38/38

    MINI PROJECT

    AIM:-