Closed yinkaiming1987 closed 8 years ago
fslr (the dev version) should have fslroi
as a function.
You can pad the image, but there are many ways to do this. You can pad zeros on the left/bottom, the right/top, symmetrically on each side (but there may be asymmetry in the dimensions). You can extract the array of the nifti
object using:
arr = out@.Data
And the abind
package may be helpful. Why do you want to do this?
That's great! I need to pad zeros symmetrically on left, right, and also slices number so to make it a cubic space, then I will rotate it around the centre of this cubic, to obtain an isotropic rotation.
Could you show me some commands to to this? Also do you know how to transform a file of the voxel size e.g. 1.5 x 1.5 x 2 to 1 x 1 x 1 in fslr?
Thanks, Kaiming
On 28 March 2016 at 18:37, John Muschelli notifications@github.com wrote:
fslr (the dev version) should have fslroi as a function.
You can pad the image, but there are many ways to do this. You can pad zeros on the left/bottom, the right/top, symmetrically on each side (but there may be asymmetry in the dimensions). You can extract the array of the nifti object using:
arr = out@.Data
And the abind package may be helpful. Why do you want to do this?
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/muschellij2/fslr/issues/3#issuecomment-202500586
You need to resample the image. You can also register the image to the MNI template (1x1x1).
Here is a function that should symmetrically do this (it favors the right over the left if it's not truly symmetric)
add_zero_dimensions = function(img,
newdim,
value = NA){
dimg = dim(img)
# img[1:dimg[1], 1:dimg[2], c(1:7, 36:29)] = 0
# img[1:dimg[1], c(1:7, 512:505), 1:dimg[3]] = 0
# img[c(1:7, 512:505), 1:dimg[2], 1:dimg[3]] = 0
stopifnot(length(dimg) == length(newdim))
stopifnot(all(newdim > 0))
diff_dim = newdim - dimg
stopifnot(all(diff_dim >= 0))
arr = array(value, dim = newdim)
inds = list()
idim = 1
for (idim in seq_along(dimg)){
adder = diff_dim[idim]
left = floor(adder/2)
right = adder - left
top = newdim[idim]
ind = seq(left + 1, top - right)
# stopifnot(length(ind) == dz)
inds[[idim]] = ind
}
arr[inds[[1]], inds[[2]], inds[[3]]] = img
arr = copyNIfTIHeader(img, arr)
return(arr)
}
You should read the documents on the FSL website. I'm closing this as this is more of how to do an analysis pipeline than issue with the package.
Thanks John,
Continue to the last question, I have a nifti file in the end. Great! I checked the path /usr/bin which has all just fsl symlinks in the format of fsl5.0-aff2rigid, and the path /usr/share/fsl/5.0 has folders as:
~$ cd /usr/share/fsl/5.0/ 5.0$ ls bin data doc etc tcl 5.0$ ls -l total 20 lrwxrwxrwx 1 root root 20 Aug 24 2013 bin -> ../../../lib/fsl/5.0 lrwxrwxrwx 1 root root 7 Aug 24 2013 data -> ../data drwxr-xr-x 6 root root 4096 Oct 22 23:02 doc drwxr-xr-x 8 root root 4096 Oct 22 23:02 etc drwxr-xr-x 3 root root 12288 Oct 22 23:02 tcl
Now I have two more questions (unrelated to the above):
1) Does fslr package have function like fslroi? Or could I perform this in other ways?
2) If I have a nifti file in dims of 170 x 240 x 240, could I use fslr package to pad it into a cubic file in dims of 240 x 240 x 240? Or do you know if there are other ways to do this?
Great thank, Kaiming