Individual MRI coordinates

Hello! I want to know what kind of coordinates are the individual MRI coordinates, SCS or MRI ?

I write the following code to get the mask of sources using the MRI coordinates, but I got the mask.nii empty, I want to know why is it, thank you!

%back to image space of Original T1
clear all;
nii2 = load_untouch_nii('sub-jimingda_T1w.nii.gz');
load('P_mri.mat');
coord2 = P_mri*1000;
R = [nii2.hdr.hist.srow_x(1:3); nii2.hdr.hist.srow_y(1:3); nii2.hdr.hist.srow_z(1:3)];
T = [nii2.hdr.hist.srow_x(4); nii2.hdr.hist.srow_y(4); nii2.hdr.hist.srow_z(4)];
Rinv = inv(R);
for i = 1:3
    coord2(:,i) = coord2(:,i) - T(i);
end;
coord2 = coord2*Rinv';
for i = 1:3
    coord2(:,i) = coord2(:,i)./nii2.hdr.dime.pixdim(i+1);
end;
sizeImg = size(nii2.img);
maskImg = zeros(sizeImg(1), sizeImg(2), sizeImg(3));
y = round(coord2);
[maskImg(y(:,1), y(:,2), y(:,3))] = 1;
nii2.img=maskImg;
save_untouch_nii(nii2,'P_mri.nii.gz');

This is the mask.nii I got:

An MRI file will be in MRI coordinates.
The SCS coordinates are obtained only when the NAS, LPA and RPA fiducials have been defined, as these fiducials give origin to the SCS axes.

Please refer to the tutorial on Coordinate systems, and the links in it, they will provide you insightful information on the topic:

We are unable to provide direct support for custom code not specifically related to Brainstorm. I'd suggest you carefully debug your code to understand each step on it and check further documentation on MRI coordinate systems

Ok, I see, thank you very much