-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11.erison_and_noise_method_use_to_remove_noise.py
78 lines (70 loc) · 3.2 KB
/
11.erison_and_noise_method_use_to_remove_noise.py
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
import numpy as np
from scipy import ndimage
import matplotlib.pyplot as plt
# ZERO WALA MATRIX BANAYA
a = np.zeros((5,5), dtype=np.int)
# print('\n',a)
# matix me matrix postion 11 se 13, aur same 21, 31 tak banaya
a[1:4, 1:4] = 1;
aBeforNosice = ndimage.binary_opening(a)
print('\nBefore noise print square\n\n',aBeforNosice)
# ek extra 1 add kiya gaya hai 44 postion pe
a[4, 4] = 1
# print('\n',a)
# Opening removes small objects
# yaha small object wo 44 wali postion ka 1 hai jisko remove kiya gaya hai
smallremove = ndimage.binary_opening(a, structure=np.ones((3,3))).astype(np.int)
print('\nUsing structue of 3*3 for removing 1 of 4*4 postion\n\n',smallremove)
smallremove1 = ndimage.binary_opening(smallremove).astype(np.int)
print('\nPrint with same smallremove value\n\n',smallremove)
# Opening can also smooth corners
# smooth corners means sare corner edges ko remove kar diya hai
smoothremove = ndimage.binary_opening(a).astype(np.int)
print('\nPrint Value of a including 1 at 4*4 which remove\n\n',smoothremove)
# -----------FINAL 3 RIGHT BOXEX GENERATE BY THIS AREA-------------------------------
square = np.zeros((32, 32))
square[10:-10, 10:-10] = 1
np.random.seed(2)
# random number me 2 = 2 digit random number generate, 20 = 20 random number length
x, y = (32*np.random.random((2, 20))).astype(np.int)
# print(x)
# print(y)
square[x, y] = 1
# 3 alag ndimage method ka use karke 3 alag input generate kiya gaya hai
open_square = ndimage.binary_opening(square)
eroded_square = ndimage.binary_erosion(square)
reconstruction = ndimage.binary_propagation(eroded_square, mask=square)
# -----------END RIGHT 3 BOX AREA----------------------------------------------------
# plt figure ka use output box ki size ke liye kiya gaya hai
plt.figure(figsize=(12, 5))
# subplot ka use agar 1 se jada image show karana hai to uski size aur space ke liye use hota hai.
# subplot ki value 3 digit me 111 se max honi cahiye
# agar ek sath 2 image dikhana hai to 121, 122 or 4 hai to 141,142...144
plt.subplot(151)
# iska use input ko get kar ke iske base be output generate karna hota hai
plt.imshow(smallremove, cmap=plt.cm.gray, interpolation='nearest')
# jab ek se jata image ko single output box me show karana ho ya custom axis input ho to use karte hai
plt.axis('off')
plt.title('Small Remove', fontsize=20)
plt.subplot(152)
plt.imshow(smoothremove, cmap=plt.cm.gray, interpolation='nearest')
plt.axis('off')
plt.title('Smooth Remove', fontsize=20)
# ------------3 RIHGT OUTPUT BOX SHOW KARANE KE LIYE--------------------------------
plt.subplot(153)
plt.imshow(square, cmap=plt.cm.gray, interpolation='nearest')
plt.axis('off')
plt.title('Squares', fontsize=20)
plt.subplot(154)
plt.imshow(open_square, cmap=plt.cm.gray, interpolation='nearest')
plt.axis('off')
plt.title('Open Square', fontsize=20)
plt.subplot(155)
plt.imshow(reconstruction, cmap=plt.cm.gray, interpolation='nearest')
plt.axis('off')
plt.title('Reconstruction', fontsize=20)
# ------------END 3 RIHGT OUTPUT BOX SHOW KARANE KE LIYE--------------------------------
# jab 1 se jada image show karna hota hai to unke bich me space ke liye use karte hai
plt.subplots_adjust(wspace=0, hspace=0.02, top=0.99, bottom=0.01, left=0.01, right=0.99)
# isse output ko show kiya gaya hai
plt.show()