"""Produce portfolio crops and numerical gradient views from the credited originals.""" from pathlib import Path import numpy as np from PIL import Image from scipy.ndimage import gaussian_filter, sobel HERE=Path(__file__).resolve().parent OUT=HERE.parent/'assets' def save(name,pixels): Image.fromarray(np.uint8(np.clip(pixels,0,255))).save(OUT/name,'WEBP',quality=94,method=6) def smooth(a): a=np.clip(a,0,1) return a*a*(3-2*a) def exposure_study(): rgb=np.asarray(Image.open(HERE/'eye-photograph.jpg').convert('RGB'),float)/255 lum=rgb@np.array([.2126,.7152,.0722]) y,x=np.indices(lum.shape); h,w=lum.shape lightness=(lum-.05)/.93 # The signed local residual keeps fine photographic texture in the dark exposure. detail=lum-gaussian_filter(lum,4) iris_center=(.505*w,.509*h) d=np.sqrt(((x-iris_center[0])/(.48*w))**2+((y-iris_center[1])/(.335*h))**2) light=np.exp(-.62*d*d) normalized=np.clip(.72*lightness+.18*(lum-gaussian_filter(lum,50))+.9*detail,0,1) base=(normalized**1.19)*light rgbout=np.stack([base*.95,base*.993,base*1.035],axis=2) natural_color=(rgb-lum[:,:,None])*.27*np.exp(-5*d*d)[:,:,None] shot=np.clip((rgbout+natural_color)*255,0,255) gy=sobel(gaussian_filter(lum,1.3),axis=0,mode='reflect')/8 gx=sobel(gaussian_filter(lum,1.3),axis=1,mode='reflect')/8 magnitude=np.hypot(gx,gy) scaled=np.clip(magnitude/np.percentile(magnitude,99.5),0,1)**.64 angle=np.arctan2(gy,gx) tint=(.5+.5*np.cos(2*angle))[:,:,None] ink=np.array([164,154,207])*(1-tint)+np.array([177,221,229])*tint edge=(scaled[:,:,None]*ink)*(.57+.43*light[:,:,None]) for name,data in [('image',shot),('gradient',edge)]: for view,width,height,box in [('wide',2000,900,(-1020,180,1463,1297)),('mobile',900,850,(50,225,1416,1515)),('detail',980,620,(240,350,1260,995))]: image=Image.fromarray(data.astype('uint8')).crop(box).resize((width,height),Image.Resampling.LANCZOS) pixels=np.asarray(image,float) yy,xx=np.indices((height,width)) if view=='wide': mask=smooth((xx/width-.37)/.32)*smooth((1.09-yy/height)/.28)*smooth((yy/height+.2)/.32) elif view=='mobile': mask=smooth((1-yy/height)/.3)*smooth((yy/height+.12)/.23) else:mask=np.ones((height,width)) background=np.array([8,9,11]) save(f'eye-{name}-{view}.webp',background+pixels*mask[:,:,None]*1.32) freq=np.fft.fftshift(np.fft.fft2((lum-lum.mean())*np.outer(np.hanning(h),np.hanning(w)))) power=np.log1p(abs(freq)) power=np.clip((power-np.percentile(power,35))/(np.percentile(power,99.7)-np.percentile(power,35)),0,1) spec=np.array([7,9,13])+power[:,:,None]**1.65*np.array([154,189,218]) save('eye-spatial-spectrum.webp',np.asarray(Image.fromarray(np.uint8(np.clip(spec,0,255))).resize((770,668),Image.Resampling.LANCZOS))) def hand_study(): raw=Image.open(HERE/'rowland-hand-1896.jpg').convert('L') raw.thumbnail((1050,1345),Image.Resampling.LANCZOS) a=np.asarray(raw,float)/255 norm=np.clip((.95-a)/.90,0,1)**1.1 color=np.array([8,9,11])+norm[:,:,None]*np.array([145,161,174]) save('radiograph.webp',color) if __name__=='__main__': exposure_study() hand_study() def comparison_stills(): for view,cut in [('wide',.83),('mobile',.83)]: first=Image.open(OUT/f'eye-image-{view}.webp').convert('RGB') second=Image.open(OUT/f'eye-gradient-{view}.webp').convert('RGB') boundary=round(first.width*cut) first.paste(second.crop((boundary,0,first.width,first.height)),(boundary,0)) values=np.asarray(first).copy() values[:,boundary]=np.round(values[:,boundary]*.65+np.array([177,221,229])*.35).astype('uint8') save(f'eye-study-{view}.webp',values) if __name__=='__main__': comparison_stills()