1

I'm trying to compute the difference in pixel values of two images, but I'm running into memory problems because the images I have are quite large. Is there way in python that I can read an image lets say in 10x10 chunks at a time rather than try to read in the whole image? I was hoping to solve the memory problem by reading an image in small chunks, assigning those chunks to numpy arrays and then saving those numpy arrays using pytables for further processing. Any advice would be greatly appreciated.

Regards,

Berk

5
  • How large are the images and how much RAM do you have? Commented Feb 13, 2014 at 21:17
  • Images go up to 10 GB and I have 6GB of RAM. I want to avoid loading the images onto the RAM. Commented Feb 13, 2014 at 22:15
  • In which format are the images stored? Commented Feb 13, 2014 at 22:50
  • Another question, when you say that you want to compute the difference in pixel values, does it means that you want to compute the difference between every two pixels of two images of the same dimensions? Commented Feb 13, 2014 at 22:52
  • Img1_pixel(x,y) - Img2_pixel(x,y) for every pixel of two images of the same dimensions. Commented Feb 13, 2014 at 23:08

2 Answers 2

4

You can use numpy.memmap and let the operating system decide which parts of the image file to page in or out of RAM. If you use 64-bit Python the virtual memory space is astronomic compared to the available RAM.

Sign up to request clarification or add additional context in comments.

1 Comment

How does this help with comparing images? Images are typically stored as TIFF or PNG or something similar. How to convert these images into files that can be loaded via memmap in the first place?
2

If you have time to preprocess the images you can convert them to bitmap files (which will be large, not compressed) and then read particular sections of the file via offset as detailed here:

Load just part of an image in python

Conversion from any file type to bitmap can be done in Python with this code:

from PIL import Image
file_in = "inputCompressedImage.png"

img = Image.open(file_in)

file_out = "largeOutputFile.bmp"

img.save(file_out)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.