arturkuchynski
arturkuchynski

Reputation: 980

Best Interpolation for grayscale segmentation mask

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.

enter image description here

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

Answers (2)

Primakov
Primakov

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

code-lukas
code-lukas

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:

Median filtered

Upvotes: 1

Related Questions