Sunday, February 21, 2010

Video Spatial Transformation - Resize

To change the size of an image in Matlab, use the imresize function. Using imresize, you can
  1. Specify the size of the output image
  2. Specify the interpolation method used
  3. Specify the filter to use to prevent aliasing

For this example however i will be using the Resize to set the size of the output
Using imresize, you can specify the size of the output image in two ways:
  • By specifying the magnification factor to be used on the image
  • By specifying the dimensions of the output image

Using 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 increases the size of the image I by 1.25 times.
I = imread('circuit.tif');
J = imresize(I,1.25);
imshow(I);
figure, imshow(J)
The same can be done in Videos:

fin = 'rawVideo.avi'; fout = 'test.avi'; fileinfo = aviinfo(fin); nframes = fileinfo.NumFrames; aviobj = avifile(fout, 'compression', 'none', 'fps',fileinfo.FramesPerSecond); for i = 1:20 %Read frames from input video mov_in = aviread(fin,i); im_in = frame2im(mov_in); %Do processing on each frame of the video
%----------------------------------------------------------------------
%In this example - Image Resize enlarge 5 times
im_out = imresize(im_in,5);
%----------------------------------------------------------------------
%Write frames to output video frm = im2frame(im_out); aviobj = addframe(aviobj,frm); %i %Just to display frame number end; %Don't forget to close output file aviobj = close(aviobj); msgbox('DONE'); return;

The results:


Image 1: Enlarged by 5X


Image 2: Enlarged by 1.5X


Image 3: Reduced by 0.5X

No comments:

Post a Comment