Code covered by the BSD License  

Highlights from
Image Interpolation (ba_interp2)

3.0

3.0 | 4 ratings Rate this file 45 Downloads (last 30 days) File Size: 1.89 MB File ID: #20342
image thumbnail

Image Interpolation (ba_interp2)

by Brian

 

18 Jun 2008 (Updated 08 Oct 2010)

Fast nearest, bi-linear and bi-cubic interpolation for image data

| Watch this File

File Information
Description

% Fast nearest, bi-linear and bi-cubic interpolation for image data
%
% Usage:
% ------
% Z = ba_interp2(F, X, Y, [method])
%
% where method is one off nearest, linear, or cubic.
%
% F is a WxHxD Image with an arbitrary number of layers D.
% X, Y are I_1 x ... x I_n matrices with the x and y coordinates to
% interpolate.
% Z is a I_1 x ... x I_n x D matrix, which contains the interpolated image channels.
%
% Notes:
% ------
% This method handles the border by repeating the closest values to the point accessed.
% This is different from matlabs border handling.
%
% Example
% ------
%
% %% The mandrills eye
% clear
% IMG=load('mandrill');
% IMG = ind2rgb(IMG.X, IMG.map);
% [Dx Dy] = meshgrid(130:0.1:250, -150:0.1:-50);
%
% R = [cos(pi/4) sin(pi/4); -sin(pi/4) cos(pi/4)];
% RD = R * [Dx(:)'; Dy(:)'] + 250;
% RDx = reshape(RD(1,:), size(Dx));
% RDy = reshape(RD(2,:), size(Dy));
%
% methods = {'nearest', 'linear', 'cubic'};
% la=nan(1,3);
% for i=1:3
% la(i) = subplot(2,2,i);
% tic;
% IMG_R = ba_interp2(IMG, RDx, RDy, methods{i});
% elapsed=toc;
% imshow(IMG_R);
% title(sprintf('Rotation and zoom using %s interpolation took %gs', methods{i}, elapsed));
% end
% linkaxes(la);
%
% License:
% --------
% GPL
% (c) 2008 Brian Amberg
% http://www.brian-amberg.de/

Acknowledgements
This submission has inspired the following:
3D Volume Interpolation with ba_interp3: Fast interp3 replacement
MATLAB release MATLAB 7.8 (R2009a)
Other requirements mex compiler
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (11)
29 Mar 2010 Courtney

Won't run without compiling ba_interp2.cpp ba_interp2.cpp won't compile. Perhaps the mex file could be included for Windows?

06 Oct 2010 Brian

Hello Courtney,

the file is actually working well for me with gnu c++ compiler and intel compiler. If you could state the errors you receive under windows, I might be willing to fix it.

09 Oct 2010 Rob Campbell

Courtney, it's unfair to give an author one star simply because you couldn't compile the code.

03 Nov 2010 Vahid Kazemi  
03 Nov 2010 Vahid Kazemi

You may want to add:

#ifdef _WIN32
inline double round( double d )
{
    return floor( d + 0.5 );
}
#endif

at the beginning (after includes) of C++ file to compile the code on windows.

19 Jan 2011 Michael Chan

Hi Brian,

I am getting this error. Please advise me. Thank you.

>> mex -O ba_interp2.cpp
lcc preprocessor error: ba_interp2.cpp:55 Could not find include file <iostream>
Error ba_interp2.cpp: 57 syntax error; found `double' expecting `;'
Error ba_interp2.cpp: 64 syntax error; found `static' expecting `;'
Error ba_interp2.cpp: 72 syntax error; found `static' expecting `;'
Error ba_interp2.cpp: 74 syntax error; found `&' expecting `)'
Error ba_interp2.cpp: 74 skipping `&' `f00_i' `,'
Error ba_interp2.cpp: 75 missing name for parameter 1 to function `indices_linear'
Error ba_interp2.cpp: 75 syntax error; found `int' expecting `{'
Error ba_interp2.cpp: 75 empty declaration
Error ba_interp2.cpp: 75 syntax error; found `&' expecting `;'
Error ba_interp2.cpp: 75 undeclared identifier `f10_i'
Error ba_interp2.cpp: 76 illegal expression
Error ba_interp2.cpp: 76 undeclared identifier `f01_i'
Error ba_interp2.cpp: 77 illegal expression
Error ba_interp2.cpp: 77 undeclared identifier `f11_i'
Error ba_interp2.cpp: 78 illegal expression
Warning ba_interp2.cpp: 78 Statement has no effect
Error ba_interp2.cpp: 78 syntax error; found `int' expecting `;'
Error ba_interp2.cpp: 78 illegal statement termination
Error ba_interp2.cpp: 78 skipping `int'
Error ba_interp2.cpp: 78 undeclared identifier `x'
Error ba_interp2.cpp: 78 too many errors
 
  C:\PROGRA~1\MATLAB\R2010A\BIN\MEX.PL: Error: Compile of 'ba_interp2.cpp' failed.
 
??? Error using ==> mex at 222
Unable to complete successfully.

20 Jan 2011 Brian

Hello Michael,

have you tried to compile other mex files. Compilation works for me on Ubuntu and Fedora, but it seems that you are using Windows. I do not actively support windows, as I do not have a windows machine with matlab available.

Brian

23 Jan 2011 Michael Chan

Hi Brian,

yes, I am using Windows. This also happens to ba_interp3 as well. Could you supply a windows version as well, as though it may be a controversial platforms, there are many such users. Thank you for your efforts.

I really want to put a 5 stars rating, however, I cannot see the effects.

10 Feb 2011 Michael

Hi Brian,

I just wanted to verify without checking the entire code. Does your code do the same as
ZI = interp2(X,Y,Z,XI,YI)
? If not, what is the difference? Thanks! It works very fast!

10 Feb 2011 Brian

Hello Michael,

it has a slightly different feature set.
The differences are:
- No support for X, Y, you have to do that yourself to the XI and YI variables.
  That behaviour is what I need most often, and it saves a few cycles.
- Support for Z with dimensions HxWxD1xD2x..., returning Z(XI,YI,:,:,:,...) in slightly abused notation. I.e. it treats the dimensions following the first two dimensions as vectors and interpolates these. This is useful for color image interpolation, where you have arrays of size [H x W x 3].

I hope that helps,

Brian

04 Oct 2011 Jaroslaw Tuszynski

can not compile mex file

Please login to add a comment or rating.
Updates
09 Oct 2008

Forgot important keyword

08 Oct 2010

- Add single precision handling.
- Updated the string comparison function, such that it might work under visual studio (tested only with linux)

08 Nov 2010

Included patch by Vahid Kazemi.

Tag Activity for this File
Tag Applied By Date/Time
interp2 Brian 22 Oct 2008 10:06:29
interpolation Brian 22 Oct 2008 10:06:29
nearest neighbour Brian 22 Oct 2008 10:06:29
nearest neighbor Brian 22 Oct 2008 10:06:29
doesnt work Courtney 29 Mar 2010 17:48:34
bilinear Brian 06 Oct 2010 16:33:59
bicubic Brian 06 Oct 2010 16:34:05
image processing Brian 08 Oct 2010 11:55:53
bicubic kyleada 26 Mar 2012 23:25:35

Contact us at files@mathworks.com