hMRI-group / hMRI-toolbox

A toolbox for quantitative MRI and in vivo histology using MRI (hMRI)
GNU General Public License v2.0
60 stars 44 forks source link

Magnitude of input for R2* calculation must be >> 1 #57

Open lukeje opened 1 year ago

lukeje commented 1 year ago

Description of problem

Several tools along the hMRI toolbox pipeline were written under the expectation that the input data would always be integer-type nifti files. This means that several shortcuts were taken (e.g. here) which become invalid for input data which have magnitudes in the range [0, 1].

Workaround

Scale all of the input data by some large factor (e.g. 1000 or 10000) before putting them into the toolbox pipeline. This can be done using e.g. spm_calc or fslmaths. Note that such tools often overwrite the descrip field of the nifti file, and so it is strongly advised to use sidecar json files containing the protocol details (with the same base-name as the newly-scaled data) rather than relying on the descrip field.

siawoosh commented 1 year ago

I think that scaling only can be dangerous because it might introduce ceiling effects for other data (data format).

A simple solution to solve both problems could be to plug a normalization function (see what we use in acid_hysco below) before the thresholding step in line data = max(data, 1);

---- Example normalisation function ----

function [I1,I2] = normalizeIntensities(I1,I2)

% =========================================================================
% function [I1,I2] = normalizeIntensities(I1,I2
%
% normalizes intensities to the range of [0, 256]
%
% Inputs:
%   I1,I2  - image data with intensity range [mini, maxi]
%
% Outputs:
%   I1,I2  - image data with intensity range [0, 256]
% =========================================================================

    mini = min(min(I1(:)),min(I2(:)));
    I1 = I1 - mini;
    I2 = I2 - mini;
    maxi = max(max(I1(:)),max(I2(:)));
    I1 = (256/maxi)*I1;
    I2 = (256/maxi)*I2;

end
lukeje commented 1 year ago

Thanks for the suggestion @siawoosh. However I can imagine scenarios where this could get problematic, e.g. if a non-linear deformation had been applied to the image before being input into the toolbox and so there are very positive or very negative voxels. Probably there are ways to guess reasonable min and max values from the data (e.g. percentiles) which would be less affected by these outliers, but they could still go wrong. Perhaps we should provide a rescaling function ourselves where the user can specify the min and max values to be scaled?