def load_mask(self, image_id): """ Generate instance masks for an image. Returns: masks: A bool array of shape [height, width, instance count] with one mask per instance. class_ids: a 1D array of class IDs of the instance masks. """ # If not a sidelobe dataset image, delegate to parent class. image_info = self.image_info[image_id] if image_info["source"] != "sidelobe": return super(self.__class__, self).load_mask(image_id) # Set bitmap mask of shape [height, width, instance_count] info = self.image_info[image_id] filename = info["path_mask"] class_id = info["class_id"] # Read mask data, header = utils.read_fits(filename, stretch=False, normalize=False, convertToRGB=False) height = data.shape[0] width = data.shape[1] data = data.astype(np.bool) mask = np.zeros([height, width, 1], dtype=np.bool) mask[:, :, 0] = data instance_counts = np.full([mask.shape[-1]], class_id, dtype=np.int32) # Return mask, and array of class IDs of each instance return mask, instance_counts
def load_image(self, image_id): """Load the specified image and return a [H, W, 1] Numpy array.""" # Load image filename = self.image_info[image_id]['path'] convertToRGB: bool = False image, header = utils.read_fits(filename, stretch=True, normalize=True, convertToRGB=convertToRGB) if not convertToRGB: image = np.expand_dims(image, axis=2) return image
def load_image(self, image_id): """Load the specified image and return a [H,W,3] Numpy array.""" # Load image filename = self.image_info[image_id]['path'] image, header = utils.read_fits(filename, stretch=True, normalize=True, convertToRGB=True) return image
def load_gt_mask(self, image_id): """ Load gt mask """ # Read filename info = self.image_info[image_id] filename = info["path_mask"] class_id = info["class_id"] # Read mask data, header = utils.read_fits(filename, stretch=False, normalize=False, convertToRGB=False) height = data.shape[0] width = data.shape[1] data = data.astype(np.bool) mask = np.zeros([height, width, 1], dtype=np.bool) mask[:, :, 0] = data return mask
def load_image(self, image_id): """Load the specified image and return a [H,W,3] Numpy array.""" # Load image filename = self.image_info[image_id]['path'] image, header = utils.read_fits(filename, stretch=True, normalize=True, convertToRGB=True) #image = skimage.io.imread(filename) # If grayscale. Convert to RGB for consistency. #if image.ndim != 3: # image = skimage.color.gray2rgb(image) # If has an alpha channel, remove it for consistency #if image.shape[-1] == 4: # image = image[..., :3] return image
def detect_and_color_splash(model, image_path): # Run model detection and generate the color splash effect print("Running on {}".format(args.image)) # Read image #image = skimage.io.imread(args.image) image, header = utils.read_fits(filename=image_path, stretch=True, normalize=True, convertToRGB=True) # Detect objects r = model.detect([image], verbose=1)[0] # Color splash splash = color_splash(image, r['masks']) # Save output file_name = "splash_{:%Y%m%dT%H%M%S}.png".format(datetime.datetime.now()) skimage.io.imsave(file_name, splash)
def read_img(self): """ Read input FITS image """ res= utils.read_fits( self.image_path, stretch=False, normalize=False, convertToRGB=False ) if not res: logger.error("Failed to read image %s!" % self.image_path) return -1 self.img_data= res[0] self.img_header= res[1] self.nx= self.img_data.shape[1] self.ny= self.img_data.shape[0] logger.info("Input image %s has size %d x %d..." % (self.image_path,self.nx,self.ny)) return 0