In [10]:
import sys
import os
print(sys.version)
print(os.getcwd())
import tensorflow as tf
print(tf.VERSION)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
import cv2
print(cv2)
In [2]:
import h5py
from skimage import measure, morphology
import numpy as np
import scipy.ndimage as ndimage
import matplotlib.pyplot as plt
n = 10
l = 256
im = np.zeros((l, l))
np.random.seed(1)
points = l*np.random.random((2, n**2))
im[(points[0]).astype(np.int), (points[1]).astype(np.int)] = 1
im = ndimage.gaussian_filter(im, sigma=l/(4.*n))
mask = (im > im.mean()).astype(np.float)
mask += 0.1 * im
img = mask + 0.2*np.random.randn(*mask.shape)
hist, bin_edges = np.histogram(img, bins=60)
bin_centers = 0.5*(bin_edges[:-1] + bin_edges[1:])
binary_img = img > 0.5
plt.imshow(binary_img)
plt.show()
# Remove small white regions
open_img = ndimage.binary_opening(binary_img)
plt.imshow(open_img)
plt.show()
# Remove small black hole
close_img = ndimage.binary_closing(open_img)
plt.imshow(close_img)
plt.show()
labels = measure.label(close_img)
plt.imshow(labels)
plt.show()
loc = ndimage.find_objects(labels)
print(loc)
In [3]:
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
fig = plt.figure()
ax = Axes3D(fig)
x = [0,1,1,0]
y = [0,0,1,1]
z = [0,1,0,1]
verts = list(zip(x, y, z))
poly = Poly3DCollection([verts])
poly.set_alpha(0.2)
ax.autoscale()
ax.add_collection3d(poly)
plt.show()
In [4]:
import matplotlib.pyplot as plt
import matplotlib.patches as patches
import scipy.ndimage as ndimage
# im = np.asarray([[[0,0 ,1,1],[0,0,1,0],[0,0,1,0],[0,142,1,0]],
# [[0,212,1,0],[0,0,1,0],[0,0,1,0],[0,242,1,0]],
# [[0,312,1,0],[0,0,1,0],[0,0,1,0],[0,342,1,0]]])
im = np.asarray([[0,0,0,0,0,0,0],
[0,0,1,1,1,1,0],
[0,1,1,1,1,1,0],
[0,1,1,1,1,1,0],
[0,1,1,1,1,1,0],
[0,1,1,1,1,1,0],
[0,1,1,1,1,1,0],
[0,1,1,1,1,1,0],
[0,0,0,0,0,0,0]])
fig1, ax1 = plt.subplots(1)
ax1.imshow(im, cmap=plt.cm.gray)
ax1.scatter(3, 3)
ax1.add_patch(patches.Rectangle((0,0),4,4,linewidth=1,edgecolor='r',facecolor='none'))
plt.show()
In [5]:
from scipy.ndimage.interpolation import shift
import numpy as np
arrayToShift = np.reshape([i for i in range(27)],(3,3,3))
print('Before shift')
print(arrayToShift)
shiftVector = (0,0,0)
shiftedarray = shift(arrayToShift,shift=shiftVector,mode='wrap')
print('After shift')
print(shiftedarray)
In [6]:
t = np.arange(0.01, 5.0, 0.01)
s1 = np.sin(2*np.pi*t)
s2 = np.exp(-t)
s3 = np.sin(4*np.pi*t)
ax1 = plt.subplot(311)
plt.plot(t, s1)
plt.setp(ax1.get_xticklabels(), fontsize=6)
# share x only
ax2 = plt.subplot(312, sharex=ax1)
plt.plot(t, s2)
# make these tick labels invisible
plt.setp(ax2.get_xticklabels(), visible=False)
# share x and y
ax3 = plt.subplot(313, sharex=ax1, sharey=ax1)
plt.plot(t, s3)
plt.xlim(0.01, 5.0)
plt.show()
In [ ]: