def get_item(self, idx): label_url = self.get_label_url(idx) ori_url = self.get_original_url(idx) src_url = self.get_src_url(idx) gt = cv2.imread(label_url, 0) ori = cv2.imread(ori_url, 0) src = cv2.imread(src_url) if src.shape[0] != self.resize or src.shape[1] != self.resize: src = imutils.resize(src, width=self.resize) src = src[:self.resize, :self.resize] # ensure size if gt.shape[0] != self.resize or gt.shape[1] != self.resize: gt = imutils.resize(gt, width=self.resize) gt = gt[:self.resize, :self.resize] # ensure size gt = ((gt > 0) * 255).astype(np.uint8) if ori.shape[0] != self.resize or ori.shape[1] != self.resize: ori = imutils.resize(ori, width=self.resize) ori = ori[:self.resize, :self.resize] # ensure size gt = self.one2three(gt) obj = ObjectImageAndMaskTransform(src, gt.astype(np.float32) / 255) if self.transform: obj = self.transform(obj) obj = obj.to_dict() obj['ori'] = ori.astype(np.float32) / 255 return obj
def __getitem__(self, idx): image, label = self.data[idx] image_t = utility.to_channels(image, ch=self.num_channels) label_t = np.zeros((label.shape[0], label.shape[1], 2)) label_t[:, :, 0] = (label < 1) label_t[:, :, 1] = (label >= 1) obj = ObjectImageAndMaskTransform(image_t, label_t) if self.transform: obj = self.transform(obj) return obj.to_dict()
def __getitem__(self, idx): idx = idx % len(self.data) image, label = self.data[idx] image_t = utility.to_channels(image, ch=self.num_channels) label_t = (label > 127).astype(np.uint8) obj = ObjectImageAndMaskTransform(image_t, label_t) if self.transform: obj = self.transform(obj) return obj.to_dict()
def __getitem__(self, idx): idx = idx % len(self.data) image, label = self.data[idx] image_t = utility.to_channels(image, ch=self.num_channels) label_t = np.zeros_like(label) label_t[:, :, 0] = (label[..., 0] == 0) label_t[:, :, 1] = (label[..., 0] == 1) label_t[:, :, 2] = (label[..., 0] >= 2) obj = ObjectImageAndMaskTransform(image_t, label_t) if self.transform: obj = self.transform(obj) return obj.to_dict()
def __getitem__(self, idx): idx = idx%len(self.data) image, mask = self.data[idx] image_t = utility.to_channels(image, ch=self.num_channels ) label_t = np.zeros( (mask.shape[0], mask.shape[1], 2) ) label_t[:,:,0] = (mask < 0) label_t[:,:,1] = (mask > 0) obj = ObjectImageAndMaskTransform( image_t, label_t ) if self.transform: sample = self.transform( obj ) return obj.to_dict()
def __getitem__(self, idx): idx = idx % len(self.data) image, label, contours = self.data[idx] image_t = utility.to_channels(image, ch=self.num_channels) label_t = np.zeros((label.shape[0], label.shape[1], 3)) label_t[:, :, 0] = (label < 128) label_t[:, :, 1] = (label > 128) label_t[:, :, 2] = (contours > 128) obj = ObjectImageAndMaskTransform(image_t, label_t) if self.transform: obj = self.transform(obj) return obj.to_dict()
def __getitem__(self, idx): idx = idx % len(self.data) data = self.data[idx] if self.use_weight: image, label, weight = data elif self.load_segments: image, label, segs = data if self.shuffle_segments: segs = segs[..., np.random.permutation(segs.shape[-1])] else: image, label = data image_t = utility.to_channels(image, ch=self.num_channels) label = to_one_hot(label, self.num_classes) if self.use_weight: obj = ObjectImageMaskAndWeightTransform(image_t, label, weight) elif self.load_segments: obj = ObjectImageMaskAndSegmentationsTransform( image_t, label, segs) else: obj = ObjectImageAndMaskTransform(image_t, label) if self.transform: obj = self.transform(obj) obj = obj.to_dict() obj['segment'] = preprocessing.apply_preprocessing( obj['segment'], self.middle_proc) if self.load_segments: ## Warring! axis = np.argmin(obj['segment'].shape) if self.use_ori: if self.transform: inputs = torch.cat((obj['image'], obj['segment']), dim=axis) else: inputs = np.concatenate((obj['image'], obj['segment']), axis=axis) obj['image'] = inputs else: obj['image'] = obj['segment'] obj.pop('segment') return obj
def __getitem__(self, idx): idx = idx % len(self.data) data = self.data[idx] if self.use_weight: image, label, weight = data else: image, label = data label = (label == 255).astype(float) # 1024, 1024, 3, max= 1 # image: 1024, 1024, 3, max = 255 image_t = utility.to_channels(image, ch=self.num_channels) # image_t: 1024, 1024, 3, max = 255 if self.use_weight: obj = ObjectImageMaskAndWeightTransform(image_t, label, weight) else: obj = ObjectImageAndMaskTransform(image_t, label) if self.transform: obj = self.transform(obj) return obj.to_dict()