Skip to content

Commit

Permalink
fix: preprocess to transfer RGB to BGR
Browse files Browse the repository at this point in the history
  • Loading branch information
arabian9ts committed Mar 17, 2018
1 parent 8065904 commit c5e2438
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions util/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,32 @@
author: arabian9ts
"""

import numpy
import skimage
import skimage.io
import skimage.transform
import numpy as np
from scipy.misc import imread, imresize

def load_image(path):
def preprocess(path):
"""
load specified image
Args: image path
Return: resized image
Return: resized image, its size and channel
"""
img = skimage.io.imread(path)
img = img / 255.
resized_img = skimage.transform.resize(img, (300, 300))
return numpy.array(resized_img, dtype=numpy.float32)
img = imread(path)
h, w, c = img.shape
img = imresize(img, (300, 300))
img = img[:, :, ::-1].astype('float32')
img /= 255.
return img, w, h, c


def deprocess(x):
"""
restore processed image
Args: processed image
Return: restored image
"""
# x = x[:, :, ::-1]
x *= 255.
x = np.clip(x, 0, 255).astype('uint8')
return x

0 comments on commit c5e2438

Please sign in to comment.