MATLAB Answers

Normalize the intensity of the data within an ROI to a zero-mean, unit-variance space

6 views (last 30 days)
Hi,
I have nifti neuroimaging data that I want to normalise within an ROI to a zero-mean, unit-variance space.
I tried using the code below however kept on getting an error;
ROI = niftiread('CHB_train_Case01_T1_brain_mask.nii');
Raw_brain = niftiread('CHB_train_Case01_T1.nii');
ind = find(ROI==1);
mean_val = mean(Raw_brain(ind));
std_val = std(Raw_brain(ind));
Raw_brain(ind)= Raw_brain(ind)-mean_val;
Raw_brain(ind)= (Raw_brain(ind)-mean_val)/std_val;
niftiwrite(Raw_brain,'Raw_brain_normalised_T1.nii');
the error I seem to be getting is as follows;
Error using var (line 74)
Invalid data type. First input argument must be single or double.
Error in std (line 59)
y = sqrt(var(varargin{:}));
Error in untitled8 (line 5)
std_val = std(Raw_brain(ind));
Would appreciate any guidance/help
Thanks

  2 Comments

Ghazn Khan
Ghazn Khan on 18 Aug 2020
Error using var (line 74)
Invalid data type. First input argument must be single or double.
Error in std (line 59)
y = sqrt(var(varargin{:}));
Error in untitled8 (line 5)
std_val = std(Raw_brain(ind));
MATLAB can't seem to compute standard deviation

Sign in to comment.

Accepted Answer

Srivardhan Gadila
Srivardhan Gadila on 22 Aug 2020
The error is due to the conflict with data type. Input argument of the std function must be of data type single or double. As per my knowledge the output data type of the niftiread would be unsigned integer (I think unit8 specifically).
Try with the following code:
ROI = niftiread('CHB_train_Case01_T1_brain_mask.nii');
Raw_brain = niftiread('CHB_train_Case01_T1.nii');
ind = find(ROI==1);
mean_val = mean(Raw_brain(ind));
std_val = std(double(Raw_brain(ind)));

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!