"""Conservative masks for manually centered iris crops, not automatic segmentation.""" import cv2 import numpy as np def iris_mask(image): h,w=image.shape[:2] y,x=np.indices((h,w),dtype=np.float32) radius=np.hypot(x-w/2,y-h/2)/min(h,w) return (radius>.16)&(radius<.40) def glare_mask(image): # Saturated near-white highlights; ordinary bright colored fibers are retained. bright=(np.min(image,axis=2)>190)&(np.max(image,axis=2)>240) size=max(3,round(min(image.shape[:2])*.009)) return cv2.dilate(bright.astype(np.uint8),np.ones((size,size),np.uint8)).astype(bool) def normalize(image): gray=cv2.cvtColor(image,cv2.COLOR_BGR2GRAY).astype(np.float32) mean=cv2.GaussianBlur(gray,(0,0),7) variance=cv2.GaussianBlur((gray-mean)**2,(0,0),7) return np.clip(128+32*(gray-mean)/np.sqrt(variance+20),0,255).astype(np.uint8)