1 回答
TA贡献1786条经验 获得超13个赞
你可以像这样处理它,我使用的是 HSV 颜色空间而不是 YCbCr 颜色空间:
#!/usr/bin/env python3
import numpy as np
from PIL import Image
# Open image and convert to HSV colourspace
im = Image.open('hand.png').convert('HSV')
# Convert to Numpy array
ni = np.array(im)
# Get H, S and V of central pixel - consider taking a median of a larger area here
h,s,v = ni[int(ni.shape[0]/2), int(ni.shape[1]/2)]
# Separate each channel to own array
H = ni[:,:,0]
S = ni[:,:,1]
V = ni[:,:,2]
# Permissible +/- tolerances on each channel
deltah = 20
deltas = 80
deltav = 50
# Make masks of pixels with acceptable H, S and V
hmask = np.where((H > h-deltah) & (H < h+deltah), 255, 0).astype(np.uint8)
smask = np.where((S > s-deltas) & (S < s+deltas), 255, 0).astype(np.uint8)
vmask = np.where((V > v-deltav) & (V < v+deltav), 255, 0).astype(np.uint8)
# Save as images for inspection
Image.fromarray(hmask).save('hmask.png')
Image.fromarray(smask).save('smask.png')
Image.fromarray(vmask).save('vmask.png')
生成的色调蒙版:
产生的饱和度遮罩:
结果值掩码:
然后,您可以将掩码与或或组合在一起以获得更复杂的掩码组合。
添加回答
举报