我是python的新手,并且很难理解为什么第一段代码可以工作,但另一部分没有不同的图像。我有兴趣将图像导入多维numpy数组。此外,我必须计算图像梯度的大小
第一个代码示例中的是ndarray,而第二个示例中的g是ndarray
第一个有效:
from Snaxel import Snaxel
from Snake import Snake
from get_snaxels import get_snaxels;
import numpy
import scipy
from pylab import imread, imshow, gray, mean
from matplotlib.pyplot import imsave
alpha = 1.0
beta = 0.0
gamma = -10.0
delta_y = 3
delta_x = 0
row_idx = 160
contour = [];
count = 0
for i in range(0, 1000):
contour.append((row_idx, i))
snaxels, num_snaxels = get_snaxels(contour)
a = imread('synthesized_kymogram_2.png')
f = numpy.rot90(a, 2)
f = numpy.rot90(a, 2)
snake = Snake(snaxels, alpha, beta, delta_y, delta_x, f, gamma)
snake.MinimizeEnergy()
但是,当我修改以下内容时:
from Snaxel import Snaxel
from Snake import Snake
from get_snaxels import get_snaxels;
import numpy
import scipy
from pylab import imread, imshow, gray, mean
from matplotlib.pyplot import imsave
alpha = 1.0
beta = 0.0
gamma = -10.0
delta_y = 3
delta_x = 0
row_idx = 160
contour = [];
count = 0
for i in range(0, 1000):
contour.append((row_idx, i))
snaxels, num_snaxels = get_snaxels(contour)
a = imread('20091016_tumor_26_18245948_1chop.png')
g=ndimage.gaussian_gradient_magnitude(a, 0.4)
snake = Snake(snaxels, alpha, beta, delta_y, delta_x, g, gamma)
snake.MinimizeEnergy()
第二种方法出现以下错误:
if energy < min_energy:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我认为梯度的大小会起作用。但是,它不是吗?有谁知道如何解决它?