def __getitem__(self, index): image, label = self._make_img_gt_point_pair(index) seg = None if self.cfg.NO_TRANS == False: if 'seg' == self.cfg.TARGET_MODAL: seg = Image.fromarray((color_label_np( label_copy, ignore=self.ignore_label).astype(np.uint8)), mode='RGB') # seg = np.load(seg_path) seg = Image.fromarray(seg.astype(np.uint8), mode='RGB') sample = {'image': image, 'label': label, 'seg': seg} else: # print(image.size) sample = {'image': image, 'label': label} for key in list(sample.keys()): if sample[key] is None: sample.pop(key) # if self.transform: # sample = self.transform(sample) # return sample if self.split == "train": return self.transform_tr(sample) elif self.split == 'val': return self.transform_val(sample)
def __getitem__(self, index): example = self.examples[index] img_path = example["img_path"] # img = cv2.imread(img_path, -1) # (shape: (1024, 2048, 3)) image = Image.open(img_path).convert('RGB') # image = F.resize(image, (320, 640)) # resize img without interpolation (want the image to still match label_img_path = example["label_img_path"] label_img = Image.open(label_img_path).convert( 'L') # (shape: (1024, 2048)) # label_img = F.resize(label_img, (320, 640), interpolation=Image.NEAREST) label_img = convert(np.array(label_img)) # resize label_img without interpolation (want the resulting image to # still only contain pixel values corresponding to an object class): seg = Image.fromarray((color_label_np(label_img).astype(np.uint8)), mode='RGB') label = Image.fromarray(label_img.astype(np.uint8)) # depth = Image.open(depth_dir[idx]).convert('RGB') depth = None sample = {'image': image, 'depth': depth, 'label': label, 'seg': seg} # sample = {'image': image, 'depth': depth, 'label': label} if self.transform: sample = self.transform(sample) return sample
def __getitem__(self, idx): if self.phase_train: img_dir = self.img_dir_train depth_dir = self.depth_dir_train label_dir = self.label_dir_train else: img_dir = self.img_dir_test depth_dir = self.depth_dir_test label_dir = self.label_dir_test # label = np.load(label_dir[idx]) image = Image.open(img_dir[idx]).convert('RGB') # image_np = np.asarray(image) # depth = Image.fromarray(np.uint8(color_label_np(np.load(label_dir[idx]))), mode='RGB') # depth = Image.fromarray(color_label_np(np.uint8(np.load(label_dir[idx]))), mode='RGB') # depth = Image.open(depth_dir[idx]).convert('RGB') # label = np.uint8(np.maximum(_label, 0)) # label = Image.fromarray(label) # label = Image.fromarray(np.uint8(np.load(label_dir[idx]))) # label_np = np.asarray(label) _label = np.load(label_dir[idx]) _label_copy = _label.copy() for k, v in self.id_to_trainid.items(): _label_copy[_label == k] = v label = Image.fromarray(_label_copy.astype(np.uint8)) depth = Image.open(depth_dir[idx]).convert('RGB') seg = Image.fromarray((color_label_np(_label_copy).astype(np.uint8)), mode='RGB') # # if len(label)==530: # f = open('/home/lzy/ResNet_Backbone_segmentation/result','w') # for i in range(len(label)): # for j in range(len(label[0])): # f.write(str(int(label[i][j]))+' ') # f.write('\r') # f.close() # for i in range(1000000): # print(i) # cv2.imshow('label',label) sample = {'image': image, 'depth': depth, 'label': label, 'seg': seg} # sample = {'image': image, 'depth': depth, 'label': label} if self.transform: sample = self.transform(sample) return sample
def __getitem__(self, index): example = self.examples[index] image_path = example["img_path"] label_path = example["label_path"] seg_path = example["seg_path"] # image = np.load(img_path) # label = np.load(label_path) image = cv2.imread( image_path, cv2.IMREAD_COLOR) # BGR 3 channel ndarray wiht shape H * W * 3 image = cv2.cvtColor( image, cv2.COLOR_BGR2RGB ) # convert cv2 read image from BGR order to RGB order image = np.float32(image) label = cv2.imread(label_path, cv2.IMREAD_GRAYSCALE) # GRAY 1 ch # image = self.examples[index]["image"] # label = self.examples[index]["label"] label_copy = label.copy() for k, v in self.id_to_trainid.items(): label_copy[label == k] = v label = np.asarray(label_copy) # image=cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2BGR) seg = None if self.cfg.NO_TRANS == False: if 'seg' == self.cfg.TARGET_MODAL: seg = (color_label_np(label_copy, ignore=self.ignore_label, dataset='cityscapes').astype(np.uint8)) seg = cv2.cvtColor(np.asarray(seg), cv2.COLOR_RGB2BGR) # seg=np.load(seg_path) # seg = Image.fromarray(seg.astype(np.uint8),mode='RGB') # seg = self.examples[index]["seg"] sample = {'image': image, 'label': label, 'seg': seg} else: # print(image.size) sample = {'image': image, 'label': label} for key in list(sample.keys()): if sample[key] is None: sample.pop(key) if self.transform: sample = self.transform(sample) return sample
def __getitem__(self, index): image, label = self._make_img_gt_point_pair(index) label_copy = label seg = None if self.cfg.NO_TRANS == False: if 'seg' == self.cfg.TARGET_MODAL: seg = Image.fromarray((color_label_np(label_copy, ignore=self.ignore_label).astype(np.uint8)), mode='RGB') # seg = np.load(seg_path) if 'lab' ==self.cfg.TARGET_MODAL: seg=color.rgb2lab(image) sample = {'image': image, 'label': label, 'seg': seg} else: # print(image.size) sample = {'image': image, 'label': label} for key in list(sample.keys()): if sample[key] is None: sample.pop(key) return self.transform(sample)
def __getitem__(self, index): example = self.examples[index] # image = example["image"] # label = example["label"] image_path = example["image_path"] label_path = example["label_path"] image = cv2.imread(image_path, cv2.IMREAD_COLOR) #loadimage image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) image = np.float32(image) label = cv2.imread(label_path, cv2.IMREAD_GRAYSCALE) label = np.asarray(label) label = label - 1 # label_copy = label.copy() label_copy[label == -1] = 255 label = label_copy seg = None if self.cfg.NO_TRANS == False: if 'seg' == self.cfg.TARGET_MODAL: seg = (color_label_np(label, ignore=self.ignore_label, dataset=ade20k).astype(np.uint8)) seg = cv2.cvtColor(np.asarray(seg), cv2.COLOR_RGB2BGR) # seg=np.load(seg_path) # seg = Image.fromarray(seg.astype(np.uint8),mode='RGB') # seg = self.examples[index]["seg"] sample = {'image': image, 'label': label, 'seg': seg} else: # print(image.size) sample = {'image': image, 'label': label} for key in list(sample.keys()): if sample[key] is None: sample.pop(key) if self.transform: sample = self.transform(sample) return sample