0

I wanted to move the DICOM images around x-axis with the value 4.2 milimeter and have written the following code:

srcFile2=dir('C:\Users\User\Desktop\Projekt\meine B.A\Programmieren\Archiv CBCT_A_04_08\*.dcm');
for i=1:88
    filename2=strcat('C:\Users\User\Desktop\Projekt\meine B.A\Programmieren\Archiv CBCT_A_04_08\',srcFile2(i).name);
    CBCT(:,:,i)=dicomread(filename2);
end
info_CBCT=dicominfo('C:\Users\User\Desktop\Projekt\meine B.A\Programmieren\Archiv CBCT_A_04_08\CT.Test CatPhan.Image 1');
info_CBCT.PixelSpacing(1);
info_CBCT.PixelSpacing(2);

CBCT=double(CBCT);

cb_ref = imref2d(size(CBCT),info_CBCT.PixelSpacing(1),info_CBCT.PixelSpacing(2))

T = [1 0 0;0 1 0;4.2 0 1];%-2.5883
tform_t = affine2d(T);
for j=1:88
Axial_CBCT_Trans1(:,:,j)= imwarp(CBCT(:,:,j),tform_t);
end

It worked without any error message. Then I subtracted the image before and after the translation.

Axial_CBCT_Trans1(:,:,48)-CBCT(:,:,48);

After the subtraction the difference is zero. this has the following that the image is not shifted around x-axis. Does anyone have this problem? I would ask if my code is written correctly? Can the command (affine2d) be used in DIOM images or is there another command for the DICOM data , to move the DICOM images in x axis?

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141

1 Answers1

1

By default imwarp automatically centralize the output image.
You may add 'OutputView' argument for avoiding the automatic centralization.

Replace imwarp(CBCT(:,:,j),tform_t); with:

imwarp(CBCT(:,:,j), tform_t, 'OutputView', imref2d(size(CBCT(:,:,j))));

Here is a code sample that reproduce the issue (without DCOM):

I = imread('peppers.png');

T = [1 0 0; 0 1 0; 40.2 0 1];
tform_t = affine2d(T);

J = imwarp(I, tform_t); % Automatic centralization
K = imwarp(I, tform_t, 'OutputView', imref2d(size(I)));

figure;imshow(J);title('J'); % Displayed without translation.
figure;imshow(K);title('K'); % Displayed with translation.
Rotem
  • 30,366
  • 4
  • 32
  • 65