# NOT RUN {
# extract a vector from an image 'img' of class 'antsImage' by considering only the region starting at index (1,1,1) with size (10,10,10) ;
# here the first 10 elements of vect correspond to first column ( row = 1:10 , col = 1 , slice = 1 ) of image-region, next 10 elements come from
# second column ( row = 1:10 , col = 2 , slice = 1 ) of the image-region and so on
reg = new( "antsRegion" , index = c(1,1,1) , size = c(10,10,10) )
vect = img[ NULL , region = reg ] # OR
vect = img[ list( mask = NULL , region = reg ) ]
# set the values of pixels in the square ( row = 1:10 , col = 1:10 , slice = 3 ) using the vector c(1:100) ;
# here the first column ( row = 1:10 , col = 1 , slice = 3 ) of image gets values c(1:10), second column ( row = 1:10 , col = 2 , slice = 3 ) gets
# values c(11:20) and so on
img[ 1:10 , 1:10 , 3 ] <- c(1:100)
# }
Run the code above in your browser using DataLab