def test_optimize(): lena = scipy.misc.lena() blurred1 = scipy.ndimage.gaussian_filter(lena, 3.0) blurred2 = scipy.ndimage.gaussian_filter(blurred1, 1.5) fp = af.FocusPoint(0, 0, 10, 10) stack = np.dstack((blurred2, np.dstack((blurred1, lena)))) assert af.optimize(stack, fp, af.cost_sobel) == 2
def _on_region_update(self, widget, x, y, width, height): fp = af.FocusPoint(x, y, width, height) J_sobel = af.optimize(self.stack, fp, af.cost_sobel) J_abs_grad = af.optimize(self.stack, fp, af.cost_abs_gradient) J_sq_grad = af.optimize(self.stack, fp, af.cost_squared_gradient) self.ax.clear() self.ax.plot(J_sobel / np.max(J_sobel), '.-', color='#348ABD', label='Sobel') self.ax.plot(J_abs_grad / np.max(J_abs_grad), '.-', color='#7A68A6', label='Absolute Gradient') self.ax.plot(J_sq_grad / np.max(J_sq_grad), '.-', color='#467821', label='Squared Gradient') self.ax.legend(loc=3) self.figure.canvas.draw() opt = np.argmax(J_sobel) self.canvas.update_image(self.stack[:,:,opt])