Vous êtes sur la page 1sur 5

assignment

file:///C:/Documents%20and%20Settings/Administrator/My%20Documen...

Contents read video file read all video frames get the number of frames create a Matlab movie struct from the video frames creat a figure Adding salt and pepper noise to the extracted frames clc; clear all; close all; read video file obj = mmreader('C:\Documents and Settings\Administrator\Desktop\cookie.avi'); % .ogv for linux video files get(obj)

General Properties: Duration = 3.1333 Name = cookie.avi Path = C:\Documents and Settings\Administrator\Desktop Tag = Type = mmreader UserData = [] Video Properties: BitsPerPixel = 24 FrameRate = 15.0000 Height = 600 NumberOfFrames = 47 VideoFormat = RGB24 Width = 800

read all video frames vidFrames = read(obj); % vidFrame is a 4*4 matrix % it is a 2d array of 2d images get the number of frames numFrames = get(obj, 'numberofFrames'); create a Matlab movie struct from the video frames for k = 1: numFrames-1 mov(k).cdata = vidFrames(:,:,:,k); mov(k).colormap = []; % matrix mov contains each frame end creat a figure Fig1 = figure; montage(vidFrames); print -djpeg Fig1

% all frames % save the file

Warning: Image is too big to fit on screen; displaying at 8% Warning: You used the function print with a filename Fig1 that matches the name of a variable in your workspace. If you wanted to use the value of Fig1 instead of printing to the file Fig1, try calling print in the following form:

1 of 5

11/4/2013 4:30 PM

assignment

file:///C:/Documents%20and%20Settings/Administrator/My%20Documen...

print('-depsc',Fig1) For a more detailed example, see the doc for <a href="matlab:doc('print')">print</a> or <a href="matlab:helpview(fullfile(docroot,'techdoc','matlab_prog','matlab_prog.map'),'matlab_calling_syntax')" of commands and functions</a>

Adding salt and pepper noise to the extracted frames and removing it using median filter a = imread('Fig1.jpg'); % to read the file r = a(:,:,1); g = a(:,:,2); b = a(:,:,3); r = imnoise(r,'salt & pepper', 0.02); g = imnoise(g,'salt & pepper', 0.02); b = imnoise(b,'salt & pepper', 0.02); NoisyImage(:,:,1)=r; NoisyImage(:,:,2)=g; NoisyImage(:,:,3)=b; NoisyImage=uint8(NoisyImage); figure; imshow(a); title('image of extracted frames') figure; imshow(NoisyImage); title('After adding noise') r1=NoisyImage(:,:,1); g1=NoisyImage(:,:,2); b1=NoisyImage(:,:,3); r1=medfilt2(r1,[3 3]); g1=medfilt2(g1,[3 3]); b1=medfilt2(b1,[3 3]); FilteredImage(:,:,1)=r1; FilteredImage(:,:,2)=g1; FilteredImage(:,:,3)=b1;

2 of 5

11/4/2013 4:30 PM

assignment

file:///C:/Documents%20and%20Settings/Administrator/My%20Documen...

FilteredImage=uint8(FilteredImage); figure; imshow(FilteredImage); title('Filtered image using median filter')

Warning: Image is too big to fit on screen; displaying at 50% Warning: Image is too big to fit on screen; displaying at 50% Warning: Image is too big to fit on screen; displaying at 50%

3 of 5

11/4/2013 4:30 PM

assignment

file:///C:/Documents%20and%20Settings/Administrator/My%20Documen...

4 of 5

11/4/2013 4:30 PM

assignment

file:///C:/Documents%20and%20Settings/Administrator/My%20Documen...

Published with MATLAB 7.6

5 of 5

11/4/2013 4:30 PM

Vous aimerez peut-être aussi