<filename>CNIC-X/util.py
# -*- coding: utf-8 -*-
import skimage.io
import skimage.transform
import ipdb
import numpy as np
def load_image(path):
 try:
  img=skimage.io.imread(path).astype(float)
 except:
  return None
 if img is None:return None
 if len(img.shape)<2:return None
 if len(img.shape)==4:return None
 if len(img.shape)==2:img=np.tile(img[:,:,None],3)
 if img.shape[2]==4:img=img[:,:,:3]
 if img.shape[2]>4:return None
 img/=255.
 short_edge=min(img.shape[:2])
 yy=int((img.shape[0]-short_edge)/2)
 xx=int((img.shape[1]-short_edge)/2)
 resized_img=skimage.transform.resize(img,[224,224])
 return resized_img



<filename>CNIC-X/util.py
# -*- coding: utf-8 -*-
import skimage.io
import skimage.transform
import ipdb
import numpy as np
def load_image(path):
 try:
  img=skimage.io.imread(path).astype(float)
 except:
  return None
 if img is None:return None
 if len(img.shape)<2:return None
 if len(img.shape)==4:return None
 if len(img.shape)==2:img=np.tile(img[:,:,None],3)
 if img.shape[2]==4:img=img[:,:,:3]
 if img.shape[2]>4:return None
 img/=255.
 short_edge=min(img.shape[:2])
 yy=int((img.shape[0]-short_edge)/2)
 xx=int((img.shape[1]-short_edge)/2)
 resized_img=skimage.transform.resize(img,[224,224])
 return resized_img



# -*- coding: utf-8 -*-