def __init__( self, huefile, saturationfile, valuefile, huemin, saturationmin, valuemin, huemax, saturationmax, valuemax, gamma=1.0, bb=[0, 0, -1, -1], ): self.hdata = FitsData(huefile, bb) self.sdata = FitsData(saturationfile, bb) self.vdata = FitsData(valuefile, bb) # use the original data to calculate the RGB values hue = (numarray.ravel(self.hue.hdata) - huemin) / (huemax - huemin) hue = (numarray.ravel(self.hue.hdata) - huemin) / (huemax - huemin) hue = (numarray.ravel(self.hue.hdata) - huemin) / (huemax - huemin) self.red = MyImage.__init__(self, "L", self.hdata.size) self.green = MyImage.__init__(self, "L", self.hdata.size) self.blue = MyImage.__init__(self, "L", self.hdata.size) MyImage.__init__(self, "RGB", self.hdata.size) self.im.putband(self.hue.im, 0) self.im.putband(self.saturation.im, 1) self.im.putband(self.value.im, 2)
def get_optic_flow(im0,im1,pix,wnd,dt): """ Compute optic flow at pixel location Inputs: im0 -- image 0 im1 -- image 1 pix -- pixel locations wnd -- computation window dt -- time step between images """ # Get index location of pixel i0,i1 = pix[1], pix[0] # Get regions for optic flow calculation E1_w_bndry = im1[i0-wnd-2:i0+wnd+3,i1-wnd-2:i1+wnd+3] E0 = im0[i0-wnd:i0+wnd+1,i1-wnd:i1+wnd+1] # Cast to Float for computation E1_w_bndry = nx.asarray(E1_w_bndry, nx.Float32) E0 = nx.asarray(E0, nx.Float32) E1 = E1_w_bndry[2:-2,2:-2] # Gaussian Filter #std = 1.5 #E1_w_bndry = gaussian_filter(E1_w_bndry,std) #E1 = E1_w_bndry[2:-2,2:-2] #E0 = gaussian_filter(E0, std) # Get time derivatives dE_dt = (E1-E0)/dt # Get spacial derivatives Ex_w_bndry, Ey_w_bndry = lsq_deriv(E1_w_bndry) Ex = Ex_w_bndry[2:-2,2:-2] Ey = Ey_w_bndry[2:-2,2:-2] # Create Problem matrices n = 2*wnd+1 A = nx.concatenate((nx.ravel(Ex)[:,None], nx.ravel(Ey)[:,None]), axis=1) b = -nx.ravel(dE_dt) ## Solution method 1 (fastest?) ------------------------ #At = nx.transpose(A) #AtA = nx.matrixmultiply(At,A) #Atb = nx.matrixmultiply(At,b) #try: # x = solve(AtA,Atb) #except: # x = nx.array([0.0,0.0]) # Solution method 2 ------------------------------------ # New method x,resids,rank,s = scipy.linalg.lstsq(A,b) return x[0], x[1]
def get_optic_flow(im0, im1, pix, wnd, dt): """ Compute optic flow at pixel location Inputs: im0 -- image 0 im1 -- image 1 pix -- pixel locations wnd -- computation window dt -- time step between images """ # Get index location of pixel i0, i1 = pix[1], pix[0] # Get regions for optic flow calculation E1_w_bndry = im1[i0 - wnd - 2:i0 + wnd + 3, i1 - wnd - 2:i1 + wnd + 3] E0 = im0[i0 - wnd:i0 + wnd + 1, i1 - wnd:i1 + wnd + 1] # Cast to Float for computation E1_w_bndry = nx.asarray(E1_w_bndry, nx.Float32) E0 = nx.asarray(E0, nx.Float32) E1 = E1_w_bndry[2:-2, 2:-2] # Gaussian Filter #std = 1.5 #E1_w_bndry = gaussian_filter(E1_w_bndry,std) #E1 = E1_w_bndry[2:-2,2:-2] #E0 = gaussian_filter(E0, std) # Get time derivatives dE_dt = (E1 - E0) / dt # Get spacial derivatives Ex_w_bndry, Ey_w_bndry = lsq_deriv(E1_w_bndry) Ex = Ex_w_bndry[2:-2, 2:-2] Ey = Ey_w_bndry[2:-2, 2:-2] # Create Problem matrices n = 2 * wnd + 1 A = nx.concatenate((nx.ravel(Ex)[:, None], nx.ravel(Ey)[:, None]), axis=1) b = -nx.ravel(dE_dt) ## Solution method 1 (fastest?) ------------------------ #At = nx.transpose(A) #AtA = nx.matrixmultiply(At,A) #Atb = nx.matrixmultiply(At,b) #try: # x = solve(AtA,Atb) #except: # x = nx.array([0.0,0.0]) # Solution method 2 ------------------------------------ # New method x, resids, rank, s = scipy.linalg.lstsq(A, b) return x[0], x[1]
def __init__(self, file1, file2, fmin, fmax, gamma=1.0, bb=[0, 0, -1, -1], minquality=1.0): self.numerator = FitsData(file1, bb) self.denominator = FitsData(file2, bb) self.size = self.numerator.size if self.size != self.denominator.size: raise IndexError, "Incompatible sizes in RatioImage!" MyImage.__init__(self, "L", self.size) if self.ratiofunc == None: self.fitsdata = self.numerator.fitsdata / self.denominator.fitsdata else: self.fitsdata = self.ratiofunc(self.numerator.fitsdata, self.denominator.fitsdata) self.flatnormaldata = (numarray.ravel(self.fitsdata) - fmin) / (fmax - fmin) self.flatnormaldata = numarray.clip(self.flatnormaldata, 0.0, 1.0) if gamma != 1.0: self.flatnormaldata = self.flatnormaldata ** (1.0 / gamma) self.putdata(self.flatnormaldata, scale=255.0) self.quality = numarray.where(self.denominator.fitsdata > minquality, 1, 0) self.quality = numarray.where(self.numerator.fitsdata > minquality, self.quality, 0) self.alpha = Image.new("L", self.size) self.alpha.putdata(numarray.ravel(self.quality), scale=255) self.im = Image.composite(self, Image.new("L", self.size, 255), self.alpha).im
def __init__(self, fitsfile, fmin, fmax, gamma=1.0, bb=[0, 0, -1, -1], icut=None, cutaxis=1, takelog=0): FitsData.__init__(self, fitsfile, bb, icut, cutaxis) MyImage.__init__(self, "L", self.size) # 06 Dec 2010: add new attributes: min, max to allow outside inspection # 05 Dec 2010: If fmin or fmax is None, then the respective limit is found from the data self.min = fmin if not fmin is None else self.fitsdata.min() self.max = fmax if not fmax is None else self.fitsdata.max() if takelog: self.flatnormaldata = (numarray.ravel(numarray.log10(self.fitsdata)) - numarray.log10(self.min)) / ( numarray.log10(self.max) - numarray.log10(self.min) ) else: self.flatnormaldata = (numarray.ravel(self.fitsdata) - self.min) / (self.max - self.min) # 09 Sep 2005: How on earth did this ever work before? It is necessary # to clip fitsdata to [fmin,fmax] before applying gamma correction, or # else we get sqrt of negative numbers.... # Aha, there is a smart way to do this! self.flatnormaldata = numarray.clip(self.flatnormaldata, 0.0, 1.0) if gamma != 1.0: self.flatnormaldata = self.flatnormaldata ** (1.0 / gamma) self.putdata(self.flatnormaldata, scale=255.0)
def numarray_to_cvx(*args): """Returns CVX matrices from NumArray matrices Note that NumArray one-dimensional arrays are transformed as row vectors in CVX. See/Run test_numarray_cvx_conversions() for details. """ matrices = [] for a in args: a = numarray_asmatrix(a) m, n = a.shape a = numarray.ravel( numarray.transpose(a) ) matrices.append( cvx.matrix(a, (m,n), 'd') ) if len(matrices)==1: return matrices[0] return matrices
def numarray_to_cvx(*args): """Returns CVX matrices from NumArray matrices Note that NumArray one-dimensional arrays are transformed as row vectors in CVX. See/Run test_numarray_cvx_conversions() for details. """ matrices = [] for a in args: a = numarray_asmatrix(a) m, n = a.shape a = numarray.ravel(numarray.transpose(a)) matrices.append(cvx.matrix(a, (m, n), 'd')) if len(matrices) == 1: return matrices[0] return matrices