A customer asked me last week how to do multidimensional interpolation with integer inputs. The MATLAB function interpnsupports only double- and single-precision inputs.
It's possible to do this using a little-known Image Processing Toolbox function called tformarray. But tformarray is a general spatial transformation engine with a complicated syntax. It isn't easy to figure out how to use it for interpolation, so I decided to write a wrapper M-file to do it.
The function iminterpn, which has a syntax similar to interpn, is now available on the MATLAB Central File Exchange. I hope some of you find it useful.
i have a gray value image(512×512), it has some high contrast objects in it. i extracted the high contrast objects from the gray value image and created another binary image of same size. now, i want to do interpolation on the gray value image where/under the high contrast objects are, and i also want to overlay the high contrast objects image on the interploated new image. could you please help me in this step?
Damodar—You might find the function roifill to be useful for interpolating in the gray value image based on the locations of the high contrast objects. I’m not I understand your second question. If you overlay the high-contrast objects over the original image, which has been changed only by modifying the pixels where the high-contrast objects are, wouldn’t you expect the result to look just like the original image?
thank you very much for giving information for my last question.sir now I want to upsample the image using cubic spline interpolation.sir I used the following code [X,Y]=meshgrid(2:2:256)
Z(X,Y)=Image
[X1,Y1]=meshgrid(2:1:256)
Z1 = interp2(X,Y,Z,X1,Y1,’spline’)
I got the error” Subscripted assignment dimension mismatch”.
Can I use ‘interp2′ instruction for cubic spline interpolation of image(both colour and grey)
reji
hai
I want to upsample the image using cubic spline interpolation.
Can I use ‘interp2′ instruction for cubic spline interpolation of image(both colour and grey)
Can I use convolution methods for cubic spline interpolation
‘Pratt’ in his image processing book mentioned that convolution kernals can be used for interpolation.
reji
Reji—Yes, you can use interp2 for cubic spline interpolation of an image. I do not know why you received an error message. You’ll need to check your interp2 inputs carefully against the description in the reference page for interp2.
Continuous-time convolution kernels can be used for interpolation. For example, linear interpolation can be viewed as convolution of an impulse train with a triangular kernel. However, cubic spline interpolation is more involved, because the proper kernel weights are data-dependent.
I think I see the problem. Your script assumes a cubic array, whereas I have a stack of images obtained from microscopy where the interpixelar distance in the plane of an image does not correspond to the image separation distance. Am I correct about this? Is there anyways you can make this script fully functional, like the interpn command (so it would take the same number of inputs and wouldn’t be limited to evenly spaced arrays of data)?
I would like to use sinc interpolation in imtransform. I read the Matlab user guide that makeresampler can be used to customize an interpolant for use in imtransform. However, I don’t quite understand how to use makeresampler to creat a sinc interpolant based on the example given there. Can you please guide/show me how to do this?
Thank you very much and your help is truly appreciated!
where interpolant is a two-element cell array of the
form:
{half_width, positive_half}
half_width is a positive scalar designating the half width of a symmetric interpolating kernel. positive_half is a vector of values regularly sampling the kernel on the closed interval [0 positive_half]. So you could just provide a closely-spaced table of samples of the sinc function. You can’t truly interpolate using the sinc function, of course, since it is infinitely wide. You’ll have to choose a suitable width.
Thanks for your guidance. I wonder if I need to supply the R = makeresampler({half_width, positive_half}, padmethod)
with the positive_half of a ‘normalized’ sinc function or it does the normalization inherently when image is resampled during imtransform?
Thanks for your reply regarding how to use makeresampler function. I’ve written the codes below to supply the makeresampler with a Hann windowed truncated sinc function interpolating kernel (positive half). I used the function trapz to calculate the are under the function’s curve. Is this the right or proper way to make a normalized interpolating kernel? Thank you for your help.
fc = 0.4;
halfWidth = 3;
samplingRate = 0.001;
x = -halfWidth:samplingRate:halfWidth; % sampling frequency = 1000Hz
hannWind = hann(length(x));
hannWindSinc = hannWind.*(sin(2*pi*fc*x)./(pi*x))';
hannWindSinc(floor(length(x)/2+1),1) = max(hannWindSinc(:));
normHannWindSinc = hannWindSinc/(trapz(hannWindSinc)*samplingRate);
R = makeresampler({halfWidth, normHannWindSinc(floor(length(normHannWindSinc)/2+1):end)'},
'bound');
Esther—It seems like a reasonable procedure, although the function you’ve created is not, strictly, speaking, and interpolation kernel. Because it does not go through 0 at 1, -1, 2, -2, …, the output won’t exactly equal the input at the locations corresponding to the input samples, which is what you’d expect from interpolation. It looks like the function you’ve chosen will have a smoothing effect.
About
Steve Eddins is a software development manager in the MATLAB and image processing areas at MathWorks. Steve coauthored Digital Image Processing Using MATLAB. He writes here about image processing concepts, algorithm implementations, and MATLAB.
thank u sir
Hi Steve:
i have a gray value image(512×512), it has some high contrast objects in it. i extracted the high contrast objects from the gray value image and created another binary image of same size. now, i want to do interpolation on the gray value image where/under the high contrast objects are, and i also want to overlay the high contrast objects image on the interploated new image. could you please help me in this step?
Thank U.
Sincerely
Damodar
Damodar—You might find the function roifill to be useful for interpolating in the gray value image based on the locations of the high contrast objects. I’m not I understand your second question. If you overlay the high-contrast objects over the original image, which has been changed only by modifying the pixels where the high-contrast objects are, wouldn’t you expect the result to look just like the original image?
Sir
thank you very much for giving information for my last question.sir now I want to upsample the image using cubic spline interpolation.sir I used the following code [X,Y]=meshgrid(2:2:256)
Z(X,Y)=Image
[X1,Y1]=meshgrid(2:1:256)
Z1 = interp2(X,Y,Z,X1,Y1,’spline’)
I got the error” Subscripted assignment dimension mismatch”.
Can I use ‘interp2′ instruction for cubic spline interpolation of image(both colour and grey)
reji
hai
I want to upsample the image using cubic spline interpolation.
Can I use ‘interp2′ instruction for cubic spline interpolation of image(both colour and grey)
Can I use convolution methods for cubic spline interpolation
‘Pratt’ in his image processing book mentioned that convolution kernals can be used for interpolation.
reji
Reji—Yes, you can use interp2 for cubic spline interpolation of an image. I do not know why you received an error message. You’ll need to check your interp2 inputs carefully against the description in the reference page for interp2.
Continuous-time convolution kernels can be used for interpolation. For example, linear interpolation can be viewed as convolution of an impulse train with a triangular kernel. However, cubic spline interpolation is more involved, because the proper kernel weights are data-dependent.
Hi Steve,
Can this interpolate type logical input? For example if I have a 3D BW matrix that I want to interpolate?
Thanks
~Roman
Roman—Yes.
Hi Steve,
I am trying to convert this:
Original_Image_3D_Matrix_INTERPOLATED_all_channels(:,:,:,tiff_channel_number) = …
uint8(interp3(X_original,Y_original,Z_original,…
double(Original_Image_3D_Matrix(:,:,:,tiff_channel_number)),…
X_interpolated,Y_interpolated,Z_interpolated));
to this:
Original_Image_3D_Matrix_INTERPOLATED_all_channels(:,:,:,tiff_channel_number) = …
iminterpn(Original_Image_3D_Matrix(:,:,:,tiff_channel_number),…
X_interpolated,Y_interpolated,Z_interpolated);
the former works while the latter gives me mostly black images. is there anything that jumps out at you that i am doing wrong?
Steve,
I think I see the problem. Your script assumes a cubic array, whereas I have a stack of images obtained from microscopy where the interpixelar distance in the plane of an image does not correspond to the image separation distance. Am I correct about this? Is there anyways you can make this script fully functional, like the interpn command (so it would take the same number of inputs and wouldn’t be limited to evenly spaced arrays of data)?
~Roman
hi
am trying to do image interpolation with bilinear method but i donot know how to start withm can you please suggest me some algorithm to do
interp3 is what i use for interpolating a 3D stack of images
Hi Steve,
I would like to use sinc interpolation in imtransform. I read the Matlab user guide that makeresampler can be used to customize an interpolant for use in imtransform. However, I don’t quite understand how to use makeresampler to creat a sinc interpolant based on the example given there. Can you please guide/show me how to do this?
Thank you very much and your help is truly appreciated!
Esther—Use this syntax:
where interpolant is a two-element cell array of the
form:
{half_width, positive_half}half_width is a positive scalar designating the half width of a symmetric interpolating kernel. positive_half is a vector of values regularly sampling the kernel on the closed interval [0 positive_half]. So you could just provide a closely-spaced table of samples of the sinc function. You can’t truly interpolate using the sinc function, of course, since it is infinitely wide. You’ll have to choose a suitable width.
Hi Steve,
Thanks for your guidance. I wonder if I need to supply the R = makeresampler({half_width, positive_half}, padmethod)
with the positive_half of a ‘normalized’ sinc function or it does the normalization inherently when image is resampled during imtransform?
Thank you.
Esther—No automatic normalization is performed. You have to supply an interpolating kernel that is correctly normalized.
Hi Steve,
Thanks for your reply regarding how to use makeresampler function. I’ve written the codes below to supply the makeresampler with a Hann windowed truncated sinc function interpolating kernel (positive half). I used the function trapz to calculate the are under the function’s curve. Is this the right or proper way to make a normalized interpolating kernel? Thank you for your help.
fc = 0.4; halfWidth = 3; samplingRate = 0.001; x = -halfWidth:samplingRate:halfWidth; % sampling frequency = 1000Hz hannWind = hann(length(x)); hannWindSinc = hannWind.*(sin(2*pi*fc*x)./(pi*x))'; hannWindSinc(floor(length(x)/2+1),1) = max(hannWindSinc(:)); normHannWindSinc = hannWindSinc/(trapz(hannWindSinc)*samplingRate); R = makeresampler({halfWidth, normHannWindSinc(floor(length(normHannWindSinc)/2+1):end)'}, 'bound');Esther—It seems like a reasonable procedure, although the function you’ve created is not, strictly, speaking, and interpolation kernel. Because it does not go through 0 at 1, -1, 2, -2, …, the output won’t exactly equal the input at the locations corresponding to the input samples, which is what you’d expect from interpolation. It looks like the function you’ve chosen will have a smoothing effect.