Passing Different Interpolation Parameters for Images and Masks in Custom Augmentation Function

Dear All,

I’m currently working on a custom augmentation function and I have a question regarding passing different parameter values to a tuple of image and mask for transformations. In the code snippet provided below, I am using the GridDistortion function to augment both the image and the mask. However, I would like to pass interpolation=1 for the image and interpolation=0 for the mask in a single call to aug_raw = self.gd(image=np.array(aug_img), mask=np.array(aug_msk)).

class Transformation(ItemTransform):
    split_idx=0 #training
    order=2 #after resize
    def __init__(self,augs_img):
        self.augs_img=augs_img
        self.gd =G.GridDistortion(normalized=True,border_mode=0,distort_limit=0.5,p=0.5)
  
    def encodes(self, x):
        img,msk=x
        aug_img=PILImage.create(np.array(img))
        aug_msk=PILMask.create(np.array(msk))
       
        for aug in self.augs_img:
            aug_img = aug(image=np.array(aug_img))['image']
        
        aug_raw = self.gd(image=np.array(aug_img), mask=np.array(aug_msk))
        
        return PILImage.create(aug_raw['image']),PILMask.create(aug_raw['mask'])

I would greatly appreciate any guidance or suggestions on how to achieve this. Thank you in advance for your assistance.

Best regards,
Bilal

I managed to address this issue by implementing self.gd_img and self.gd_msk functions, each with a specific interpolation value of 1 and 0, respectively. I invoked these functions independently for the image and mask, while ensuring to set the random seed before making the method calls. It worked like a charm.