【问题标题】:Numpy: negative dimensions are not allowedNumpy:不允许负尺寸
【发布时间】:2020-10-08 06:46:39
【问题描述】:

使用 GeFolki 进行不同卫星数据集的配准我收到以下 ValueError 试图操纵数据。

你能解释一下我做错了什么吗?请帮帮我

from skimage.transform import resize
nx = int(round(dimx/fdecimation)) 
ny = int(round(dimy/fdecimation))
Mg = resize(Master,(nx, ny),1,'constant')
nsx = int(round(dimxn/fdecimation)) 
nsy = int(round(dimyn/fdecimation))
Sg = resize(Slave,(nsx, nsy),1,'constant')       

# Rank computation and Criterion on images after deximation
from rank import rank_sup as rank_filter_sup
from rank import rank_inf as rank_filter_inf
Mg_rank = rank_filter_inf(Mg, rank) # rank sup : high value pixels have low rank
Sg_rank = rank_filter_inf(Sg, rank)

R=np.zeros((nx-nsx-1,ny-nsy-1)); 
indices=np.nonzero(Sg_rank);
test2=Sg_rank[indices];

for k in range(0,nx-nsx-1):
    for p in range(0,ny-nsy-1):
        test1=Mg_rank[k:k+nsx,p:p+nsy];
        test1=test1[indices];
        test=(test1-test2)**2
        R[k,p]=test.mean(); 



ValueError                                Traceback (most recent call last)
<ipython-input-24-bebe7595123d> in <module>
     17 Sg_rank = rank_filter_inf(Sg, rank)
     18 
---> 19 R=np.zeros((nx-nsx-1,ny-nsy-1));
     20 indices=np.nonzero(Sg_rank);
     21 test2=Sg_rank[indices];

ValueError: negative dimensions are not allowed

【问题讨论】:

    标签: numpy dimensions valueerror negative-number


    【解决方案1】:

    显然nx-nsx-1,ny-nsy-1 之一是负数,但您不能创建行/列数为负数的 0 数组。我建议打印出这些值,看看它们在哪里得到负面的修正。

    【讨论】:

    • 嗯,这真的取决于你想通过创建 R 来实现什么以及你的整个目标。我建议您检查一下您希望 R 是什么以及如何使用它,以便您可以将尺寸固定为正确的尺寸。
    • 也请查看stackoverflow.com/help/someone-answers 了解如何接受答案。谢谢。
    猜你喜欢
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    • 2020-01-18
    • 2023-02-26
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 1970-01-01
    相关资源
    最近更新 更多