Created
January 11, 2018 13:59
-
-
Save ArnoutDevos/3d325a0b442251b6648f7983259e90ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
def imgread(path): | |
print "Image:", path.split("/")[-1] | |
# Read in the image using python opencv | |
img = cv2.imread(path) | |
img = img / 255.0 | |
print "Raw Image Shape: ", img.shape | |
# Center crop the image | |
short_edge = min(img.shape[:2]) | |
W, H, C = img.shape | |
to_crop = min(W, H) | |
cent_w = int((img.shape[1] - short_edge) / 2) | |
cent_h = int((img.shape[0] - short_edge) / 2) | |
img_cropped = img[cent_h:cent_h+to_crop, cent_w:cent_w+to_crop] | |
print "Cropped Image Shape: ", img_cropped.shape | |
# Resize the cropped image to 224 by 224 for VGG16 network | |
img_resized = cv2.resize(img_cropped, (224, 224), interpolation=cv2.INTER_LINEAR) | |
print "Resized Image Shape: ", img_resized.shape | |
return img_resized |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment