Use skimage transforms in PyTorch Transforms

I want to apply skimage’s Local Binary Pattern transformation on my data, and was wondering if there was any possibility of doing this inside my torch’s Transforms, which right now is the following:

data_transforms = {
    'train': transforms.Compose([
        transforms.CenterCrop(178),
        transforms.RandomHorizontalFlip(),
        transforms.ToTensor(),
        transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])
    ]),
    'val': transforms.Compose([
        transforms.CenterCrop(178),
        transforms.ToTensor(),
        transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5])
    ]),
}

If not, how would I implement it?

If you want to add the skimage transformation between other Image transformation, you could use the following code snippet as a base class and apply the desired transformation inside:

class MySkimageTransform(object):
    def __init__(self):
        '''
        initialize your transformation here, if necessary
        '''
        

    def __call__(self, pic):
        arr = np.array(pic) # transform to np array
        # apply your transformation
        pic = Image.from_array(arr)
        return pic
1 Like

Thanks for your help! It worked :slight_smile: