Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resizing a 3D image (and resampling)

I have 3D image of a brain (let's call it flash) and it's currently 263 x 256 x 185. I want to resize it to be the size of another image(call it whole_brain_bravo); 256 x 256 x 176, and (hopefully) use a lanczos interpolation to resample (Image.ANTIALIAS). My (failed) attempt:

from scipy import ndimage as nd
import nibabel as nib
import numpy as np



a = nib.load('flash.hdr') # nib is what I use to load the images
b = nib.load('whole_brain_bravo.hdr')

flash = a.get_data() # Access data as array (in this case memmap)
whole = b.get_data()

downed = nd.interpolation.zoom(flash, zoom=b.shape) # This obviously doesn't work

Have you guys ever done this sort of thing on a 3D image?

like image 278
faskiat Avatar asked Aug 22 '13 16:08

faskiat


People also ask

What is the difference between resampling and resizing an image?

Summary. Image resizing keeps the number of pixels in your image the same and affects only how large your image will print (the Document Size). Image resampling physically changes the number of pixels in your image (the Pixel Dimensions).

What happens to an image if you resize it with resampling selected?

Resizing and resampling images Resampling changes the total number of pixels in the image, which are displayed as Width and Height in pixels in the Image Size dialog. When you increase the number of pixels in this part of the dialog box (upsampling), the application adds data to the image.

What is resizing and resampling?

resizing means changing a size of an image without changing the number of pixels. resampling means changing the number of pixels. this will affect the quality of your image.

What is the difference between resizing and resampling in Photoshop?

When keeping the number of pixels in the image the same and changing the size at which the image will print, that's known as resizing. If physically changing the number of pixels in the image, it is called resampling.


1 Answers

From the docstring for scipy.ndimage.interpolate.zoom:

"""
zoom : float or sequence, optional
    The zoom factor along the axes. If a float, `zoom` is the same for each
    axis. If a sequence, `zoom` should contain one value for each axis.
"""

What is the scale factor between the two images? Is it constant across all axes (i.e. are you scaling isometrically)? In that case zoom should be a single float value. Otherwise it should be a sequence of floats, one per axis.

For example, if the physical dimensions of whole and flash can be assumed to be equal, then you could do something like this:

 dsfactor = [w/float(f) for w,f in zip(whole.shape, flash.shape)]
 downed = nd.interpolation.zoom(flash, zoom=dsfactor)
like image 115
ali_m Avatar answered Sep 30 '22 17:09

ali_m