def get_segmentations(self, img_id): img_id_str = self.get_str_id(img_id) run_name = img_id_str.split('_')[0] gt_fname = os.path.join( self.gt_folder, run_name, img_id_str + '_{}_instanceIds.png'.format(self.gt_subfolder)) gt_img = cv2.imread(gt_fname, -1) if gt_img is None: log.warning('GT image does not exist: "{}"'.format(gt_fname)) # raise Exception('Image file not exist: "{}"'.format(gt_fname)) segm = [] colors = [] else: # log.warning('GT image does exist: "{}"'.format(gt_fname)) segm, colors = sep_labels.get_separate_labels(gt_img) sem_segm = [None] * 8 segm_final = [] segm_sem_cls = [] for ss, cc in zip(segm, colors): if cc > 1000: sem_cls = int(np.floor(cc / 1000)) ins_id = int(cc) % 1000 label = self.id_to_label[sem_cls] if label.trainId > 0: sem_cls_train = label.trainId segm_final.append(ss) if sem_segm[sem_cls_train - 1] is None: sem_segm[sem_cls_train - 1] = np.zeros(ss.shape) sem_segm[sem_cls_train - 1] = np.maximum(sem_segm[sem_cls_train - 1], ss) segm_sem_cls.append(sem_cls_train - 1) return segm_final, sem_segm, segm_sem_cls
def get_segmentations(self, img_id): img_id_str = self.get_str_id(img_id) fname = '{}.png'.format(img_id_str) gt_fname = os.path.join(self.gt_folder, fname) if not os.path.exists(gt_fname): raise Exception('GT file not exists: {} or '.format(gt_fname)) gt_img = cv2.imread(gt_fname) segm, colors = sep_labels.get_separate_labels(gt_img) if len(segm) > 0: sem_segm = [np.zeros(segm[0].shape)] for ss in segm: sem_segm[0] = np.maximum(ss, sem_segm[0]) else: sem_segm = [] return segm, sem_segm, [0] * len(segm)
def get_segmentations(self, img_id): img_id_str = self.get_str_id(img_id) run_name = img_id_str.split("_")[0] if self.semantic_only: gt_fname_suffix = "labelIds.png" else: gt_fname_suffix = "instanceIds.png" gt_fname = os.path.join( self.gt_folder, run_name, img_id_str + "_{}_{}".format(self.gt_subfolder, gt_fname_suffix)) gt_img = cv2.imread(gt_fname, -1) if gt_img is None: log.warning("GT image does not exist: \"{}\"".format(gt_fname)) segm = [] colors = [] else: segm, colors = sep_labels.get_separate_labels(gt_img) sem_segm = {} segm_final = [] segm_sem_cls = [] for ss, cc in zip(segm, colors): if cc > 1000: sem_cls = int(np.floor(cc / 1000)) ins_id = int(cc) % 1000 else: sem_cls = cc ins_id = 0 label = self.id_to_label[sem_cls] if label.trainId >= 0: sem_cls_train = label.trainId segm_final.append(ss) if sem_cls_train not in sem_segm: sem_segm[sem_cls_train] = np.zeros(ss.shape) sem_segm[sem_cls_train] = np.maximum(sem_segm[sem_cls_train], ss) segm_sem_cls.append(sem_cls_train) return segm_final, sem_segm, segm_sem_cls