python - What is dimension order of numpy shape for image data? -
i using nibabel
lib load data nii file. read document of lib @ http://nipy.org/nibabel/gettingstarted.html, , found that
this information available without need load of main image data memory. of course there access image data numpy array
this code load data , shapes
import nibabel nib img = nib.load('example.nii') data = img.get_data() data = np.squeeze(data) data = np.copy(data, order="c") print data.shape
i got result
128, 128, 64
what order of data shape? widthxheightxdepth
? , input must arranged depth, height, width
. use input=data.transpose(2,0,1)
. right? all
update: found numpy read image order height x width x depth
reference http://www.python-course.eu/images/axis.jpeg
ok, here's take:
using scipy.ndimage.imread('img.jpg', mode='rgb')
, resulting array have order: (h, w, d)
i.e. (height, width, depth) because of terminology numpy uses ndarrays (axis=0, axis=1, axis=2)
or analogously (y, x, z)
if 1 visualize in 3 dimensions.
# read image in [21]: img = scipy.ndimage.imread('suza.jpg', mode='rgb') # image shape (h, w, d) in [22]: img.shape out[22]: (634, 1366, 3) # transpose shape (d, h, w) in [23]: tr_img = img.transpose((-1, 0, 1)) in [23]: tr_img.shape out[23]: (3, 634, 1366)
if consider img_shape tuple,
# index (0, 1, 2) img_shape = (634, 1366, 3) # or index (-3, -2, -1)
choose 1 convenient way remember.
ps: should noted libraries tensorflow (almost) follows same convention numpy.
tf.image_decode_jpeg() returns:
a tensor of type uint8. 3-d shape
[height, width, channels]
Comments
Post a Comment