Coefficient computation for bicubic interpolation

Dear Community Members,
Since bicubic interpolation for an image requires 16 coefficients which will eventually form the window with which we would convolve the sampled image, right. So my question is "how could I calculate these coefficients?". Do I have to get the matrix of the input image through matlab? If yes, how? Kindly don't suggest imread since it only shows how many rows and columns are present. If no, what is an exact way of computing the coefficients for bicubic interpolation?
Thanks in advance

Answers (1)

Matt J
Matt J on 20 Nov 2012
Edited: Matt J on 20 Nov 2012
Normally, you would use interp2, griddedInterpolant, or the spline command to do bicubic interpolation.
Only in very special cases, like if you are interpolating at gridded sample points, can the operation be formulated as a convolution, and even then, griddedInterpolant probably does this for you internally.

18 Comments

I used spline but in vain. Do you have an example of this command?
Do you have an example of what you tried?
Yes, here it is: bicubic=[1 4 6 4 1; 4 16 24 16 4; 6 24 36 24 6; 4 16 24 16 4; 1 4 6 4 1]; These coefficients were convolved with the input image later.
Using spline was trial and error thing and hence I wouldn't prefer to use it unless somebody could convince me to. This is because my results were horrible and not even close plus my input is an image and not a numerical data and hence I immediately assumed that spline wouldn't work for it. What are your suggestions on the filter? I basically filled in the repeated values wherever there were zeros.
Now how did I get these values? I basically made assumptions that since bicubic is parabolic in nature and hence the equation would be close to y=x^2.
Matt J
Matt J on 20 Nov 2012
Edited: Matt J on 20 Nov 2012
That's not an example of what you tried. That is an example of some sort of initial data. What is supposed to be done with this data? If it is to be interpolated, then at what locations?
That's exactly my point in the question which I repeat: "how could I calculate these coefficients?" or more precisely relating to your comment, "how could I compute or know the locations at which the interpolation process needs to be carried out?"
When you perform an interpolation operation, the locations at which you interpolate are the raw input data and are supposed to be known a priori by you. They are not something that gets computed over the course of the operation.
For example, if I have the data [10,20] and I associate them with the locations [1,2] and I want to interpolate at the locations [1.5,1.7], I would do as follows
>> interp1([1,2], [10 20], [1.5,1.7],'spline')
ans =
15 17
This would have been fine given my input would have been numerical which is not the case since my input is an image. In case of an "Image", I am basically sampling it eight times after which I need to see the matrix of the image. Hence my next question already stated above, "Do I have to get the matrix of the input image through matlab? If yes, how?".
Well, your terminology is a bit confusing. I don't know why an "image" is something you consider a non-numerical thing. An image is just a 2D numerical array
However, here is what I suspect you want: I suspect you are given an image of dimensions NxN and you want to obtain an upsampled version of this image that is 8Nx8N. If that's the case, you would do
F=griddedInterpolant(yourImage,'cubic');
locations=linspace(1,N,8*N);
newImage=F({locations, locations});
First of all, Thanks for all your help.
Second, How does this method works. I'm trying to access it's functionality through help command but there's no documentation on it plus for some reason, this function is undefined in Matlab.
Third, I am trying to reconstruct an image using cubic interpolation. I have an image, I intentionally down sampled it ten times. Using this down sampled image, I am trying to reconstruct it using cubic interpolation.
What version of MATLAB do you have?
If you have an old version of MATLAB, you can also upsample by factors of 2^n by doing
newImage = interp2(yourImage,n, 'spline');
I have 7.9.0 R2009b, Maybe its not supported. Since I'm doing cubic interpolation instead of spline, interp2(xs,'cubic'); appeared appropriate but the image got even more distorted.
I assume you really meant to write
interp2(xs,3,'cubic');
No, I didn't mean to since 'n' is giving out of memory error even though the code itself makes sense.
Matt J
Matt J on 21 Nov 2012
Edited: Matt J on 21 Nov 2012
Not sure why that's what you wnat. If you do interp2(xs,'cubic'), you will upsample xs by a factor of 2, whereas earlier you said you wanted to upsample by a factor of 8.
Anyway, if you don't like the result, it's either because your data is bad or else it's not very cubic.
It's not about ther result, I am not getting it at the first place with interp2(xs,3,'cubic'); I'm getting out of memory error.
Matt J
Matt J on 21 Nov 2012
Edited: Matt J on 21 Nov 2012
My 2nd remark was referring to the factor-of-2 upsampling result, not the one that gave you an out-of-memory error.
Earlier, you said you thought that result looked distorted. If it looks distorted, the only thing to blame is either the data or the interpolation model.
I believe so too, Thanks for help.

Sign in to comment.

Categories

Find more on Interpolation in Help Center and File Exchange

Asked:

on 20 Nov 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!