save cluster image with given dimensions

96 views
Skip to first unread message

Tian Lin

unread,
Feb 13, 2019, 2:56:19 PM2/13/19
to xjView discuss group
Hi,

I would like to save a cluster as mask for my future use. I used the save current image as mask function and got the mask nii file. However, I noticed that the dimension of this mask file is 74 X 92 X 78, which is different to the original image file as 91 X 109 X 91. This inconsistency makes me cannot use the Rest toolbox to extract data from the images by using created mask file.

I am wondering if there is a way that I can save the mask image with the same dimensions used in the original images.

Thank you very much,

Tian

Xiaowei Song

unread,
Feb 13, 2019, 11:55:55 PM2/13/19
to xjview-dis...@googlegroups.com, 崔旭
Hi, Tian,

1. I tried the example2.img from xjView and I found the saved mask has same dimension as example2.img. I cannot repeat your error.

2. I am also pretty sure that REST SliceViewer can save clusters to mask, or some specified cluster (after you clicked a cluster) to a mask file since I wrote the code 10 years ago. You can try this way too.

3. REST toolkit has a reslice option which can change the dimension or voxel size of mask to any size you want. Thus you need not worry. If you like coding, I also have some codes I wrote 10 years ago to do the resampling using native Matlab code (i.e., no dependency of SPM or any other packages): http://restfmri.net/forum/node/78,
"mask_DownSampled=mask(1:3:181, 1:3:217, 1:3:181);" means get one value every three values. This is down sampled very simply because it happened to be the 1/3 size of the original size. In your case, you should not only change the write function because the key is the resample code not the save code. I just wrote a resample script (should be placed in the REST dir) to do the job. So the work maybe as:
 
 
mask=rest_readfile('YOUR MASK FILE PATH');
mask_DownSampled=rest_reSample3D(mask, [53,63,46]);
rest_writefile(mask_DownSampled, 'FULL PATH WHERE YOU WANT TO SAVE YOUR RESAMPLED MASK', [53,63,46],[YOUR VOXEL SIZE], [YOUR ORIGIN],  'double');
 function Result=rest_reSample3D(A3DBrain, ANewDimension)
%Resample 3D matrix, such as in REST mask resampling operation
%-----------------------------------------------------------
%	Copyright(c) 2007~2010
%	State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
%	Written by Xiao-Wei Song
%	http://resting-fmri.sourceforge.net
% Mail to Author: Xiaowei Song (dawnwei.song @ gmail.com)
%	Version=1.0 %	Release=20080801
%-----------------------------------------------------------
[dim1,dim2,dim3]=size(A3DBrain);
theFactor = ANewDimension./size(A3DBrain);
theInterpolant={'cubic','cubic','cubic'};
thePadMethod='fill';
theResampleStruct = makeresampler(theInterpolant, thePadMethod);
theTransFormStruct= maketform('affine', [theFactor(1) 0 0 ; 0 theFactor(2) 0; 0 0 theFactor(3);0 0 0]);
Result = tformarray(A3DBrain,theTransFormStruct,theResampleStruct,[1 2 3],[1 2 3],ANewDimension,[],[]);

--
You received this message because you are subscribed to the Google Groups "xjView discuss group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xjview-discuss-g...@googlegroups.com.
To post to this group, send email to xjview-dis...@googlegroups.com.
Visit this group at https://groups.google.com/group/xjview-discuss-group.
For more options, visit https://groups.google.com/d/optout.


--
Best,
Xiaowei Song 
Reply all
Reply to author
Forward
0 new messages