This tutorial 6 should give you a simple example how to write a custom Dataset.
The __getitem__ method will accept an index in the standard use case, which is used to load, process, and return the sample (and target if possible).
You can use other libraries such as PIL to load the image and apply any preprocessing on this sample you like.
The DataLoader will then create a batch of all returned samples for the current indices.