uci-cbcl / NoduleNet

[MICCAI' 19] NoduleNet: Decoupled False Positive Reduction for Pulmonary Nodule Detection and Segmentation
Other
185 stars 57 forks source link

Bug report and possible fix solution #49

Closed WeebOwO closed 1 year ago

WeebOwO commented 1 year ago

1. Bug description

when your input patch size are not equal in three axis, the current scale method in datasets/bbox_reader.py will go wrong because of it's padding size are not equal in x, y, z direction.

2. Possible fix solution

Origin solution:

if isScale:
          with warnings.catch_warnings():
              warnings.simplefilter("ignore")
              crop = zoom(crop,[1,scale,scale,scale],order=1)
          newpad = self.crop_size[0]-crop.shape[1:][0]
          if newpad<0:
              crop = crop[:,:-newpad,:-newpad,:-newpad]
          elif newpad>0:
              pad2 = [[0,0],[0,newpad],[0,newpad],[0,newpad]]
              crop = np.pad(crop,pad2,'constant',constant_values =self.pad_value)
          for i in range(4):
              target[i] = target[i]*scale
          for i in range(len(bboxes)):
              for j in range(4):
                  bboxes[i][j] = bboxes[i][j]*scale

My fix:

if isScale:
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                crop = zoom(crop,[1,scale,scale,scale],order=1)
            newpad = np.array(self.crop_size)-np.array(crop.shape[1:])
            if newpad[0] < 0 or newpad[1] < 0 or newpad[2] < 0:
                crop = crop[:,:-newpad[0],:-newpad[1],:-newpad[2]]
            elif newpad[0] > 0 or newpad[1] > 0 or newpad[2] > 0:
                pad2 = [[0,0],[0,newpad[0]],[0,newpad[1]],[0,newpad[2]]]
                crop = np.pad(crop, pad2,'constant', constant_values = self.pad_value)
            for i in range(4):
                target[i] = target[i]*scale
            for i in range(len(bboxes)):
                for j in range(4):
                    bboxes[i][j] = bboxes[i][j]*scale