How to enlarge an image using spline interpolation

I want to double the size of the input image using "spline". Please tell me how

 Accepted Answer

KSSV
KSSV on 28 Aug 2020
Edited: KSSV on 28 Aug 2020
I = imread("image.jpeg") ; % assuming image to m*n
[m,n,p] = size(I) ;
x = 1:n ;
y = 1:m ;
% Inteprolate to double
xi = 1:2*n ;
yi = 1:2*m ;
I = double(I) ;
Inew = zeros(2*m,2*n) ;
% Row wise inteprolation
for i = 1:m
Inew(i,:) = spline(x,I(i,:),xi) ;
end
% Column wise interpolation
for j = 1:n
Inew(:,j) = spline(y,I(:,j),yi) ;
end
Change the class if Inew to the original I. Also read about imresize.

5 Comments

I'm sorry to reply your comment.
Thank you for helping me.
But I didn't work.
inputimageoutputimage
I = imread("lenna.jpg") ; % assuming image to m*n
I=rgb2gray(I);
[m,n,] = size(I) ;
x = 1:n ;
y = 1:m ;
% Inteprolate to double
xi = 1:2*n ;
yi = 1:2*m ;
I = double(I) ;
Inew = zeros(2*m,2*n) ;
% Row wise inteprolation
for i = 1:m
Inew(i,:) = spline(x,I(i,:),xi) ;
end
% Column wise interpolation
for j = 1:n
Inew(:,j) = spline(y,I(:,j),yi) ;
end
figure
imshow(Inew)
Check the below code:
I = imread("image.jpeg") ; % assuming image to m*n
I=rgb2gray(I);
[m,n] = size(I) ;
x = 1:n ;
y = 1:m ;
% Inteprolate to double
xi = linspace(1,n,2*n) ;
yi = linspace(1,m,2*m) ;
I = double(I) ;
I1 = zeros(m,2*n) ;
% Row wise inteprolation
for i = 1:m
I1(i,:) = spline(x,I(i,:),xi) ;
end
Inew = zeros(2*m,2*n) ;
% Column wise interpolation
for j = 1:2*n
Inew(:,j) = spline(y,I1(:,j),yi) ;
end
Inew = uint8(Inew) ;
figure
imshow(Inew)
Thank you for your replying.
I succeeded thanks to you.
What was the cause of the failure?
KSSV
KSSV on 29 Oct 2020
Edited: KSSV on 29 Oct 2020
You can see both the codes given..there are few mistakes int he first code which have been rectiffied. Especially generating the new grid fot enlarging the image.
Thanks is accepting/ voting the answer.
Thank you for your replying!
I understood!

Sign in to comment.

More Answers (1)

A=peaks(10);
B=interp2(A,1,'spline');
subplot(1,2,1)
imagesc(A)
subplot(1,2,2)
imagesc(B)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Products

Release

R2020a

Asked:

T.K
on 28 Aug 2020

Commented:

T.K
on 30 Oct 2020

Community Treasure Hunt

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

Start Hunting!