Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lukeje opened this issue Nov 16, 2022 · 2 comments
Open

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

lukeje opened this issue Nov 16, 2022 · 2 comments
Labels
bug Something isn't working futureplans

Comments

@lukeje
Copy link
Member

lukeje commented Nov 16, 2022

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.

@lukeje lukeje added the bug Something isn't working label Nov 16, 2022
@lukeje lukeje changed the title Magntitude of input for R2* calculation must be >> 1 Magnitude of input for R2* calculation must be >> 1 Nov 16, 2022
@siawoosh
Copy link
Contributor

siawoosh commented Jan 30, 2023

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
Copy link
Member Author

lukeje commented Feb 28, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working futureplans
Projects
None yet
Development

No branches or pull requests

2 participants