-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdilation_erosion_DeepLearning.py
More file actions
87 lines (68 loc) · 2.21 KB
/
Copy pathdilation_erosion_DeepLearning.py
File metadata and controls
87 lines (68 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# -*- coding: utf-8 -*-
"""Dilation_Erosion.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1-qsQq1KaixXM6-adv9JV4IcSFoPpTM0G
# Example of Morpholophy Operations with Deep Learning
Morphological Layers for Keras/Tensorflow2 (reference : https://github.com/Jacobiano/morpholayers)
"""
# Commented out IPython magic to ensure Python compatibility.
import tensorflow
import numpy as np
import matplotlib.pyplot as plt
# %matplotlib inline
plt.rc('font', family='serif')
plt.rc('xtick', labelsize='x-small')
plt.rc('ytick', labelsize='x-small')
import skimage
print('TensorFlow version:',tensorflow.__version__)
print('Numpy version:',np.__version__)
print('Skimage version:',skimage.__version__)
!pip install tensorflow==2.2.0
!pip install numpy==1.18.1
!git clone https://github.com/Jacobiano/morpholayers.git
from morpholayers import *
from morpholayers.layers import Dilation2D,Erosion2D
from imageio import imread
from tensorflow.keras.layers import Input,Lambda
from tensorflow.keras.models import Model
!wget http://cdn.shopify.com/s/files/1/0035/2754/0782/articles/International_Flower_Day_1200x1200.jpeg?v=1579365491
I=imread('11.jpg')*1.
plt.gray()
#plt.figure(figsize=(6,6))
#plt.imshow(I[:,:,0])
#plt.show()
I=(I[:,:,0:1]>130)
print(I.shape)
size_im=I.shape
plt.figure(figsize=(6,6))
plt.imshow(I[:,:,0])
plt.show()
InLayer=Input(size_im)
x=Dilation2D(1,kernel_size=(7,7),kernel_initializer='zeros')(InLayer)
model=Model(InLayer,x)
model.summary()
!mv 14.jpg /content/img
Z=model.predict(np.expand_dims(I,axis=0))
plt.figure(figsize=(6,6))
plt.title('Dilation')
plt.imshow(Z[0,:,:,0]/255)
plt.show()
for se in range(3,10,2):
InLayer=Input(size_im)
x=Dilation2D(1,kernel_size=(se,se))(InLayer)
model=Model(InLayer,x)
Z=model.predict(np.expand_dims(I,axis=0))
plt.figure(figsize=(6,6))
plt.title('Dilation with a square of side '+str(se))
plt.imshow(Z[0,:,:,0]/255)
plt.show()
InLayer=Input(size_im)
x=Erosion2D(1,kernel_size=(5,5),kernel_initializer='zeros')(InLayer)
model=Model(InLayer,x)
model.summary()
Z=model.predict(np.expand_dims(I,axis=0))
plt.figure(figsize=(6,6))
plt.title('Dilation')
plt.imshow(Z[0,:,:,0]/255)
plt.show()