def startsnake(): t = np.arange(0, 2 * np.pi, 0.1) x = 437 + 350 * np.cos(t) y = 493 + 400 * np.sin(t) #alpha =0.003 #beta = 0.02 #gamma = 300 #iterations = 100 alpha = float(dig.alpha.text()) beta = float(dig.beta.text()) gamma = float(dig.gamma.text()) iterations = 100 # fx and fy are callable functions fx, fy = sn.create_external_edge_force_gradients_from_img(dig.snake, sigma=10) snakes = sn.iterate_snake(x=x, y=y, a=alpha, b=beta, fx=fx, fy=fy, gamma=gamma, n_iters=iterations, return_all=True) fig = plt.figure() ax = fig.add_subplot(111) ax.imshow(dig.snake, cmap=plt.cm.gray) ax.set_xticks([]) ax.set_yticks([]) ax.set_xlim(0, dig.snake.shape[1]) ax.set_ylim(dig.snake.shape[0], 0) ax.plot(np.r_[x, x[0]], np.r_[y, y[0]], c=(0, 1, 0), lw=2) for i, snake in enumerate(snakes): if i % 10 == 0: ax.plot(np.r_[snake[0], snake[0][0]], np.r_[snake[1], snake[1][0]], c=(0, 0, 1), lw=2) # Plot the last one a different color. ax.plot(np.r_[snakes[-1][0], snakes[-1][0][0]], np.r_[snakes[-1][1], snakes[-1][1][0]], c=(1, 0, 0), lw=2) plt.show() yourQImage = qimage2ndarray.array2qimage(dig.snake) gray = QtGui.QImage(yourQImage) pixmap = QtGui.QPixmap.fromImage(gray) pixmap = pixmap.scaled(dig.label_snake_image.width(), dig.label_snake_image.height(), QtCore.Qt.KeepAspectRatio) dig.label_snake_image.setPixmap(pixmap) # Set the pixmap onto the label dig.label_snake_image.setAlignment(QtCore.Qt.AlignCenter)
def left_lung(src): x, y = np.mgrid[-4:4:256j, -4:4:256j] rad = (x**2 + y**2)**0.5 tht = np.arctan2(y, x) # first shape of the snake t = np.arange(0, 2 * np.pi, 0.1) x = 200 + 120 * np.cos(t) y = 450 + 280 * np.sin(t) alpha = 0.0005 beta = 0.001 gamma = 100 iterations = 500 # fx and fy are callable functions fx, fy = sn.create_external_edge_force_gradients_from_img(src, sigma=10) snakes = sn.iterate_snake(x=x, y=y, a=alpha, b=beta, fx=fx, fy=fy, gamma=gamma, n_iters=iterations, return_all=True) return snakes
def snakeContour(self): img = np.load('./img.npy') t = np.arange(0, 2*np.pi, 0.1) x = 120+50*np.cos(t) y = 140+60*np.sin(t) alpha = 0.001 beta = 0.4 gamma = 100 iterations = 50 # fx and fy are callable functions fx, fy = sn.create_external_edge_force_gradients_from_img( img ) snakes = sn.iterate_snake( x = x, y = y, a = alpha, b = beta, fx = fx, fy = fy, gamma = gamma, n_iters = iterations, return_all = True ) self.activeContoursInputImage.setImage(img,xvals=np.linspace(1., 3., img.shape[0])) # self.activeContoursOutputImage.setImage(img,xvals=np.linspace(1., 3., img.shape[0])) fig = plt.pyplot.figure() ax = fig.add_subplot() ax.imshow(img) ax.set_xticks([]) ax.set_yticks([]) ax.set_xlim(0,img.shape[1]) ax.set_ylim(img.shape[0],0) ax.plot(np.r_[x,x[0]], np.r_[y,y[0]], c=(0,1,0), lw=2) for i, snake in enumerate(snakes): if i % 10 == 0: ax.plot(np.r_[snake[0], snake[0][0]], np.r_[snake[1], snake[1][0]], c=(0,0,1), lw=2) # Plot the last one a different color. ax.plot(np.r_[snakes[-1][0], snakes[-1][0][0]], np.r_[snakes[-1][1], snakes[-1][1][0]], c=(1,0,0), lw=2) plt.pyplot.savefig('snake.jpg') outImg = cv.imread('./snake.jpg') self.activeContoursOutputImage.setImage(outImg) cny_img_in = cv.imread('CannyInput.jpg') self.cannyInputImage.setImage(cny_img_in.T) cny_img_out = canny.canny_apply("CannyInput.jpg") # print(type(np.asarray(cny_img_out))) self.cannyOutputImage.setImage(np.asarray(cny_img_out).T)
x = 120 + 50 * np.cos(t) y = 140 + 60 * np.sin(t) alpha = 0.001 beta = 0.4 gamma = 100 iterations = 50 # fx and fy are callable functions fx, fy = sn.create_external_edge_force_gradients_from_img(img) snakes = sn.iterate_snake(x=x, y=y, a=alpha, b=beta, fx=fx, fy=fy, gamma=gamma, n_iters=iterations, return_all=True) fig = plt.figure() ax = fig.add_subplot(111) ax.imshow(img, cmap=plt.cm.gray) ax.set_xticks([]) ax.set_yticks([]) ax.set_xlim(0, img.shape[1]) ax.set_ylim(img.shape[0], 0) ax.plot(np.r_[x, x[0]], np.r_[y, y[0]], c=(0, 1, 0), lw=2) for i, snake in enumerate(snakes):
y = 128+100*np.sin(t) alpha = 0.001 beta = 0.01 gamma = 100 iterations = 50 # fx and fy are callable functions fx, fy = sn.create_external_edge_force_gradients_from_img( img, sigma=10 ) snakes = sn.iterate_snake( x = x, y = y, a = alpha, b = beta, fx = fx, fy = fy, gamma = gamma, n_iters = iterations, return_all = True ) fig = plt.figure() ax = fig.add_subplot(111) ax.imshow(img, cmap=plt.cm.gray) ax.set_xticks([]) ax.set_yticks([]) ax.set_xlim(0,img.shape[1]) ax.set_ylim(img.shape[0],0) ax.plot(np.r_[x,x[0]], np.r_[y,y[0]], c=(0,1,0), lw=2)