Consider rescaling (binning) large images
A binning 2x2 on large images would already speed up the program and reduced memory usage