0

我正在尝试使用 python 进行图像处理。

我尝试创建一个包含 numpy.ndarrays 的列表。

我的代码看起来像这样,

def Minimum_Close(Shade_Corrected_Image, Size):

    uint32_Shade_Corrected_Image = pymorph.to_int32(Shade_Corrected_Image)
    Angles = []

    [Row, Column] = Shade_Corrected_Image.shape


    Angles = [i*15 for i in range(12)] 



    Image_Close = [0 for x in range(len(Angles))]
    Image_Closing = numpy.zeros((Row, Column))

    for s in range(len(Angles)):

        Struct_Element = pymorph.seline(Size, Angles[s])
        Image_Closing = pymorph.close(uint32_Shade_Corrected_Image,Struct_Element )
        Image_Close[s] = Image_Closing

    Min_Close_Image = numpy.zeros(Shade_Corrected_Image.shape)

    temp_array = [][]
    Temp_Cell = numpy.zeros((Row, Column))

    for r in range (1, Row):
        for c in range(1,Column):
            for Cell in Image_Close:

                Temp_Cell = Image_Close[Cell]

                temp_array[Cell] = Temp_Cell[r][c]

            Min_Close_Image[r][c] = min(temp_array)    



    Min_Close_Image = Min_Close_Image - Shade_Corrected_Image    

    return Min_Close_Image

运行此代码时出现错误:

Temp_Cell = Image_Close[Cell]

TypeError: only integer arrays with one element can be converted to an index

如何制作一个包含不同多维数组的数据结构,然后遍历它?

4

2 回答 2

1

使用 numpy 时,不需要制作数组列表。

我建议像这样重写整个函数:

def Minimum_Close(shade_corrected_image, size):

    uint32_shade_corrected_image = pymorph.to_int32(shade_corrected_image)

    angles = np.arange(12) * 15

    def pymorph_op(angle):
        struct_element = pymorph.seline(size, angle)
        return pymorph.close(uint32_shade_corrected_image, struct_element)

    image_close = np.dstack(pymorph_op(a) for a in angles)

    min_close_image = np.min(image_close, axis=-1) - shade_corrected_image

    return min_close_image

我降低了大小写的变量名称,以便它们不再作为类突出显示。

于 2013-08-21T12:12:03.940 回答
0

关于什么:

for cnt,Cell in enumerate(Image_Close):
  Temp_Cell = Image_Close[cnt]
于 2013-08-21T11:26:06.210 回答