fnm = 't1_icbm_normal_1mm_pn3_rf20.rawb'; dim = [181 217 181]; mat = [1 0 0 -91; 0 1 0 -127; 0 0 1 -73; 0 0 0 1]; fid = fopen(fnm); data = fread(fid, prod(dim), 'uint8'); img = reshape(data, dim); V = struct('fname', 'bw1.img',... 'dim', dim,... 'mat', mat,... 'pinfo', [1;0;0],... 'dt', [spm_type('uint8') spm_platform('BigEnd')],... 'n', [1 1]... ); spm_write_vol(V, img);