有没有办法修复旋转和移动布尔掩码时真值的丢失?

2024-09-27 07:29:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用一个布尔掩码,当我移动并旋转它时,掩码中的真值会减少,假值会增加。我希望所有真值在移动和旋转布尔掩码后都相等。我怎样才能解决这个问题

import numpy as np
import scipy
from scipy import ndimage
import skimage
from skimage import draw

mask = skimage.draw.ellipsoid(12,14,25)

# padding the boolean array 

mask2 = np.pad(mask, pad_width = 50 , mode = 'constant')

# shifting the mask

shift1 = scipy.ndimage.shift(mask2, np.array([0,0,-25]))

# Rotating the shifted mask 

angle1 = 30
mask3 = scipy.ndimage.interpolation.rotate(shift1,angle1 , axes (0,2), reshape = False)

# Rotating the roated mask3 along different axis

angle2 = 45
mask4 = scipy.ndimage.interpolation.rotate(mask3, angle2 , axes = (0,1), reshape = False)

# Shapes of same mask after different operations

print np.argwhere(mask == True).shape

print np.argwhere(mask2 == True).shape

print np.argwhere(shift1 == True).shape

print np.argwhere(mask3 == True).shape

print np.argwhere(mask4 == True).shape

所以遮罩是一个椭球体,在数组的中心,有所有的真值。这个椭球体之外的值都是假的。 在第一步中,我用假值填充数组并使其变大。这对真值没有影响,我在mask2中得到的真值和在mask中得到的一样多。第二步是移动mask2这是我的真实价值开始消失的地方为什么?如何修复?在接下来的两个步骤中,旋转移动的遮罩甚至会降低真值。基本上到最后我就丢了面具。有什么办法可以解决这个问题吗


Tags: theimporttruenpmaskscipyprintshape

热门问题