2

I have 3 dicom stacks of size 512x512x133, 512x512x155 and 512x512x277. I would like to resample all the stack to make the sizes 512x512x277, 512x512x277 and 512x512x277. How to do that?

I know I can do resampling using slice thickness and pixel spacing. But that would not ensure same number of slices in each cases.

Amit Joshi
  • 15,448
  • 21
  • 77
  • 141
Avijit Dasgupta
  • 2,055
  • 3
  • 22
  • 36
  • Please don't ask duplicate questions. If your question is not getting answers, improve the question, or maybe just give it a bit more time. – beaker Jul 05 '16 at 14:55
  • 1
    Actually, what happened is that, I posted the question at night. But due to some glitch (may be) it was not showing in the morning. So, I posted it again. :( Sorry! – Avijit Dasgupta Jul 07 '16 at 15:39

2 Answers2

1

You can use scipy.ndimage.interpolate.zoom, specifying the array of zoom factors for each axis like this:

# example for first image
zoomArray = desiredshape.astype(float) / original.shape
zoomed = scipy.ndimage.interpolate.zoom(original, zoomArray)

UPDATE:

If that is too slow, you could try somehow to create separate images from the vertical slices of your "image cube", process them with some high-speed image library (some folks love ImageMagick, there's also PIL, opencv, etc.), and stack them together again. That way, you'd take 512 images of size 512x133 and resize them to 512x277, then stack again to 512x512x277 which is your final desired size. Also, this separation would allow for parallelization. One think to consider is: this would only work if the transversal axis (the one along which you will slice the 2D images) would not be resized!

heltonbiker
  • 26,657
  • 28
  • 137
  • 252
0

You can use the Resample transform in TorchIO.

import torchio as tio
small, medium, large = dicom_dirs  # the folders of your three DICOMs
reference = tio.ScalarImage(large)
resample = tio.Resample(reference)
small_resampled = resample(small)
medium_resampled = resample(medium)

The three images now have the same shape, 512 x 512 x 277.

Disclaimer: I am the main developer of TorchIO.

fepegar
  • 595
  • 5
  • 15