Reputation: 21
I am using scipy.interpolate.CubicSpline for basically interpolating between three frames, which I have to do for each pixel of the frame:
for x in range(input_img.shape[1]):
for y in range(input_img.shape[0]):
t = (t_frame_k_minus_1 + v, t_frame_k + y, t_frame_k_plus_1 + v_strich)
x_interpolated = CubicSpline(t, (u, x, u_strich))
y_interpolated = CubicSpline(t, (v, y, v_strich))
interpolation_results[pix_count, 0] = x_interpolated(t_frame_k_half_N)
interpolation_results[pix_count, 1] = y_interpolated(t_frame_k_half_N)
this takes approximately 12 min (I have an 1920 x 1080 frame). Now I want to now, is there a faster way for cubic spline interpolation? If you now an answer in MATLAB, I could use that too
Upvotes: 0
Views: 532
Reputation: 35525
In MATLAB you can use either interp3
or imresize3
. I would suggest the second if you want interpolation in uniform time points.
You can just do
frames=cat(3,frame1, frame2 ,...); % just make your data a 3D volume
size_frame_3= size(frames,3)*2; % or any other uniform sampling
vol_out=imresize3(frames,[size(frames,1);size(frames,2);size_frame_3])
Otherwise, with interp3
:
frames=cat(3,frame1, frame2 ,...); % just make your data a 3D volume
desired_t_indx= % make a list of which t points you want to interpolate at, assuming frames are at t=1:size(frames,3)
[y, x, z]=ndgrid(1:size(frames,1),1:size(frames,2),desired_t_indx);
framesOut=interp3(frames,x,y,z,'cubic');
Both of this should take significantly less than 12 minutes. The second one takes 0.316283 seconds in my PC for 1900x1080x3 frames
where I make desired_t_inx=[1.5,2.5]
, i.e. 2 frames.
Upvotes: 2