MATLAB: Can I apply imtranslate to a 4D image

4d imagedicomimage processingimtranslate

Can you please give me examples of imtranslate code lines that is being applied to a 4D DICOM image?
I get the errors that imtranslate is taking a 3D image as input.

Best Answer

The code below implements what I mentioned in my comment. It might also be the case that your 4D is actually a 3D in the same format as in the mri.mat example bundled with the IPT. In that case, you could simply have used squeeze.
S=load('mri');%load a builtin 3D example
IM=repmat(squeeze(S.D),1,1,1,10);%generate a 4D
translation_vector=[13 40 -1 2];
IM2=imtranslate(IM(:,:,:,1),translation_vector(1:3));
for n=2:size(IM,4)
IM2(:,:,:,n)=imtranslate(IM(:,:,:,n),translation_vector(1:3));
end
if translation_vector(4)~=0
IM2b=imtranslate(squeeze(IM2(1,:,:,:)),[0 0 translation_vector(4)]);
IM2b=permute(IM2b,[4 1 2 3]);
for n=2:size(IM2,1)
IM2b(n,:,:,:)=imtranslate(squeeze(IM2(n,:,:,:)),[0 0 translation_vector(4)]);
end
IM2=IM2b;
end
Related Question