Reputation: 980
Suppose I need to resize grayscale segmentation mask which contains only two colors: 255 and 0. The resize itself in my case can be applied both for downscaling and upscaling the mask.
For example,cv2.INRER_AREA
interpolation sometimes can color pixels in 254,253
color near the white area, and put 2,3,4...
near black area.
Which interpolation should be used to obtain a resulting mask without but keep the colors I need?
Or It's better to mark all white pixels with 1, i.e. to use a binary/bolean mask?
Upvotes: 1
Views: 2655
Reputation: 316
I would definitely suggest cv2.INTER_BITS.
You can try to calculate DICE coefficient with the new mask(upsampled->downsampled to original shape) to see how good is your interpolation method.
Upvotes: 1
Reputation: 1651
If you only have two values anyway, pay attention if you use the bool
dtype, as not all image processing operations will be supported.
Something that is both easy and fast is to filter your image with a median filter to fill in gaps. (This is admittedly a little lazy but has produced good results for me in the past).
If you want to interpolate with your uint8
range, maybe thresholding afterwards will do the trick for your.
Edit: This is what a median filter produces:
Upvotes: 1