In [ ]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [12]:
import numpy as np
import imtools
import imtools.misc
import imtools.sample_data
import imtools.image_manipulation as imma
import sed3

Get 3D data


In [13]:
datap = imtools.sample_data.generate()
data3d = datap["data3d"]
segmentation = datap["segmentation"]

print(data3d.shape, data3d.dtype)


(100, 100, 100) int64

Show every 20th slice


In [14]:
sed3.show_slices(data3d, slice_step=20)


One slice


In [15]:
plt.imshow(data3d[30,:,:])


Out[15]:
<matplotlib.image.AxesImage at 0x7f123ff55d10>

Manual crop


In [16]:
crinfo = [[10, 56], [14, 64], [39, 78]]
data3d_cropped = imma.crop(data3d, crinfo)

print(data3d.shape, data3d.dtype)
#sed3.show_slices(data3d_cropped, slice_step=20)
plt.imshow(data3d_cropped[30,:,:])


(100, 100, 100) int64
Out[16]:
<matplotlib.image.AxesImage at 0x7f123fec5fd0>

Get crinfo from labeled image


In [17]:
plt.imshow(segmentation[30,:,:])


Out[17]:
<matplotlib.image.AxesImage at 0x7f12440c3cd0>

In [18]:
crinfo_auto = imma.crinfo_from_specific_data(segmentation, 5)
crinfo_auto


Out[18]:
[[0, 99], [20, 99], [45, 99]]

In [19]:
crinfo_auto = imma.crinfo_from_specific_data(segmentation, [5])
crinfo_auto


Out[19]:
[[0, 99], [20, 99], [45, 99]]

In [20]:
crinfo_auto = imma.crinfo_from_specific_data(segmentation, [5, 5, 5])
crinfo_auto


Out[20]:
[[0, 99], [20, 99], [45, 99]]

In [21]:
data3d_cropped_auto = imma.crop(data3d, crinfo_auto)
plt.imshow(data3d_cropped_auto[30,:,:])


Out[21]:
<matplotlib.image.AxesImage at 0x7f1256b61250>

Uncrop data


In [22]:
data3d_uncropped = imma.uncrop(
    data3d_cropped_auto, 
    crinfo_auto, 
    [100, 100, 100])
plt.imshow(data3d_uncropped[30,:,:])


Out[22]:
<matplotlib.image.AxesImage at 0x7f123fdc1dd0>