Simple Matlab tutorial using matlab inbuilt commands
Upcoming SlideShare
Loading in...5
×
 

Simple Matlab tutorial using matlab inbuilt commands

on

  • 1,310 views

simple matlab tutorial with the following commands imread, ...

simple matlab tutorial with the following commands imread,
im2bw,
imfinfo,
imadjust,
graythresh,
imcrop,
imrotate,
imtranslate,
imcomplement,
imadd,
imsubtract,
imdivide,
imlincomb,
imnoise,
wiener,
medfilt2,
imfilter,
fspecial,
ordfilt2,
perwitt,
sobel,
canny.
and with outputs

Statistics

Views

Total Views
1,310
Views on SlideShare
1,309
Embed Views
1

Actions

Likes
1
Downloads
122
Comments
0

1 Embed 1

http://www.linkedin.com 1

Accessibility

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Simple Matlab tutorial using matlab inbuilt commands Simple Matlab tutorial using matlab inbuilt commands Document Transcript

  • To read an image into ‘a’ variable a=imread(C:Usersm12cs018Desktopr1.jpg) To obtain information about a graphics file and its contents: imfinfo('C:Usersm12cs018Desktopr1.jpg') Filename: 'C:Usersm12cs018Desktopr1.jpg' FileModDate: '13-Mar-2013 14:26:31' FileSize: 93228 Format: 'png' FormatVersion: [] Width: 194 Height: 279 BitDepth: 24 ColorType: 'truecolor' FormatSignature: [137 80 78 71 13 10 26 10] Colormap: [ ] Histogram: [ ] InterlaceType: 'none' Transparency: 'none' SimpleTransparencyData: [ ] BackgroundColor: [ ] RenderingIntent: 'perceptual' Chromaticities: [0.3127 0.3290 0.6400 0.3300 0.3000 0.6000 0.1500 0.0600] Gamma: 0.4545 XResolution: 3779 YResolution: 3779 ResolutionUnit: 'meter' XOffset: [ ] YOffset: [ ] OffsetUnit: [ ] SignificantBits: [ ]
  • Convert image to binary image, based on threshold BW = im2bw(I, level) converts the grayscale image I to a binary image. The output image BW replaces all pixels in the input image with luminance greater than level with the value 1 (white) and replaces all other pixels with the value 0 (black). >>b= im2bw(a,0.89) >> imshow(b); Convert an RGB image to a grayscale image >>c=rgb2gray(a) >> imshow(c); Display histogram of image data >> imhist(c)
  • Contrast enhancement imadjust Adjust image intensity values or colormap Syntax: J = imadjust(I) Creating the binary of an image using graythresh Thresholding can be performed by using the graythresh Global image threshold using Otsu's method Syntax level = graythresh(I) level = graythresh(I) computes a global threshold (level) that can be used to convert an intensity image to a binary image with im2bw. level is a normalized intensity value that lies in the range [0, 1]. I=rgb2gray(a) level = graythresh(I); BW = im2bw(I,level); imshow(BW)
  • histeq Enhance contrast using histogram equalization. a=imread('C:fp1.jpg') b=rgb2gray(a) imhist(b) 500 400 300 200 100 0 0 c=histeq(b) imhist(c) 50 100 150 200 250
  • 1000 900 800 700 600 500 400 300 200 100 0 0 50 100 150 200 250 Spatial Transformations To resize an image, use the imresize function. When you resize an image, you specify the image to be resized and the magnification factor. To enlarge an image, specify a magnification factor greater than 1. To reduce an image, specify a magnification factor between 0 and 1. For example, the command below reduces the size of an image by 0.75 times. >> I = rgb2gray(a); >> J = imresize(I,.75); >> imshow(I) >>imshow(J)
  • You can specify the size of the output image by passing a vector that contains the number of rows and columns in the output image. If the specified size does not produce the same aspect ratio as the input image, the output image will be distorted. This example creates an output image with 100 rows and 150 columns. >>J = imresize(I,[100 150]); To use bilinear >>Y = imresize(X,[100 150],'bilinear') Using the imcrop function imcrop is used to extract a rectangular portion of an image, You can specify the crop region interactively using the mouse >>J = imcrop(I); or You can specify the crop rectangle as a four-element position vector, [xmin ymin width height] i.e, [60 40 100 90] >>J = imcrop(I,[60 40 100 90]);
  • To rotate an image Use the imrotate function. We specify rotation angle, in degrees. If you specify a positive rotation angle, imrotate rotates the image counterclockwise; if you specify a negative rotation angle, imrotate rotates the image clockwise. To rotate the image 35° counterclockwise using bilinear interpolation >>J = imrotate(I,35,'bilinear'); >>imshow(J) imrotate uses nearest-neighbor interpolation by default to determine the value of pixels in the output image, but you can specify other interpolation methods. To perfrom Translation to (40,40) from origin >> xform = [ 1 0 0 0 1 0 40 40 1 ] xform = 1 0 0 0 1 0 40 40 1 >> tform_translate = maketform('affine',xform); >> k= imtransform(I, tform_translate); >>[cb_trans xdata ydata]= imtransform(I, tform_translate); >> cb_trans2 = imtransform(I, tform_translate,... 'XData', [1 (size(I,2)+ xform(3,1))],... 'YData', [1 (size(I,1)+ xform(3,2))]); >> imshow(cb_trans2) Image Arithmetic
  • Creating the negative of an image using imcomplement >>J=imcomplement(I) >> imshow(J) Imadd Add two images or add constant to image c=imresize(a,[300,300]) d=imresize(b,[300,300]) imshow(c) K=imadd(c,d) imshow(K) OUTPUT:
  • imsubtract Subtract one image from another or subtract constant from image K=imsubtract(c,d) imshow(K) imdivide Divides two images or divides image by constant K=imdivide(c,d) imshow(K) immultiply Multiply two images or multiply image by constant K=immultiply(c,d) imshow(K) imabsdiff absolute difference of two images K=immultiply(c,d) imshow(K) To display an image in the background and another image on foreground. >> b = imresize(a,[300 300]); >> d = imresize(c,[300 300]); >> e = imlincomb(.5,b,.5,d);
  • >> imshow(b) >> imshow(d) >> imshow(e) Removing Noise By Adaptive Filtering I = rgb2gray(a); >> imshow(I)
  • >> J = imnoise(I,'gaussian',0,0.025); >> imshow(I) >> imshow(J) Output after applying Gaussian noise. Remove the noise, using the wiener2 function. K = wiener2(J,[5 5]); imshow(K) Removing noise using Median filter K=medfilt2(J,[3 3]) imshow(K)
  • Removing noise using Gaussian filter 1. Add Salt and pepper noise J=imnoise(I,'salt & pepper',.02) imshow(J) 2. Creating Gaussian filter h = fspecial(type,parameters) creates a twodimensional filter h of the specified type. fspecial returns h as a correlation kernel, which is the appropriate form to use with imfilter. type is a string having one of these values. h=fspecial('gaussian',[3 3],.7) h= 0.0113 0.0838 0.0113 0.0838 0.6193 0.0838 0.0113 0.0838 0.0113 3. Filter noisy image with Gaussian filter L=imfilter(J,h) imshow(L) Removing noise using 2 dimensionl order-statistics filter L=ordfilt2(J,5,ones(3,3)) imshow(L)
  • Removing noise using Averaging filter 1.Create kernel for average filter with low pass characterisitics k=[ 1 1 1 111 1 1 1]/9 k= 0.1111 0.1111 0.1111 0.1111 0.1111 0.1111 0.1111 0.1111 0.1111 2. Plot frequency response characteristics freqz2(k) 3.Apply averaging filter Filter M=imfilter(J,k) imshow(M) Magnitude 1 0.5 0 1 0 Fy -1 -1 0 -0.5 Fx 0.5 1
  • Find the edges of an image using the Prewitt , Sobel and Canny methods. BW1 = edge(I,'prewitt'); BW2 = edge(I,'canny'); Imshow(BW2) BW2 = edge(I,'sobel'); Imshow(BW2)