def apodize(img, napodize=10, doZ=True): """ softens the edges of a singe xy section to reduce edge artifacts and improve the fits return copy of the img """ img = img.copy() img = img.astype(N.float32) # casting rule # determine napodize shape = N.array(img.shape) // 2 napodize = N.where(shape < napodize, shape, napodize) if doZ and img.ndim >= 3 and img.shape[0] > 3: rr = range(-3, 0) else: rr = range(-2, 0) for idx in rr: fact = N.arange(1. / napodize[idx], napodize[idx], 1. / napodize[idx], dtype=N.float32)[:napodize[idx]] for napo in range(napodize[idx]): slc0 = [Ellipsis, slice(napo, napo + 1) ] + [slice(None)] * abs(idx + 1) if not napo: slc1 = [Ellipsis, slice(-(napo + 1), None) ] + [slice(None)] * abs(idx + 1) else: slc1 = [Ellipsis, slice(-(napo + 1), -(napo)) ] + [slice(None)] * abs(idx + 1) img[slc0] *= fact[napo] img[slc1] *= fact[napo] #img[slc0] = img[slc0] * fact[napo] # casting rule #img[slc1] = img[scl1] * fact[napo] return img
def apodize(img, napodize=10, doZ=True): """ softens the edges of a singe xy section to reduce edge artifacts and improve the fits return copy of the img """ img = img.copy() img = img.astype(N.float32) # casting rule # determine napodize shape = N.array(img.shape) // 2 napodize = N.where(shape < napodize, shape, napodize) if doZ and img.ndim >= 3 and img.shape[0] > 3: rr = list(range(-3,0)) else: rr = list(range(-2,0)) for idx in rr: fact = N.arange(1./napodize[idx],napodize[idx],1./napodize[idx], dtype=N.float32)[:napodize[idx]] for napo in range(napodize[idx]): slc0 = [Ellipsis,slice(napo, napo+1)] + [slice(None)] * abs(idx+1) if not napo: slc1 = [Ellipsis,slice(-(napo+1),None)] + [slice(None)] * abs(idx+1) else: slc1 = [Ellipsis,slice(-(napo+1),-(napo))] + [slice(None)] * abs(idx+1) img[slc0] *= fact[napo] img[slc1] *= fact[napo] #img[slc0] = img[slc0] * fact[napo] # casting rule #img[slc1] = img[scl1] * fact[napo] return img
def selectZsecs(self, start=0, stop=None, pattern=[1], pickWhich=1): """ stores section indices to be picked up when doing copy region pattern: smallest pattern of elements eg. [1,1,0,2] pickWich: sections corresponding this number in the pattern is picked up """ if stop is None: stop = self.cropbox_u[0] if start is None: start = self.cropbox_l[0] unit = len(pattern) idx = N.arange(self.nz) repeat = N.ceil(self.nz / float(unit)) repPat = N.tile(pattern, repeat)[:self.nz] ids = N.compress(repPat == pickWhich, idx) self._zIdx = [i for i in ids if i >= start and i < stop] if not self._zIdx: self._zIdx = [0] print self._zIdx self.cropbox_l[0] = start self.cropbox_u[0] = stop if self.cropbox_l[0] == self.cropbox_u[0]: self.cropbox_u[0] += 1 self._zPtrn = pattern self._zPick = pickWhich
def logpolar(image, center=None, angles=None, radii=None): """Return log-polar transformed image and log base.""" shape = image.shape if center is None: center = shape[0] / 2, shape[1] / 2 if angles is None: angles = shape[0] if radii is None: radii = shape[1] theta = N.zeros((angles, radii), dtype=N.float64) theta.T[:] = -N.linspace(0, N.pi, angles, endpoint=False) #d = radii d = N.hypot(shape[0] - center[0], shape[1] - center[1]) log_base = 10.0**(N.log10(d) / (radii)) radius = N.empty_like(theta) radius[:] = N.power(log_base, N.arange(radii, dtype=N.float64)) - 1.0 x = radius * N.sin(theta) + center[0] y = radius * N.cos(theta) + center[1] output = N.zeros_like(x) ndii.map_coordinates(image, [x, y], output=output) return output, log_base
def selectTimes(self, start=None, stop=None, pattern=[1], pickWhich=1): """ stores section indices to be picked up when doing copy region pattern: smallest pattern of elements eg. [1,1,0,2] pickWich: sections corresponding this number in the pattern is picked up """ if stop is None: stop = self.nt if start is None: start = 0 unit = len(pattern) idx = N.arange(self.nt) repeat = N.ceil(self.nt / float(unit)) repPat = N.tile(pattern, repeat)[:len(idx)] ids = N.compress(repPat == pickWhich, idx) self._tIdx = [i for i in ids if i >= start and i < stop] self._tPtrn = pattern self._tPick = pickWhich
def logpolar(image, center=None, angles=None, radii=None): """Return log-polar transformed image and log base.""" shape = image.shape if center is None: center = shape[0] / 2, shape[1] / 2 if angles is None: angles = shape[0] if radii is None: radii = shape[1] theta = N.zeros((angles, radii), dtype=N.float64) theta.T[:] = -N.linspace(0, N.pi, angles, endpoint=False) #d = radii d = N.hypot(shape[0]-center[0], shape[1]-center[1]) log_base = 10.0 ** (N.log10(d) / (radii)) radius = N.empty_like(theta) radius[:] = N.power(log_base, N.arange(radii, dtype=N.float64)) - 1.0 x = radius * N.sin(theta) + center[0] y = radius * N.cos(theta) + center[1] output = N.zeros_like(x) ndii.map_coordinates(image, [x, y], output=output) return output, log_base