def fitTrace(self,kwidth=10,porder=3,cwidth=30,pad=False): sh = self.sh xr1 = (0,sh[1]) xrs = [xr1] polys = [] for xr in xrs: xindex = np.arange(xr[0],xr[1]) kernel = np.median(self.image[int(sh[0]/2-kwidth):int(sh[0]/2+kwidth),xindex],0) centroids = [] totals = [] for i in np.arange(sh[0]): row = self.image[i,xindex] row_med = np.median(row) total = np.abs((row-row_med).sum()) cc = fp.ifft(fp.fft(kernel)*np.conj(fp.fft(row-row_med))) cc_sh = fp.fftshift(cc) centroid = helpers.calc_centroid(cc_sh,cwidth=cwidth).real - xindex.shape[0]/2. centroids.append(centroid) totals.append(total) centroids = np.array(centroids) yindex = np.arange(sh[0]) gsubs = np.where((np.isnan(centroids)==False)) centroids[gsubs] = median_filter(centroids[gsubs],size=20) coeffs = np.polyfit(yindex[gsubs],centroids[gsubs],porder) poly = np.poly1d(coeffs) polys.append(poly) return xrs,polys
def _findYOffsets(self): kernel = np.median(self.stack[:,:,0],1) offsets = np.empty(0) nplanes = self.stack.shape[2] for i in np.arange(nplanes): profile = np.median(self.stack[:,:,i],1) cc = fp.ifft(fp.fft(kernel)*np.conj(fp.fft(profile))) cc_sh = fp.fftshift(cc) cen = helpers.calc_centroid(cc_sh).real - self.height/2. offsets = np.append(offsets,cen) return offsets
def _findYOffsets(self): kernel = np.median(self.stack[:, :, 0], 1) offsets = np.empty(0) nplanes = self.stack.shape[2] for i in np.arange(nplanes): profile = np.median(self.stack[:, :, i], 1) cc = fp.ifft(fp.fft(kernel) * np.conj(fp.fft(profile))) cc_sh = fp.fftshift(cc) cen = helpers.calc_centroid(cc_sh).real - self.height / 2. offsets = np.append(offsets, cen) return offsets
def fitTrace(self, kwidth=10, porder=3, cwidth=30, pad=False): sh = self.sh xr1 = (0, sh[1]) xrs = [xr1] polys = [] for xr in xrs: xindex = np.arange(xr[0], xr[1]) kernel = np.median( self.image[int(sh[0] / 2 - kwidth):int(sh[0] / 2 + kwidth), xindex], 0) centroids = [] totals = [] for i in np.arange(sh[0]): row = self.image[i, xindex] row_med = np.median(row) total = np.abs((row - row_med).sum()) cc = fp.ifft(fp.fft(kernel) * np.conj(fp.fft(row - row_med))) cc_sh = fp.fftshift(cc) centroid = helpers.calc_centroid( cc_sh, cwidth=cwidth).real - xindex.shape[0] / 2. centroids.append(centroid) totals.append(total) centroids = np.array(centroids) yindex = np.arange(sh[0]) gsubs = np.where((np.isnan(centroids) == False)) centroids[gsubs] = median_filter(centroids[gsubs], size=20) coeffs = np.polyfit(yindex[gsubs], centroids[gsubs], porder) poly = np.poly1d(coeffs) polys.append(poly) return xrs, polys