If it is possible to do the image processing operations in tensor, that would be ideal. If not, you just have to know and write your own backward function to calculate gradients based on the operations you perform.
Refer about how to extend pytorch here: https://pytorch.org/docs/stable/notes/extending.html 47