I have question about array index
mriidx = self.mriids[idx] #img file name
maskidx = self.maskids[idx] #mask file name
mask_file = os.path.join(self.masks_dir, maskidx)
img_file = os.path.join(self.imgs_dir, mriidx)
img = Image.open(img_file).convert("RGB")
mask = Image.open(mask_file).convert("L")
mask = np.array(mask)
img = np.array(img)
print("img shape :", img.shape,'\n', "mask shape :", mask.shape)
obj_ids = np.unique(mask)
print('obj_ids :',obj_ids)
obj_ids = obj_ids[1:]
print('obj_ids[1:] shape :', obj_ids[1:].shape)
print('obj_ids[1:] :', obj_ids[1:])
and here are the two types of outputs I got
img shape : (256, 256, 3)
mask shape : (256, 256)
obj_ids : [0]
obj_ids[1:] shape : (0,)
obj_ids[1:] : []
img shape : (256, 256, 3)
mask shape : (256, 256)
obj_ids : [ 0 255]
obj_ids[1:] shape : (0,)
obj_ids[1:] : []
My first question is in the first output, obj_ids is [0].
then how is obj_ids[1:] not have error? isn’t it out of index range?
and my second question is in the second output.
why does obj_ids has additional space?
doesn’t it has to be [0 255] not [ 0 255]?