def show(self, idx): img_land = imread(self._landpath % self.ids[idx]) img_seg = imread(self._segpath % self.ids[idx]) img_edge = vision.shift_edge(img_seg) f, (ax1, ax2, ax3) = plt.subplots(1, 3, sharey=True, figsize=(12, 4)) f.suptitle('Sample-{} in NewZealand Dataset'.format(idx)) ax1.imshow(img_land) ax1.set_title('Land Sample') ax2.imshow(img_seg, 'gray') ax2.set_title('Segmap Sample') ax3.imshow(img_edge, 'gray') ax3.set_title('Edge Sample') plt.show()
def __getitem__(self, idx): src_file = self.srcpath % self.datalist[idx] tar_file = self.tarpath % self.datalist[idx] src = imread(src_file) tar = imread(tar_file) assert len(tar.shape) == 2, "Mask should be 2D." tar = vision.shift_edge(tar, self.tar_ch) # src => uint8 to float tensor src = (src / 255).transpose((2, 0, 1)) src = torch.from_numpy(src).float() # tar => float to float tensor tar = tar.transpose((2, 0, 1)) tar = torch.from_numpy(tar).float() sample = { "src": src, "tar": tar, } return sample
def __getitem__(self, idx): img_id = self.ids[idx] img_land = imread(self._landpath % img_id) img_land = (img_land / 255).astype('float32') img_seg = imread(self._segpath % img_id) img_edge = vision.shift_edge(img_seg) # img_seg = rgb2gray(img_seg) # img_edge = np.expand_dims(vision.canny_edge(img_seg), dim=-1) # img_edge = (img_edge / 255).astype("float32") img_seg = (np.expand_dims(img_seg, -1) / 255).astype('float32') img_edge = (np.expand_dims(img_edge, -1) / 255).astype('float32') img_land = img_land.transpose((2, 0, 1)) img_seg = img_seg.transpose((2, 0, 1)) img_edge = img_edge.transpose((2, 0, 1)) return img_land, img_seg, img_edge