Exemplo n.º 1
0
 def f(file):
   image = Image.open(file)
   image = np.array(image)
   for n in nodes[1:]:
     n.multipleLoad(image.size)
     updateNode(n)
   if len(nodes):
     updateNode(nodes[0].parent)
   if len(image.shape) == 2:
     return image.reshape(*image.shape, 1)
   if image.shape[2] == 3 or image.shape[2] == 4:
     return image
   else:
     raise RuntimeError('Unknown image format')
Exemplo n.º 2
0
 def f(im):
   nonlocal h, w
   if opt['update']:
     _, h, w = im.shape
     oriLoad = h * w
     h = round(h * opt['scaleH']) if 'scaleH' in opt else opt['height']
     w = round(w * opt['scaleW']) if 'scaleW' in opt else opt['width']
     newLoad = h * w
     if len(nodes):
       nodes[pos].load = im.nelement()
       newLoad /= oriLoad
       for n in nodes[pos + 1:]:
         n.multipleLoad(newLoad)
         updateNode(n)
     if out['source']:
       opt['update'] = False
   return resizeByTorch(im, w, h, opt['method'])
Exemplo n.º 3
0
 def f(file):
     image = Image.open(file)
     context.imageMode = image.mode
     if image.mode == 'P':
         context.palette = image
         image = image.convert('RGB')
     image = np.array(image)
     for n in nodes:
         n.multipleLoad(image.size)
         updateNode(n)
     if len(nodes):
         p = nodes[0].parent
         updateNode(p)
         p.callback(p)
     if len(image.shape) == 2:
         return image.reshape(*image.shape, 1)
     if image.shape[2] == 3 or image.shape[2] == 4:
         return image
     else:
         raise RuntimeError('Unknown image format')