Question

I am currently writing a Python program that retrieves the pixels from two BMP files and finds the percent difference between them (without using the Pillow library for the purpose of learning). I can think of two ways to approach this problem:

1) Read the pixels from each file in separate streams and compare the results as the files are being read.
2) Read the pixels from one file into a multi-dimensional list, read the pixels from the other into another multi-dimensional list, and then compare the resulting lists one-by-one.

Out of these two approaches, which would be a more efficient choice to tackling my goal? Or is there another approach which would be better? I am currently working on 256x256 24-bit BMPs and plan on introducing images with larger resolutions.

Was it helpful?

Solution

Reading data into an array requires allocating memory and means that you don't start comparing the data until you've finished loading the files. This, in theory, will take longer that comparing the data as it is read in. It also (naturally) requires more memory.

For such a small amount of data, this is not really a major concern however. Unless you are looking at really large files, it's likely going to be hard to notice a difference. Most people will find the array approach to be simpler to get right as well.

Licensed under: CC-BY-SA with attribution
scroll top