Slope and intercept when reading Nifti images

Dear all,

I have a very basic question: I am reading in nifti images using:

ImageType::Pointer readImage(string imageName) {
typename ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(imageName);
try {
reader->Update();
}
catch (itk::ExceptionObject &excp) {
std::cerr << excp << std::endl;
}
ImageType::Pointer image = reader->GetOutput();
return reader->GetOutput();
}

Am I correct that the ITK image reader is applying the slope and intercept automatically? Or do I have to manually multiply by the slope and add the intercept to get the correct values?

I am asking because I have some images where the results are reasonable, but I have one image where the image values are not making sense after reading it. When I apply then slope and intercept, the values are making sense… (this file can be downloaded here: https://wetransfer.com/downloads/3aa534c3139492a4687df079bd1bde0120190805143844/4ff1ff5b3944d7bfa2b2c40c798ae40820190805143844/b82e99)

Thanks a lot for your answer.

Elli

Hi Elli,

Yes, rescale / slope and intercept is applied with NIFTI files per:

HTH,
Matt

1 Like

Dear Matt,

thanks for your answer…

But why is it not working for this specific image ? (you can find it here:
https://we.tl/t-ZKbnxnTWwr

)

All other softwares I used for comparison (Matlab, nibabel in python, etc) can read the image correctly. But when I read it with ITK, i get as maximum intensity 32767 as if the image would not have been scaled. When I scale it then manually by mutliplying with slope, I get the correct values. How can that be?

Thanks a lot for your help,

Elli

When I try to download the offending image, I get “Transfer deleted”. Has the the link expired? Can you refresh it?

Sure, sorry. Here is a new link: https://wetransfer.com/downloads/603bc96030ba5dfea33032524743e07b20190813161307/2586576f53a7554bfd45b001747119a320190813161307/e6f5d9

thanks in advance for looking into this!

The slope in this image is ignored because both SForm and QForm codes are zero:

1 Like

Hey Dzenan,

thanks! But officially that is not correct, right? Because I read that the scaling with slope and intercept should always be applied also when sform and qform are 0…

Anyhow, I can make a workaround in my code. So thanks a lot for the information!

Regards

Elli

Where is the official answer to this question? Also, you could dig a little through git history of that file to see when changes were made, and maybe also why.

Thanks, thats a good idea.

Well, officially is a bit difficult to define. We just had a big discussion in our group whats the right way to handle nifti images… And what we found online in the header descriptions was that scaling should always be applied. Anyhow, I will check the history! Thank you!

1 Like