Python scipy.ndimage.laplace() Examples
The following are 9
code examples of scipy.ndimage.laplace().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy.ndimage
, or try the search function
.
Example #1
Source File: test_ndimage.py From Computable with MIT License | 5 votes |
def test_laplace01(self): for type in [numpy.int32, numpy.float32, numpy.float64]: array = numpy.array([[3, 2, 5, 1, 4], [5, 8, 3, 7, 1], [5, 6, 9, 3, 5]], type) * 100 tmp1 = ndimage.correlate1d(array, [1, -2, 1], 0) tmp2 = ndimage.correlate1d(array, [1, -2, 1], 1) output = ndimage.laplace(array) assert_array_almost_equal(tmp1 + tmp2, output)
Example #2
Source File: test_ndimage.py From Computable with MIT License | 5 votes |
def test_laplace02(self): for type in [numpy.int32, numpy.float32, numpy.float64]: array = numpy.array([[3, 2, 5, 1, 4], [5, 8, 3, 7, 1], [5, 6, 9, 3, 5]], type) * 100 tmp1 = ndimage.correlate1d(array, [1, -2, 1], 0) tmp2 = ndimage.correlate1d(array, [1, -2, 1], 1) output = numpy.zeros(array.shape, type) ndimage.laplace(array, output=output) assert_array_almost_equal(tmp1 + tmp2, output)
Example #3
Source File: test_ndimage.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_laplace01(self): for type_ in [numpy.int32, numpy.float32, numpy.float64]: array = numpy.array([[3, 2, 5, 1, 4], [5, 8, 3, 7, 1], [5, 6, 9, 3, 5]], type_) * 100 tmp1 = ndimage.correlate1d(array, [1, -2, 1], 0) tmp2 = ndimage.correlate1d(array, [1, -2, 1], 1) output = ndimage.laplace(array) assert_array_almost_equal(tmp1 + tmp2, output)
Example #4
Source File: test_ndimage.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_laplace02(self): for type_ in [numpy.int32, numpy.float32, numpy.float64]: array = numpy.array([[3, 2, 5, 1, 4], [5, 8, 3, 7, 1], [5, 6, 9, 3, 5]], type_) * 100 tmp1 = ndimage.correlate1d(array, [1, -2, 1], 0) tmp2 = ndimage.correlate1d(array, [1, -2, 1], 1) output = numpy.zeros(array.shape, type_) ndimage.laplace(array, output=output) assert_array_almost_equal(tmp1 + tmp2, output)
Example #5
Source File: test_filters.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_multiple_modes(): # Test that the filters with multiple mode cababilities for different # dimensions give the same result as applying a single mode. arr = np.array([[1., 0., 0.], [1., 1., 0.], [0., 0., 0.]]) mode1 = 'reflect' mode2 = ['reflect', 'reflect'] assert_equal(sndi.gaussian_filter(arr, 1, mode=mode1), sndi.gaussian_filter(arr, 1, mode=mode2)) assert_equal(sndi.prewitt(arr, mode=mode1), sndi.prewitt(arr, mode=mode2)) assert_equal(sndi.sobel(arr, mode=mode1), sndi.sobel(arr, mode=mode2)) assert_equal(sndi.laplace(arr, mode=mode1), sndi.laplace(arr, mode=mode2)) assert_equal(sndi.gaussian_laplace(arr, 1, mode=mode1), sndi.gaussian_laplace(arr, 1, mode=mode2)) assert_equal(sndi.maximum_filter(arr, size=5, mode=mode1), sndi.maximum_filter(arr, size=5, mode=mode2)) assert_equal(sndi.minimum_filter(arr, size=5, mode=mode1), sndi.minimum_filter(arr, size=5, mode=mode2)) assert_equal(sndi.gaussian_gradient_magnitude(arr, 1, mode=mode1), sndi.gaussian_gradient_magnitude(arr, 1, mode=mode2)) assert_equal(sndi.uniform_filter(arr, 5, mode=mode1), sndi.uniform_filter(arr, 5, mode=mode2))
Example #6
Source File: test_filters.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_multiple_modes_laplace(): # Test laplace filter for multiple extrapolation modes arr = np.array([[1., 0., 0.], [1., 1., 0.], [0., 0., 0.]]) expected = np.array([[-2., 2., 1.], [-2., -3., 2.], [1., 1., 0.]]) modes = ['reflect', 'wrap'] assert_equal(expected, sndi.laplace(arr, mode=modes))
Example #7
Source File: plot_interactive_tree.py From scipy_2015_sklearn_tutorial with Creative Commons Zero v1.0 Universal | 5 votes |
def plot_tree(max_depth=1): fig, ax = plt.subplots(1, 2, figsize=(15, 7)) h = 0.02 x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5 y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5 xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h)) if max_depth != 0: tree = DecisionTreeClassifier(max_depth=max_depth, random_state=1).fit(X, y) Z = tree.predict_proba(np.c_[xx.ravel(), yy.ravel()])[:, 1] Z = Z.reshape(xx.shape) faces = tree.tree_.apply(np.c_[xx.ravel(), yy.ravel()].astype(np.float32)) faces = faces.reshape(xx.shape) border = ndimage.laplace(faces) != 0 ax[0].contourf(xx, yy, Z, alpha=.4) ax[0].scatter(xx[border], yy[border], marker='.', s=1) ax[0].set_title("max_depth = %d" % max_depth) ax[1].imshow(tree_image(tree)) ax[1].axis("off") else: ax[0].set_title("data set") ax[1].set_visible(False) ax[0].scatter(X[:, 0], X[:, 1], c=np.array(['b', 'r'])[y], s=60) ax[0].set_xlim(x_min, x_max) ax[0].set_ylim(y_min, y_max) ax[0].set_xticks(()) ax[0].set_yticks(())
Example #8
Source File: dftreg.py From sima with GNU General Public License v2.0 | 5 votes |
def __init__(self, upsample_factor=1, max_displacement=None, num_images_for_mean=100, randomise_frames=True, err_thresh=0.01, max_iterations=5, rotation_scaling=False, save_fmt='mptiff', save_name=None, n_processes=1, verbose=False, return_registered=False, laplace=0.0): self._params = dict(locals()) del self._params['self']
Example #9
Source File: dev_Image.py From NodeEditor with MIT License | 4 votes |
def run_FreeCAD_ImageT(self): from scipy import ndimage fn=self.getData('image') import matplotlib.image as mpimg img=mpimg.imread(fn) (sa,sb,sc)=img.shape red=0.005*(self.getData("red")+100) green=0.005*(self.getData("green")+100) blue=0.005*(self.getData("blue")+100) #blue=0 say("rgb",red,green,blue) # andere filtre #img = ndimage.sobel(img) #img = ndimage.laplace(img) im2=img[:,:,0]*red+img[:,:,1]*green+img[:,:,2]*blue im2=np.round(im2) if self.getData('invert'): im2 = 1- im2 #im2 = ndimage.sobel(im2) ss=int((self.getData('maskSize')+100)/20) say("ss",ss) if ss != 0: mode=self.getData('mode') say("mode",mode) if mode=='closing': im2=ndimage.grey_closing(im2, size=(ss,ss)) elif mode=='opening': im2=ndimage.grey_opening(im2, size=(ss,ss)) elif mode=='erosion': im2=ndimage.grey_erosion(im2, size=(ss,ss)) elif mode=='dilitation': im2=ndimage.grey_dilation(im2, footprint=np.ones((ss,ss))) else: say("NO MODE") nonzes=np.where(im2 == 0) pts = [FreeCAD.Vector(sb+-x,sa-y) for y,x in np.array(nonzes).swapaxes(0,1)] h=10 pts = [FreeCAD.Vector(sb+-x,sa-y,(red*img[y,x,0]+green*img[y,x,1]+blue*img[y,x,2])*h) for y,x in np.array(nonzes).swapaxes(0,1)] colors=[img[y,x] for y,x in np.array(nonzes).swapaxes(0,1)] say("len pts",len(pts)) self.setData("Points_out",pts)