GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — deepfeatinterp/utils.py at master · paulu/deepfeatinterp Expand file tree/ Copy pathutils.pyMore file actions 62 lines (54 loc) · 1.77 KB / Copy pathutils.pyFile metadata and controls62 lines (54 loc) · 1.77 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 from __future__ import division from __future__ import with_statement from __future__ import print_function import numpy import imageutils import alignface def image_feed(S,image_dims): ''' Given a list of file paths and a 2-tuple of (H, W), yields H x W x 3 images. ''' for x in S: I=imageutils.read(x) if I.shape[:2]!=image_dims: yield imageutils.resize(I,tuple(image_dims)) else: yield I def warped_image_feed(S,MP,image_dims): ''' Given a list of file paths, warp matrices and a 2-tuple of (H, W), yields H x W x 3 images. ''' for i,x in enumerate(S): I=imageutils.read(x) yield numpy.asarray(alignface.warp_to_template(I,MP[i],image_dims=image_dims)) def center_mask_inplace(I): I[50:150,50:150]=0.5 return I def image_feed_masked(S,image_dims): ''' Given a list of file paths and a 2-tuple of (H, W), yields H x W x 3 images. ''' for x in S: I=imageutils.read(x) if I.shape[:2]!=image_dims: I=imageutils.resize(I,tuple(image_dims)) center_mask_inplace(I) yield I def color_match(A,B): ''' A is a rank 5 tensor (column of original images) B is a rank 5 tensor (grid of images) ''' A=numpy.asarray(A) B=numpy.asarray(B) print('Computing color match',A.shape,B.shape) m=A.reshape(A.shape[0],1,-1).mean(axis=2) m=numpy.expand_dims(numpy.expand_dims(numpy.expand_dims(m,-1),-1),-1) s=(A-m).reshape(A.shape[0],1,-1).std(axis=2) s=numpy.expand_dims(numpy.expand_dims(numpy.expand_dims(s,-1),-1),-1) m2=B.reshape(B.shape[0],B.shape[1],-1).mean(axis=2) m2=numpy.expand_dims(numpy.expand_dims(numpy.expand_dims(m2,-1),-1),-1) s2=(B-m2).reshape(B.shape[0],B.shape[1],-1).std(axis=2) s2=numpy.expand_dims(numpy.expand_dims(numpy.expand_dims(s2,-1),-1),-1) return (B-m2)*(s+1e-8)/(s2+1e-8)+m |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |