How can I perfom an interpolation?
3 views (last 30 days)
Show older comments
Hello, I have a code called codeAlpha, which has a value range of -1 to 1. My buffer is called frameBuffer and it has a size of (height, width, numChannels, framesPerSymbol), where framesPerSymbol is the size of the buffer. This buffer will store the frames of a video.
The ultimate goal of this code is to return a buffer called encodedBuffer which will have encoded images. These images will be obtained by adding frame (original image) + code (temporary interpolated) because the code goes from -1 to 1 and we want this transition to be controlled by N.
This is my code, I am currently having problems with the time dimension and it gives me an error.
codeAlpha = mapped*alpha;
bufferSize = size(frameBuffer,4);
numChannels = size(frameBuffer,3);
time = linspace(-1, 1, N);
frames = cat(4,zeros([size(codeAlpha),numChannels,bufferSize]));
for i = 1:length(time)
frames(:,:,:,i) = codeAlpha.*time(:,:,:,i) + codeAlpha.*(1-time(:,:,:,i))*(-1);
end
for i =1:bufferSize
encodedBuffer = frameBuffer + frames;
end
As an example I have been testing:
imgInicial = ones(2160,3840,3);
imgFinal = ones(2160,3840,3)*11;
frameBuffer = cat(4, imgInicial, imgFinal);
N = 5;
The code has the same dimensions as the images in the buffer.
I hope I have explained clearly, if you need me to explain something else, please let me know. Thank you very much in advance.
0 Comments
Answers (1)
dpb
on 24 Apr 2020
time = linspace(-1, 1, N);
frames = cat(4,zeros([size(codeAlpha),numChannels,bufferSize]));
for i = 1:length(time)
frames(:,:,:,i) = codeAlpha.*time(:,:,:,i) + codeAlpha.*(1-time(:,:,:,i))*(-1);
...
What you trying to do here?
You've defined time as a vector of 100 points over range -1:1 but then try to reference it by a 4-D vector. That will return the whole thing by dimensions collapsing.
Look at the following minimal example that is small-enough and clean-enough to be able to visualize what's going on as outline...
B=ones(2,3,3,3); % a trivially easy buffer array of three frames
t=linspace(-1,1,size(B,4)); % your weighting time vector sized on B to work in place
for i=1:numel(t),B(:,:,:,i)=B(:,:,:,i)*t(i);end % apply the weight -- other side is obvious
% show resulting B
>> B(:,:,:,1)
ans(:,:,1) =
-1 -1 -1
-1 -1 -1
ans(:,:,2) =
-1 -1 -1
-1 -1 -1
ans(:,:,3) =
-1 -1 -1
-1 -1 -1
>> B(:,:,:,2)
ans(:,:,1) =
0 0 0
0 0 0
ans(:,:,2) =
0 0 0
0 0 0
ans(:,:,3) =
0 0 0
0 0 0
>> B(:,:,:,3)
ans(:,:,1) =
1 1 1
1 1 1
ans(:,:,2) =
1 1 1
1 1 1
ans(:,:,3) =
1 1 1
1 1 1
>>
% Show problem of wrong addressing for the time vector...
>> t(:,:,:,1)
ans =
-1 0 1
>>
0 Comments
See Also
Categories
Find more on Computer Vision with Simulink in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!