Search code examples
pythonimage-maskingimage-thresholding

Threshold segmentation in area defined by mask


I am having a problem with segmentation. I have an image (74, 78, 75) and mask (512, 512, 97). I would like to threshold all intensity values in the image above 500, but confine it to the area defined by the mask (pixels with non-zero values).

newMask = np.zeros(image.shape)
newMask = np.where(image[np.any(mask != 0)] > 500)

The above logical operation returns a tuple, instead of an array. What i am i doing wrong? Cheers


Solution

  • mask[mask==0] = np.nan
    maskedIm = np.ma.masked_where(mask == 0, mask)