Interpolation filter in video

Hello,
I've been looking at the documentation on the 'interp' function, which is the function that I think I should use.
My problem is as follows: I have two types of images, alpha and negative alpha, which is alpha * (-1). Imagine that my alpha image goes from 1 to -1 and the negative alpha goes from -1 to 1, what I want to achieve is to create a video of numbers of Frames 'N', where the interpolation values are parameterizable, that is the interpolation time and the number of samples to be used, thus achieving a 'temporary' filtering.
The result of this function should be a 'N' frames video where what we will see will be in frame1: alpha, ...... frame3: alpha negative, .... frame5: alpha, frame7: alpha negative .. ..
Frame 3 is an example since it will depend on interpolation.
In the following image I show you an example of what it should be, to see if you can guide me or give a help with this problem.
Thank you very much in advance, any sure answer will help me, regards!

 Respuesta aceptada

Ameer Hamza
Ameer Hamza el 9 de Mzo. de 2020
I am not sure why you scaled the pixels from -1 to 1. The following code use pixel values from 0 to 1, and the inverse image have pixel values from 1 to 0.
im = im2double(imread('peacock.jpg'));
im_reverse = 1-im;
N = 10;
time = reshape(linspace(0, 1, N), 1, 1, 1, N);
frames = im_reverse.*time + im.*(1-time);
v = VideoWriter('video_file', 'MPEG-4');
v.FrameRate = 10;
open(v);
for i = 1:5 % how many times to repeat pattern
% im to im_reverse
for j=1:N
frame = frames(:,:,:,j);
writeVideo(v, frame);
end
% im_reverse to im
for j=N:-1:1
frame = frames(:,:,:,j);
writeVideo(v, frame);
end
end
close(v);

4 comentarios

Alber
Alber el 9 de Mzo. de 2020
I did it this way because for my code I needed to have an 'alpha' matrix that added as a mask to the video that was. The resulting video I want to get would be, for example:
frame1: video + alpha
frame2: video + alpha * (- 1) ----> If it were 0 to 1 I could not multiply by -1 but since I have 1 to -1 I get -1 to 1.
frame3: video + alpha
That is the only reason why my matrix goes from 1 to -1, I attached images:
Alpha matrix:
-Alpha matrix:
and regarding your code: 'N' are the number of samples interpolated per frame? and you could tell me what you do in these lines:
time = reshape (linspace (0, 1, N), 1, 1, 1, N);
frames = im_reverse. * time + im. * (1-time);
Otherwise I see the code great, I think it will be of great help. Thank you so much for helping me!
Yes, N is the number of frames from im to im_reverse.
These lines take advantage of the array expansion capability of MATLAB to simplify the code. This is equivalent to
time = linspace(0, 1, N);
frames = zeros([size(im), 10]);
for i = 1:length(time)
frames(:,:,:,i) = im_reverse .* time(i) + im. * (1-time(i));
end
Alber
Alber el 9 de Mzo. de 2020
Thank you very much, so it is not necessary to use the interp function?
Ameer Hamza
Ameer Hamza el 9 de Mzo. de 2020
It is possible with interp1, but the solution is a lot messier.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 9 de Mzo. de 2020

Comentada:

el 9 de Mzo. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by