def _initial_blur(self): """ Blur the original image to achieve the requested level of blur init_sigma """ if self.init_sigma > self.cur_sigma: sigma = sqrt(self.init_sigma * self.init_sigma - self.cur_sigma * self.cur_sigma) self.data = gaussian_filter(self.raw, sigma) else: self.data = self.raw
def _one_octave(self, shrink=True, do_SG4=True, n_5=False): """ Return the blob coordinates for an octave @param shrink: perform the image shrinking after the octave processing @param do_SG4: perform Savitsky-Golay 4th order fit. """ x = [] y = [] dx = [] dy = [] if not self.sigmas: self._calc_sigma() print(self.sigmas) previous = self.data dog_shape = (len(self.sigmas) - 1,) + self.data.shape self.dogs = numpy.zeros(dog_shape, dtype=numpy.float32) idx = 0 for sigma_abs, sigma_rel in self.sigmas: if sigma_rel == 0: self.blurs.append(previous) else: new_blur = gaussian_filter(previous, sigma_rel) self.blurs.append(new_blur) self.dogs[idx] = previous - new_blur previous = new_blur idx += 1 if self.dogs[0].shape == self.raw.shape: self.dogs_init = self.dogs if _blob: valid_points = _blob.local_max(self.dogs, self.cur_mask, n_5) else: valid_points = local_max(self.dogs, self.cur_mask, n_5) kps, kpy, kpx = numpy.where(valid_points) l = kpx.size if do_SG4: print ('Before refinement : %i keypoints' % l) kpx,kpy,kps,delta_s = self.refine_Hessian(kpx,kpy,kps) l = kpx.size print ('After refinement : %i keypoints' % l) dtype = numpy.dtype([('x', numpy.float32), ('y', numpy.float32), ('scale', numpy.float32), ('I', numpy.float32)]) keypoints = numpy.recarray((l,), dtype=dtype) sigmas = numpy.array([s[0] for s in self.sigmas]) keypoints[:].x = kpx * self.curr_reduction keypoints[:].y = kpy * self.curr_reduction keypoints[:].scale = (kps + delta_s ** 2) #scale = sigma^2 keypoints[:].I = self.dogs[(kps, numpy.around(kpy).astype(int), numpy.around(kpx).astype(int))] if shrink: #shrink data so that they can be treated by next octave print("In shrink") self.data = binning(self.blurs[self.scale_per_octave], 2) / 4.0 self.curr_reduction *= 2 self.blurs = [] if self.do_mask: self.cur_mask = (binning(self.cur_mask, 2) > 0).astype(numpy.int8) self.cur_mask = morphology.binary_dilation(self.cur_mask, self.grow) self.octave += 1 if len(self.keypoints) == 0 : self.keypoints = keypoints else: old_size = self.keypoints.size new_size = old_size + l self.keypoints.resize(new_size) self.keypoints[old_size:] = keypoints
def _one_octave(self, shrink=True, do_SG4=True, n_5=False): """ Return the blob coordinates for an octave @param shrink: perform the image shrinking after the octave processing @param do_SG4: perform Savitsky-Gollay 4th order fit. """ x=[] y=[] dx=[] dy=[] if not self.sigmas: self._calc_sigma() previous = self.data dog_shape = (len(self.sigmas) - 1,) + self.data.shape self.dogs = numpy.zeros(dog_shape, dtype=numpy.float32) idx = 0 for sigma_abs, sigma_rel in self.sigmas: if sigma_rel == 0: self.blurs.append(previous) else: new_blur = gaussian_filter(previous, sigma_rel) self.blurs.append(new_blur) self.dogs[idx] = previous - new_blur previous = new_blur idx += 1 print self.data.shape, self.cur_mask.shape if _blob: valid_points = _blob.local_max(self.dogs, self.cur_mask, n_5) else: valid_points = local_max(self.dogs, self.cur_mask, n_5) kps, kpy, kpx = numpy.where(valid_points) l = kpx.size dtype = numpy.dtype([('x', numpy.float32), ('y', numpy.float32), ('scale', numpy.float32), ('I', numpy.float32)]) keypoints = numpy.recarray((l,), dtype=dtype) keypoints[:].x = kpx keypoints[:].y = kpy sigmas = numpy.array([s[0] for s in self.sigmas]) keypoints[:].scale = (self.sigma_octave * sigmas.take(kps)) ** 2 #scale = sigma^2 keypoints[:].I = self.dogs[(kps, kpy, kpx)] # if do_SG4: # kx, ky, sigma, dlx, dly = self.refine_SG4(i, loc_keypoint[:].x, loc_keypoint[:].y, loc_keypoint[:].sigma) # else: # kx = loc_keypoint[:].x # ky = loc_keypoint[:].y # sigma = loc_keypoint[:].sigma # dlx = numpy.zeros_like(kx) # dly = numpy.zeros_like(ky) # x.append(kx) # y.append(ky) # dx.append(dlx) # dy.append(dly) # sigmas.append(sigma) # print(kx.__len__(), ky.__len__(), sigma.__len__()) if shrink: #shrink data so that they can be treated by next octave print("In shrink") self.data = binning(self.blurs[self.scale_per_octave], 2) / 4.0 self.sigma_octave *= 2 if self.do_mask: self.cur_mask = binning(self.cur_mask, 2).astype(numpy.int8) / 4 self.cur_mask = morphology.binary_dilation(self.cur_mask, self.grow) self.keypoints = numpy.concatenate((self.keypoints, keypoints))
def _one_octave(self, shrink=True, do_SG4=True, n_5=False): """ Return the blob coordinates for an octave @param shrink: perform the image shrinking after the octave processing @param do_SG4: perform Savitsky-Golay 4th order fit. """ x = [] y = [] dx = [] dy = [] if not self.sigmas: self._calc_sigma() print(self.sigmas) previous = self.data dog_shape = (len(self.sigmas) - 1, ) + self.data.shape self.dogs = numpy.zeros(dog_shape, dtype=numpy.float32) idx = 0 for sigma_abs, sigma_rel in self.sigmas: if sigma_rel == 0: self.blurs.append(previous) else: new_blur = gaussian_filter(previous, sigma_rel) self.blurs.append(new_blur) self.dogs[idx] = previous - new_blur previous = new_blur idx += 1 if self.dogs[0].shape == self.raw.shape: self.dogs_init = self.dogs if _blob: valid_points = _blob.local_max(self.dogs, self.cur_mask, n_5) else: valid_points = local_max(self.dogs, self.cur_mask, n_5) kps, kpy, kpx = numpy.where(valid_points) l = kpx.size if do_SG4: print('Before refinement : %i keypoints' % l) kpx, kpy, kps, delta_s = self.refine_Hessian(kpx, kpy, kps) l = kpx.size print('After refinement : %i keypoints' % l) dtype = numpy.dtype([('x', numpy.float32), ('y', numpy.float32), ('scale', numpy.float32), ('I', numpy.float32)]) keypoints = numpy.recarray((l, ), dtype=dtype) sigmas = numpy.array([s[0] for s in self.sigmas]) keypoints[:].x = kpx * self.curr_reduction keypoints[:].y = kpy * self.curr_reduction keypoints[:].scale = (kps + delta_s**2) #scale = sigma^2 keypoints[:].I = self.dogs[(kps, numpy.around(kpy).astype(int), numpy.around(kpx).astype(int))] if shrink: #shrink data so that they can be treated by next octave print("In shrink") self.data = binning(self.blurs[self.scale_per_octave], 2) / 4.0 self.curr_reduction *= 2 self.blurs = [] if self.do_mask: self.cur_mask = (binning(self.cur_mask, 2) > 0).astype( numpy.int8) self.cur_mask = morphology.binary_dilation( self.cur_mask, self.grow) self.octave += 1 if len(self.keypoints) == 0: self.keypoints = keypoints else: old_size = self.keypoints.size new_size = old_size + l self.keypoints.resize(new_size) self.keypoints[old_size:] = keypoints