def run(self): if self.ui.DCTButton.isChecked(): DCT.DCT1(self.path()) if self.ui.DFTButton.isChecked(): DFT.DFT1(self.path()) if self.ui.zhifangButton.isChecked(): histogram_equalization.his_eq(self.path()) if self.ui.noseButton.isChecked(): nose.addnoise(self.path()) if self.ui.grayButton.isChecked(): gray.gray1(self.path()) if self.ui.buguize.isChecked(): buguize.buguize(self.path()) if self.ui.duishu.isChecked(): buguize.buguize(self.path()) if self.ui.gamma.isChecked(): gamma.gamma(self.path()) if self.ui.junzhi.isChecked(): junzhi.junzhi(self.path()) if self.ui.face.isChecked(): test_face3.face(self.path()) if self.ui.fenge.isChecked(): test_fenge.fenge(self.path()) if self.ui.kuang.isChecked(): test_kuang.kuang(self.path())
def u_prime(ux, uy, uz, v): c = 299792458 #Define speed of light in m/s. ux *= c uy *= c uz *= c v *= c ux_prime = (ux - v) / (1 - ux * v / c**2) uy_prime = uy / (gamma(v) * (1 - ux * v / c**2)) uz_prime = uz / (gamma(v) * (1 - ux * v / c**2)) return ux_prime / c, uy_prime / c, uz_prime / c
def _EM_iterate_once(self, data): N = len(data) K = self.nclasses gamma_K_N = numpy.empty((K, N)) sigma_matrix = numpy.zeros((K, self.dim, self.dim)) for k in range(K): sigma_matrix[k] = numpy.diag(self.sigma[k]) for n in range(N): gamma_K_N[:, n] = gamma(data[n], self.pi, self.mu, sigma_matrix)[1] gamma_sum_K = numpy.sum(gamma_K_N, axis=1) pi_new = 1. / N * gamma_sum_K mu_new = numpy.dot(numpy.matrix(gamma_K_N), numpy.matrix(data)) for i in range(K): mu_new[i, :] /= gamma_sum_K[i] sigma_new = numpy.zeros((K, self.dim)) for i in range(K): for n in range(N): x_temp = numpy.matrix(data[n].reshape(self.dim, 1)) - mu_new[i, :] sigma_new[i] += gamma_K_N[i][n] * numpy.diag( x_temp * x_temp.transpose()) sigma_new[i] /= gamma_sum_K[i] self.pi = pi_new self.mu = mu_new self.sigma = sigma_new
def to_led(path=None, n_led=50, n_ang=32): img = mpimg.imread(path) # Levanta la imagen wx, wy, dim = img.shape # Me da las dimensiones del frame en pixeles center_x = int( (wx - 1) / 2) # Calcula la cordenada x del centro de la imagen center_y = int( (wy - 1) / 2) # Calcula la cordenada y del centro de la imagen rad = min( center_x, center_y) # Calcula el radio que barre la imagen dentro del frame led = [] intensidad = [int(31 * i**2 / n_led**2) for i in range(n_led)] for m in range(0, n_ang): for n in range(0, n_led): x = center_x + int(rad * (n + 1) / n_led * cos(m * 2 * pi / n_ang)) y = center_y + int(rad * (n + 1) / n_led * sin(m * 2 * pi / n_ang)) tupla = tuple(gamma(int(255 * g)) for g in img[x, y, 0:3]) + (intensidad[n], ) led.append(pack('BBBB', *tupla)) return b''.join(led)
def _compute_statistics(self, data): ndata = len(data) gamma_K_N = numpy.empty((self.nclasses, ndata)) sigma_matrix = numpy.zeros((self.nclasses, self.dim, self.dim)) for k in range(self.nclasses): sigma_matrix[k] = numpy.diag(self.sigma[k]) for t in range(ndata): gamma_K_N[:, t] = gamma(data[t], self.pi, self.mu, sigma_matrix)[1] self.stat0 = numpy.sum(gamma_K_N, axis=1) self.stat1 = numpy.array(numpy.matrix(gamma_K_N) * numpy.matrix(data)) self.stat2 = numpy.array( numpy.matrix(gamma_K_N) * numpy.matrix([[i * j for i, j in zip(*row)] for row in zip(data, data)]))
from gamma import gamma import numpy as np from matplotlib import pyplot as plt k = 4.551 gam = gamma(k/2, 0.00000001) def chi2(x): """ Calcula la funcion Chi^2 usando la funcion gamma calculada arriba y k=4.551 Params: :param x: el valor para el que se calculara chi """ denom = 2**(k/2) * gam return x**((k/2-1)) * np.exp(-x/2) * (1/denom) x=np.linspace(0,25, 100) plt.plot(x, chi2(x)) plt.xlabel("x", fontsize=16) plt.ylabel("$\chi ^2(x)$", fontsize=16) plt.show()
imsave('I0.png', I0) imsave('I1.png', I1) # create D1 import dehaze1 I2 = imread("D1.png") # create D2 import dehaze2 I3 = imread("D2.png") # gamma im = cv2.imread("D2.png") G1 = gamma.gamma(im) I4 = cv2.imread("G1.png") #I0 = cv2.imread("I0.png") imsave('I0/' + imgName + 'I0.png', I0) imsave('I1/' + imgName + 'I1.png', I1) imsave('I2/' + imgName + 'I2.png', I2) imsave('I3/' + imgName + 'I3.png', I3) imsave('I4/' + imgName + 'I4.png', G1) #PSNR&MAE print('PSNR I0-I2 :', cv2.PSNR(I0, I2)) print('PSNR I0-I3 :', cv2.PSNR(I0, I3)) print('PSNR I0-I4 :', cv2.PSNR(I0, I4)) #MAE