Discussion:
interp1 with uint8, please help!
(too old to reply)
Tyler Durdon
2007-12-05 17:26:40 UTC
Permalink
The interp1 function does not work with uint8 values. Is
there a similar Matlab function that does? I need this to
save space, because I'm interpolating matrix with size of
1024x1024x500 etc. Thank you.
Bruno Luong
2007-12-05 18:30:39 UTC
Permalink
If I was you, I would do the following:

- allocate a big 3d result array in uint8 class,
- do the interpolation by smaller block (say 10 images)
- Before calling interp1, cast your smaller block of inputs
from uint8 in float (e.g., single is OK), call interp1, then
affect the interpolation single array to the big 3d array of
uint8 (it will cast automatically).

Bruno
Tyler Durdon
2007-12-05 19:36:09 UTC
Permalink
Post by Bruno Luong
- allocate a big 3d result array in uint8 class,
- do the interpolation by smaller block (say 10 images)
- Before calling interp1, cast your smaller block of inputs
from uint8 in float (e.g., single is OK), call interp1, then
affect the interpolation single array to the big 3d array of
uint8 (it will cast automatically).
Bruno
Is there any way I could get you do show me the Matlab code
for this. I can do it, but your programming would be more
efficient I'm sure. Other though, Imresize uses interp with
grey level values (0-255), same as uint8. Regards.
Bruno Luong
2007-12-05 20:38:16 UTC
Permalink
%
Here we go, this is a quick try of mine. I do something not
sophisticate on the input. If it takes memory, we can try to
squeeze it a little more.

Hope it helps,

Bruno

% uint8 Input data
% This is an example:
% M=reshape(1:10,1,1,[]);
% M=repmat(M,[5,5,1]);
% M=uint8(M);

k=4; % multication factor of number of frames
d=size(M);
z=1:d(3); % original frame number
nint=(d(3)-1)*k+1; % number of interpolated frames
zi=linspace(1,d(3),nint); % interpolated indices

% Allocate a big output 3d array, same class as the original
sizeout=[d(1:2) nint];
Mint=zeros(sizeout,class(M));

% Cast original frame input to float
Msingleperm=single(permute(M,[3 1 2]));

blksize=10; % blocksize, will interpolate 10 by 10 by 10...
braket=union(0:blksize:nint,nint); % where to split
zilist=mat2cell(zi,1,diff(braket)); % splitting indices

% Go...
for i=1:length(zilist)
Mint(:,:,braket(i)+1:braket(i+1)) = ...
permute(interp1(z,Msingleperm,zilist{i}),[2 3 1]);
end
Tyler Durdon
2007-12-06 20:49:06 UTC
Permalink
Post by Bruno Luong
%
Here we go, this is a quick try of mine. I do something not
sophisticate on the input. If it takes memory, we can try to
squeeze it a little more.
Hope it helps,
Bruno
% uint8 Input data
% M=reshape(1:10,1,1,[]);
% M=repmat(M,[5,5,1]);
% M=uint8(M);
k=4; % multication factor of number of frames
d=size(M);
z=1:d(3); % original frame number
nint=(d(3)-1)*k+1; % number of interpolated frames
zi=linspace(1,d(3),nint); % interpolated indices
% Allocate a big output 3d array, same class as the original
sizeout=[d(1:2) nint];
Mint=zeros(sizeout,class(M));
% Cast original frame input to float
Msingleperm=single(permute(M,[3 1 2]));
blksize=10; % blocksize, will interpolate 10 by 10 by 10...
braket=union(0:blksize:nint,nint); % where to split
zilist=mat2cell(zi,1,diff(braket)); % splitting indices
% Go...
for i=1:length(zilist)
Mint(:,:,braket(i)+1:braket(i+1)) = ...
permute(interp1(z,Msingleperm,zilist{i}),[2 3 1]);
end
Hi Bruno,
Thanks a lot for that code it worked like a champ. It's
slower, but it solved the memory problems I was having which
is excellent! Have a good day.

Loading...