def prepare(filepath, mean_image, h, w): width = w height = h img_array = cv2.imread(filepath) # read in the image img_array = imgproc.toUINT8(img_array) img_array = imgproc.process_image(img_array, (height, width)) img_array = np.float32(img_array) new_array = cv2.resize(img_array, (width, height)) # resize image to match model's expected sizing res = new_array.reshape(-1, height, width, 3) res = res - mean_image return res # return the image with shaping that TF wants.
def read_image(filename, number_of_channels): """ read_image using skimage The output is a 3-dim image [H, W, C] """ if number_of_channels == 1: image = io.imread(filename, as_gray=True) image = imgproc.toUINT8(image) assert (len(image.shape) == 2) image = np.expand_dims(image, axis=2) #H,W,C assert (len(image.shape) == 3 and image.shape[2] == 1) elif number_of_channels == 3: image = io.imread(filename) if (len(image.shape) == 2): image = color.gray2rgb(image) image = imgproc.toUINT8(image) assert (len(image.shape) == 3) else: raise ValueError("number_of_channels must be 1 or 3") if not os.path.exists(filename): raise ValueError(filename + " does not exist!") return image
def draw_result(self, filenames): w = 1000 h = 1000 w_i = np.int(w / 10) h_i = np.int(h / 10) image_r = np.zeros((w, h, 3), dtype=np.uint8) + 255 x = 0 y = 0 for i, filename in enumerate(filenames): pos = (i * w_i) x = pos % w y = np.int(np.floor(pos / w)) * h_i image = self.read_image(filename) image = imgproc.toUINT8(trans.resize(image, (h_i, w_i))) image_r[y:y + h_i, x:x + w_i, :] = image return image_r
def prepare(filepath, mean_image, h, w): width = w height = h img_array = cv2.imread( filepath, cv2.IMREAD_UNCHANGED, ) # read in the image, convert to grayscale img_array = imgproc.toUINT8(img_array) img_array = imgproc.process_image(img_array, (height, width)) #cv2.imshow("window", img_array) #cv2.waitKey() img_array = np.float32(img_array) new_array = cv2.resize( img_array, (width, height)) # resize image to match model's expected sizing res = new_array.reshape(-1, height, width, 3) res = res - mean_image return res # return the image with shaping that TF wants.