I have 500 y slices of size 500 X 1000. I want to generate a volume of size 500,500,1000 [1000 images with size 500X500].
When I used paste filter ,i was not able to paste these slices in y direction. But I was able to paste in Z direction.
Now what I am doing is creating a volume of size (500,1000,500) and slice it again in y direction and using tile filter to stack it .
As the image are more the process is very time consuming. I know this is not the easiest way to generate the volume.
Can anyone please suggest me some better solutions.
Not sure if you’re working in ITK or SimpleITK, below is some code in SimpleITK. The filters you need to play with are JoinSeries, PasteImage, PermuteAxes and possibly setting the final images direction. The code assumes our original image is truly 2D, we use JoinSeries to make it 3D x_size,y_size,1 and then permute axes x_size, 1, z_size=y_size.
import SimpleITK as sitk
#List of file names, in our case same file ten times
file_names = ['SimpleITK.jpg']*10
#read the first file and compute our final image size
img = sitk.ReadImage(file_names)
x_size = img.GetWidth()
z_size = img.GetHeight()
y_size = len(file_names)
final_image = sitk.Image([x_size, y_size, z_size], img.GetPixelID())
for i, file_name in enumerate(file_names):
img = sitk.PermuteAxes(sitk.JoinSeries([sitk.ReadImage(file_name)]),[0,2,1])
final_image = sitk.Paste(final_image, img, [x_size, 1, z_size], [0,0,0], [0,i,0])
I am working in ITK. I will try these filters. Thank you for your help.
I tried itk::PermuteAxesImageFilter . It is working well.
Thanks a lot!!
TileImageFilter can be configured to behave similar to the
JoinSeriesImageFilter by specifying the layout as
[1,1,0]. The 0 indicates that is the axis that can be expanded, while the 1x1 is the fixed layout. By specifying the layout parameter as
[1,0,1] the images will be joined in the y-direction as desired.
Thank you @blowekamp . I tried it. It also does what i want.