Medical-SAM2 icon indicating copy to clipboard operation
Medical-SAM2 copied to clipboard

Flipping XY on interaction simulation.

Open lihaowei1999 opened this issue 9 months ago • 1 comments

In func_2d.util.random_click, the clicked point is generated as:

def random_click(mask, point_label = 1):
    max_label = max(set(mask.flatten()))
    if round(max_label) == 0:
        point_label = round(max_label)
    indices = np.argwhere(mask == max_label) 
    return point_label, indices[np.random.randint(len(indices))]

whew np.argwhere returns coordinate in sequence of row-col. However, sam2 requires input as x-y sequence. In tutorial for (sam2 finetuning), the x,y is flipped as:

coords = np.argwhere(eroded_mask > 0)
   if len(coords) > 0:
       for _ in inds:  # Select as many points as there are unique labels
           yx = np.array(coords[np.random.randint(len(coords))])
           points.append([yx[1], yx[0]])

   points = np.array(points)

Is this a possible bug or have I misunderstood anything?

lihaowei1999 avatar Mar 02 '25 08:03 lihaowei1999

I believe this is a bug but is only for 2D training. The random_click for 3D training is fixed, while the 2D version is left here unchanged.

lihaowei1999 avatar Mar 03 '25 05:03 lihaowei1999