def __init__(self, filename_or_array, **kwargs): digest_config(self, kwargs) if isinstance(filename_or_array, str): path = get_full_raster_image_path(filename_or_array) image = Image.open(path).convert(self.image_mode) self.pixel_array = np.array(image) else: self.pixel_array = np.array(filename_or_array) self.change_to_rgba_array() if self.invert: self.pixel_array[:, :, :3] = 255 - self.pixel_array[:, :, :3] Mobject.__init__(self, **kwargs)
def __init__(self, filename_or_array, **kwargs): digest_config(self, kwargs) if isinstance(filename_or_array, str): path = get_full_raster_image_path(filename_or_array) image = Image.open(path).convert(self.image_mode) self.pixel_array = np.array(image) else: self.pixel_array = np.array(filename_or_array) self.change_to_rgba_array() if self.invert: self.pixel_array[:, :, :3] = 255 - self.pixel_array[:, :, :3] AbstractImageMobject.__init__(self, **kwargs)
def get_background_array(self, file_name): if file_name in self.file_name_to_pixel_array_map: return self.file_name_to_pixel_array_map[file_name] full_path = get_full_raster_image_path(file_name) image = Image.open(full_path) back_array = np.array(image) pixel_array = self.pixel_array if not np.all(pixel_array.shape == back_array.shape): back_array = self.resize_background_array_to_match( back_array, pixel_array) self.file_name_to_pixel_array_map[file_name] = back_array return back_array
def get_background_array(self, file_name): if file_name in self.file_name_to_pixel_array_map: return self.file_name_to_pixel_array_map[file_name] full_path = get_full_raster_image_path(file_name) image = Image.open(full_path) array = np.array(image) camera = self.camera if not np.all(camera.pixel_array.shape == array.shape): array = self.resize_background_array_to_match( array, camera.pixel_array) self.file_name_to_pixel_array_map[file_name] = array return array
def get_background_array(self, file_name): if file_name in self.file_name_to_pixel_array_map: return self.file_name_to_pixel_array_map[file_name] full_path = get_full_raster_image_path(file_name) image = Image.open(full_path) array = np.array(image) camera = self.camera if not np.all(camera.pixel_array.shape == array.shape): array = self.resize_background_array_to_match( array, camera.pixel_array) self.file_name_to_pixel_array_map[file_name] = array return array
def init_background(self): height = self.get_pixel_height() width = self.get_pixel_width() if self.background_image is not None: path = get_full_raster_image_path(self.background_image) image = Image.open(path).convert(self.image_mode) # TODO, how to gracefully handle backgrounds # with different sizes? self.background = np.array(image)[:height, :width] self.background = self.background.astype(self.pixel_array_dtype) else: background_rgba = color_to_int_rgba(self.background_color, self.background_opacity) self.background = np.zeros((height, width, self.n_channels), dtype=self.pixel_array_dtype) self.background[:, :] = background_rgba
def init_background(self): if self.background_image is not None: path = get_full_raster_image_path(self.background_image) image = Image.open(path).convert(self.image_mode) height, width = self.pixel_shape #TODO, how to gracefully handle backgrounds #with different sizes? self.background = np.array(image)[:height, :width] self.background = self.background.astype(self.pixel_array_dtype) else: background_rgba = color_to_int_rgba(self.background_color, alpha=self.background_alpha) self.background = np.zeros(list(self.pixel_shape) + [self.n_rgb_coords], dtype=self.pixel_array_dtype) self.background[:, :] = background_rgba
def init_background(self): height = self.get_pixel_height() width = self.get_pixel_width() if self.background_image is not None: path = get_full_raster_image_path(self.background_image) image = Image.open(path).convert(self.image_mode) # TODO, how to gracefully handle backgrounds # with different sizes? self.background = np.array(image)[:height, :width] self.background = self.background.astype(self.pixel_array_dtype) else: background_rgba = color_to_int_rgba( self.background_color, self.background_opacity ) self.background = np.zeros( (height, width, self.n_rgb_coords), dtype=self.pixel_array_dtype ) self.background[:, :] = background_rgba