Spaces:
Paused
Paused
Download backend/experimental/preprocessing.py from modventures/iris: direct link, hf CLI and curl.
- Browser
- Download file 868 Bytes
-
https://huggingface.co/spaces/modventures/iris/resolve/main/backend/experimental/preprocessing.py
- Command line
-
hf download hf://spaces/modventures/iris/backend/experimental/preprocessing.py
-
curl -L -o preprocessing.py https://huggingface.co/spaces/modventures/iris/resolve/main/backend/experimental/preprocessing.py
868 Bytes
| """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) | |