def load_image(image_path, model=None): """Loads and rectifies an image from file. Args: image_path (str): path to an image from the dataset. model (camera_model.CameraModel): if supplied, model will be used to undistort image. Returns: numpy.ndarray: demosaiced and optionally undistorted image """ if model: camera = model.camera else: camera = re.search('(stereo|mono_(left|right|rear))', image_path).group(0) if camera == 'stereo': pattern = BAYER_STEREO else: pattern = BAYER_MONO img = Image.open(image_path) img = demosaic(img, pattern) if model: img = model.undistort(img) return img
def load_image(image_path, model=None): """Loads and rectifies an image from file. Args: image_path (str): path to an image from the dataset. model (camera_model.CameraModel): if supplied, model will be used to undistort image. Returns: numpy.ndarray: demosaiced and optionally undistorted image """ if model: camera = model.camera else: camera = re.search('(stereo|mono_(left|right|rear))', image_path).group(0) if camera == 'stereo': pattern = BAYER_STEREO else: pattern = BAYER_MONO if model: img = demosaic(Image.open(image_path), pattern) img = model.undistort(img) img = rgb_2_grey(img) else: img = non_demosaic_load(image_path) assert isinstance( img, np.ndarray) and img.dtype == np.uint8 and img.flags.contiguous return img
def load_image(image_path): img = Image.open(image_path) img = demosaic(img, 'gbrg') cvimage = np.array(img, dtype=np.uint8) cvimage = cv2.cvtColor(cvimage, cv2.COLOR_RGB2BGR) cvgray = cv2.cvtColor(cvimage, cv2.COLOR_BGR2GRAY) lbp = feature.local_binary_pattern(cvgray, 8, 1, method='default') im = Image.fromarray(np.uint8(lbp)) return im
def load_stereo(image_path: str, model: CameraModel = None): """ Loads an image and processes it with a model (if given) :param image_path: The path to an image :type image_path: String :param model: A camera model path to undistort the image and apply LUT :type model: CameraModel class :returns cv2 image """ pattern = 'gbrg' img = Image.open(str(image_path)) img = demosaic(img, pattern) if model: # Apply the model img = model.undistort(img) # print("Applying model") return img
def load_image(img_file): img_height = args.height img_width = args.width img = Image.open(img_file) img = demosaic(img, 'gbrg') if 'left' in img_file: img = args.left_model.undistort(img) if 'right' in img_file: img = args.right_model.undistort(img) img = np.array(img).astype(np.uint8) img = img[crop[0]:crop[1], crop[2]:crop[3]] orig_img_height = img.shape[0] orig_img_width = img.shape[1] zoom_y = img_height / orig_img_height zoom_x = img_width / orig_img_width img = np.array( Image.fromarray(img).resize((img_width, img_height), resample=Image.ANTIALIAS)) return img, zoom_x, zoom_y, orig_img_width, orig_img_height
def load_stereo(image_path: str, model: CameraModel = None): """ Loads an image and processes it with a model (if given) :param image_path: The path to an image :type image_path: String :param model: A camera model path to undistort the image and apply LUT :type model: CameraModel class :param view: A pass-through variable :param outName: Another pass-through variable :type outName: str :returns cv2 image """ pattern = 'gbrg' with Image.open(str(image_path)) as img: img = demosaic(img, pattern) if model: # Apply the model img = model.undistort(img) return img
def load_image_demosaic(filename): BAYER_STEREO = 'gbrg' BAYER_MONO = 'rggb' camera = re.search('(stereo|mono_(left|right|rear))', filename).group(0) if camera == 'stereo': pattern = BAYER_STEREO else: pattern = BAYER_MONO img = Image.open(filename) print(img) img = demosaic(img, pattern) #img = cv2.imread(filename) print(img.shape) #img = cv2.resize(img,(256,256)) #img = demosaic(img, pattern) cv2.imshow('image',img) cv2.waitKey(0) return np.array(img).astype(np.uint8)
def load_image(image_path): img = Image.open(image_path) img = demosaic(img, 'gbrg') im = Image.fromarray(np.uint8(img)) return im
img_suffix = '.png' dump_bits = 6 img_name = listdir(pic_file) img_postfix = img_name[0][:dump_bits] img_timeStamp = [int(x[dump_bits:].strip(img_suffix)) for x in img_name] img_timeStamp = sorted(img_timeStamp) sorted_imgname = [ img_postfix + str(x) + img_suffix for x in np.array(img_timeStamp)[idx] ] for k, each in enumerate(sorted_imgname): img = join(pic_file, each) if exists(img): img = Image.open(img) img = demosaic(img, 'GBRG') img = cv2.cvtColor(img.astype(np.uint8), cv2.COLOR_RGB2BGR) img = cv2.resize(img, (224, 224)) cv2.imwrite(save_file + str(k) + img_suffix, img) else: print(img + 'is not found') break if k % 10 == 0: print('%d / %d' % (k, len(sorted_imgname))) # save ground truth np.save(root + 'gps_' + data_name + '.npy', gps)
def __call__(self, img): if random.uniform(0, 1) > self.probability: return img img = demosaic(img, 'gbrg') return Image.fromarray(img.astype('uint8')).convert('RGB')