Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from numpy import *
- from scipy import *
- from scipy.signal import *
- from scipy.stats import *
- from pylab import*
- ''' Funkcja obliczajaca dwt '''
- def dwt(img):
- maskL = [0.02674875741080976, -0.01686411844287795, -0.07822326652898785, 0.2668641184428723, 0.6029490182363579, 0.2668641184428723,
- -0.07822326652898785, -0.01686411844287795, 0.02674875741080976]
- maskH = [0.09127176311424948, -0.05754352622849957, -0.5912717631142470, 1.115087052456994, -0.5912717631142470, -0.05754352622849957,
- 0.09127176311424948]
- height = img.shape[0]
- width = img.shape[1]
- bandL = zeros([height,int(width/2)])
- bandH = zeros(bandL.shape)
- for r in range(0, height): #1D-DWT dla wierszy
- bandL[r,:] = convolve(img[r,:], maskL, mode='same')[::2]
- bandH[r,:] = convolve(img[r,:], maskH, mode='same')[::2]
- bandLL = zeros([int(height/2),int(width/2)])
- bandLH = zeros(bandLL.shape)
- bandHL = zeros(bandLL.shape)
- bandHH = zeros(bandLL.shape)
- for c in range(0, int(width/2)): #1D-DWT dla kolumn
- bandLL[:,c] = convolve(bandL[:,c], maskL, mode='same')[::2]
- bandLH[:,c] = convolve(bandL[:,c], maskH, mode='same')[::2]
- bandHL[:,c] = convolve(bandH[:,c], maskL, mode='same')[::2]
- bandHH[:,c] = convolve(bandH[:,c], maskH, mode='same')[::2]
- return clip(bandLL, 0.0, 1.0), bandLH, bandHL, bandHH
- ''' funkcja wyswietlajaca i zapisujaca obraz '''
- def showAndSaveImg(img, imgTitle):
- figure()
- axis('off')
- title(imgTitle)
- imshow(img, cmap = cm.gray, vmin = -1.0, vmax = 1.0)
- imsave("C:/Users/Wojtek/Documents/" + imgTitle + '.png', img, cmap = cm.gray)
- def histogram1(img, ilosc, minimum, histTitle):
- figure()
- hist(img.flatten(), ilosc, range = [minimum, 1.0])
- title('Histogram pasma ' + histTitle)
- xlabel('Wartosc piksela')
- ylabel('Ilosc wystapien')
- ''' funkcja obliczajaca entropie '''
- def entropia(img, ilosc, minimum):
- hist = histogram(img.flatten(), ilosc, range = [minimum, 1.0])[0] + sys.float_info.epsilon #utworzenie histogramu
- pstwo = hist/sum(hist)
- ent = -1.0*sum(pstwo*log2(pstwo)) #obliczenie entropii
- return ent
- obraz = imread(r"C:\Users\Wojtek\Downloads\pto_obrazytestowepng (2)\obrazyTestowe\monochrome\galera_mono.png") #wczytanie obrazu
- obrazLL, obrazLH, obrazHL, obrazHH = dwt(obraz) #wywolanie funkcji dwt
- #otworzenie i zapisanie obrazow dla wszystkich pasm
- showAndSaveImg(obrazLL, 'Pasmo LL')
- showAndSaveImg(obrazLH, 'Pasmo LH')
- showAndSaveImg(obrazHL, 'Pasmo HL')
- showAndSaveImg(obrazHH, 'Pasmo HH')
- #stworzenie histogramow dla poszczegolnych pasm
- histogram1(obrazLL, 256, 0.0, 'LL')
- histogram1(obrazLH, 511, -1.0, 'LH')
- histogram1(obrazHL, 511, -1.0, 'HL')
- histogram1(obrazHH, 511, -1.0, 'HH')
- #obliczenie entropii dla poszczegolnch pasm
- print ('Entropia dla pasma LL: ', entropia(obrazLL, 256, 0.0))
- print ('Entropia dla pasma LH: ', entropia(obrazLH, 511, -1.0))
- print ('Entropia dla pasma HL: ', entropia(obrazHL, 511, -1.0))
- print ('Entropia dla pasma HH: ', entropia(obrazHH, 511, -1.0))
- show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement