Interpolation is the process used to estimate an image value at a location in between image pixels.
For example, if you resize an image so it contains more pixels than it did originally, the toolbox uses interpolation to determine the values for the additional pixels. The imresize and imrotate geometric functions use two-dimensional interpolation as part of the operations they perform. The improfile image analysis function also uses interpolation.
The interpolation methods all work in a fundamentally similar way. In each case, to determine the value for an interpolated pixel, they find the point in the input image that the output pixel corresponds to. They then assign a value to the output pixel by computing a weighted average of some set of pixels in the vicinity of the point. The weightings are based on the distance each pixel is from the point.
The methods differ in the set of pixels that are considered:
- For nearest-neighbor interpolation, the output pixel is assigned the value of the pixel that the point falls within. No other pixels are considered.
- For bilinear interpolation, the output pixel value is a weighted average of pixels in the nearest 2-by-2 neighborhood.
- For bicubic interpolation, the output pixel value is a weighted average of pixels in the nearest 4-by-4 neighborhood.
Heres the list of argument values you can use:
- 'nearest' Nearest-neighbor interpolation (the default)
- 'bilinear' Bilinear interpolation
- 'bicubic' Bicubic interpolation
Example for Images:
I = imread('circuit.tif');
J = imresize(I ,[100 150],'bilinear');
imshow(I)
figure, imshow(J)
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 using interpolation
im_out = imresize(im_in,1.5,'nearest'); %----------------------------------------------------------------------
%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:
No comments:
Post a Comment