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

6 views (last 30 days)
Ghazn Khan on 18 Aug 2020
Commented: Ghazn Khan on 25 Aug 2020
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;
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

KALYAN ACHARJYA on 18 Aug 2020
....however kept on getting an error;...
Which line error?
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

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:
ind = find(ROI==1);
mean_val = mean(Raw_brain(ind));
std_val = std(double(Raw_brain(ind)));

#### 1 Comment

Ghazn Khan on 25 Aug 2020
Hi,
I noticed that the output .nii file was flipped? Any reason for this?