0

我正在为体素渲染编写一个贪婪的网格算法,其中很大一部分是找到体积的边缘。我通过旋转体积阵列来做到这一点。然后使用 Scipy 的 Ndimage 将其与 3d 边缘检测内核进行卷积。我基本上是在z方向使用清醒的方法。这应该给我垂直于当前扫描轴的二维横截面。但是,当体积数组未完全填充时,我遇到了问题:由于某种原因,当只有一个边缘时,输出给出了两个边缘。这两个都是正面的方向。

请注意,我使用正 1 或负 1 来跟踪边缘所面对的方向。所有面都是来自任何轴的 90 * 孔整数。

我的问题如下。如何使用卷积检测垂直于 z 轴的 3d 体积阵列中的边缘?我应该使用什么样的内核?有没有其他更好的方法?

import numpy as np

from scipy import ndimage

# defines the shape of the array 

isls = 8
rows = 8
clos = 8
itrater = 0 

field = []

for z in range(isls):
    field.append([])

    for y in range(rows):
        field[z].append([])

        for x in range(clos):

            itrater += 1
            
            # to methods for filling the array 
            
            # first method fills array all with 1, it is commented out 

#             field[z][y].append(1)

            # second method

            # fills it with a box of ones that is slightly smaller than the full array 


            field[z][y].append((z<7)*(x<7)*(y<7)*1)
            
# wighted array for edge detection
    
k1 = np.array([[[-0,-0,-0],
                [-0,-1,-0],
                [-0,-0,-0]],

                [[ 0, 0, 0],
                [ 0, 0, 0],
                [ 0, 0, 0]],

                [[ 0, 0, 0],
                [ 0, 1, 0],
                [ 0, 0, 0]]])
                

# convoleds the field array with k1. Also, values outside of the array are set to 0.0 

workingGride = ndimage.convolve(field, k1, mode='constant')

# when the array is not completely filled 

# The output gives two edges with postive 1, given tree edges totally,
# when really there should only be two sides laying flat when you going up and down the z-axis of the cube

#postive or negative ones represent facing direction. 

workingGride

这是出局

array([[[-1, -1, -1, -1, -1, -1, -1,  0],
        [-1, -1, -1, -1, -1, -1, -1,  0],
        [-1, -1, -1, -1, -1, -1, -1,  0],
        [-1, -1, -1, -1, -1, -1, -1,  0],
        [-1, -1, -1, -1, -1, -1, -1,  0],
        [-1, -1, -1, -1, -1, -1, -1,  0],
        [-1, -1, -1, -1, -1, -1, -1,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0]],

       [[ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0]],

       [[ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0]],

       [[ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0]],

       [[ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0]],

       [[ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0]],

       [[ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0]],

       [[ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 1,  1,  1,  1,  1,  1,  1,  0],
        [ 0,  0,  0,  0,  0,  0,  0,  0]]])

# the last one should be filled with 0
4

0 回答 0