• API
• FAQ
• Tools
• Archive
daily pastebin goal
30%
SHARE
TWEET

# Untitled

a guest May 16th, 2018 86 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # -*- coding: utf-8 -*-
2. """
3. Created on Wed May 16 13:44:06 2018
4.
5. @author: Olejnik
6. """
7. #import os
8. #import numpy as np
9. #import matplotlib.image as img
10. #import matplotlib.pyplot as plt
11. #from scipy import misc as mc
12. #
13. #a = np.array([[1,1,1],[2,2,2],[2,3,1]])
14. #b = np.array([[1,1,1],[2,2,2],[2,3,2]])
15. #
16. #c = np.multiply(a,b)
17. #print(c)
18.
19. # -*- coding: utf-8 -*-
20. """
21. Created on Sun May 13 21:08:02 2018
22.
23. @author: Olejnik
24. """
25. import os
26. import numpy as np
27. import matplotlib.image as img
28. import matplotlib.pyplot as plt
29. from scipy import misc as mc
30.
31.
32. os.chdir('C:\Users\olejn\Desktop\WI\Semestr4\Przetwarzanie obrazu\laboratorium\lab3')
34.
35.
37.     #rozmiar maski shape[0] - wiersz, shape[1] - kolumna
40.     w_obr = obr.shape[0]
41.     h_obr = obr.shape[1]
42.     obr2 = obr.copy()
43.     newobr=np.zeros((h_obr,w_obr))
44.     norma = np.sum(mask)
45.     if norma == 0:
46.         norma = 1
47.     for x in range (0, w_obr-3):
48.         for y in range (0, h_obr-3):
50.             dodane = np.sum(wymnozone)
51.             piksel = dodane/norma
52.             newobr[y,x] = piksel
53.     return newobr
54.
55.
56. def ffilter(obr, mask):
57.     ileMasek = mask.shape[0]
58.     out = np.zeros(obr.shape)
59.     for i in range(0, ileMasek):
60.         out = out + np.abs(fmask(obr.copy(), mask[i, :, :]))
61.     out = np.abs(out /ileMasek)
62.     return out
63.
64. def wyswietl(obrOrg, obr, title):
65.     plt.subplot(1,2,1)
66.     plt.imshow(obrOrg, cmap=plt.cm.gray, vmin=0, vmax=255, aspect='auto')
67.     plt.title('Oryginal')
68.     plt.subplot(1,2,2)
69.     plt.imshow(obr, cmap=plt.cm.gray, vmin=0, vmax=255, aspect='auto')
70.     plt.title(title)
71.     plt.show()
72.
73. #filtry krawędziowe
74. def fRobertsa(obr):
81.     obr2 = ffilter(obr,mask)
82.     return obr2
83.
84. def fLaplacea(obr):
88.     obr2 = ffilter(obr,mask)
89.     return obr2
90.
91. def fPrewitta(obr):
97.     obr2 = ffilter(obr,mask)
98.     return obr2
99.
100. def fSobela(obr):
106.     obr2 = ffilter(obr,mask)
107.     return obr2
108. #dokonczyc
109. def fKirscha(obr):
119.     obr2 = ffilter(obr,mask)
120.     return obr2
121. #
122. obr = mc.imread('lab3.png')[:,:,0]
123. plt.title('Oryginal')
124. obr2=obr.copy()
125. obr2 = fRobertsa(obr)
126. wyswietl(obr, obr2, 'Roberts')
127. obr2 = fLaplacea(obr)
128. wyswietl(obr, obr2, 'Laplace')
129. obr2 = fPrewitta(obr)
130. wyswietl(obr, obr2, 'Prewitt')
131. obr2 = fSobela(obr)
132. wyswietl(obr, obr2, 'Soel')
133. obr2 = fKirscha(obr)
134. wyswietl(obr, obr2, 'Kirsch')
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top