import numpy as np
from Segmentation import IrisLocalization
from line import findline, linecoords
import multiprocessing as mp
##-----------------------------------------------------------------------------
## Function
##-----------------------------------------------------------------------------
def segment(eyeim, eyelashes_thres=80, use_multiprocess=True):
ciriris,cirpupil = IrisLocalization(eyeim)
row = np.round(ciriris[0]).astype(int)
col = np.round(ciriris[1]).astype(int)
r = np.round(ciriris[2]).astype(int)
rowp = np.round(cirpupil[0]).astype(int)
colp = np.round(cirpupil[1]).astype(int)
rp = np.round(cirpupil[2]).astype(int)
# Find top and bottom eyelid
imsz = eyeim.shape
irl = np.round(row - r).astype(int)
iru = np.round(row + r).astype(int)
icl = np.round(col - r).astype(int)
icu = np.round(col + r).astype(int)
if irl < 0:
irl = 0
if icl < 0:
icl = 0
if iru >= imsz[0]:
iru = imsz[0] - 1
if icu >= imsz[1]:
icu = imsz[1] - 1
imageiris = eyeim[irl: iru + 1, icl: icu + 1]
# If use_multiprocess
if use_multiprocess:
ret_top = mp.Manager().dict()
ret_bot = mp.Manager().dict()
p_top = mp.Process(
target=findTopEyelid,
args=(imsz, imageiris, irl, icl, rowp, rp, ret_top),
)
p_bot = mp.Process(
target=findBottomEyelid,
args=(imsz, imageiris, rowp, rp, irl, icl, ret_bot),
)
p_top.start()
p_bot.start()
p_top.join()
p_bot.join()
mask_top = ret_top[0]
mask_bot = ret_bot[0]
# If not use_multiprocess
else:
mask_top = findTopEyelid(imsz, imageiris, irl, icl, rowp, rp)
mask_bot = findBottomEyelid(imsz, imageiris, rowp, rp, irl, icl)
# Mask the eye image, noise region is masked by NaN value
imwithnoise = eyeim.astype(float)
imwithnoise = imwithnoise + mask_top + mask_bot
ref = eyeim < eyelashes_thres
coords = np.where(ref == 1)
imwithnoise[coords] = np.nan
return ciriris, cirpupil, imwithnoise
#------------------------------------------------------------------------------
def findTopEyelid(imsz, imageiris, irl, icl, rowp, rp, ret_top=None):
"""
Description:
Mask for the top eyelid region.
Input:
imsz - Size of the eye image.
imageiris - Image of the iris region.
irl -
icl -
rowp - y-coordinate of the inner circle centre.
rp - radius of the inner circle centre.
ret_top - Just used for returning result when using multiprocess.
Output:
mask - Map of noise that will be masked with NaN values.
"""
topeyelid = imageiris[0: rowp - irl - rp, :]
lines = findline(topeyelid)
mask = np.zeros(imsz, dtype=float)
if lines.size > 0:
xl, yl = linecoords(lines, topeyelid.shape)
yl = np.round(yl + irl - 1).astype(int)
xl = np
虹膜识别--mask的生成
最新推荐文章于 2021-12-27 11:42:25 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)