0

I'm trying to read images with OpenCV imread('Large Image') and it cannot allocate enough space for my image which is 25000 x 20000. I would like to store all of the red and blue pixels in there own array (don't really care about green) from this image do some math on them and reconstruct and image with these new values. Is there an alternative to OpenCV that can do what I would like?

My machine has 16gb, running windows 8.1 64 bit, and I'm using python. Thanks in advance for any advice.

BFlint
  • 2,407
  • 2
  • 16
  • 20
  • That's ~1.4GB for a single image. Wow... – karlphillip Dec 18 '14 at 16:45
  • What's the error message? – karlphillip Dec 18 '14 at 16:48
  • what format is it ? (maybe you're better off to parse it manually, and construct channels images while you read it) – berak Dec 18 '14 at 16:53
  • @karlphillip Yeah I could also have 3gb images. The error is OpenCV Error: insufficient memory (failed to allocate 1454069272 bytes) – BFlint Dec 18 '14 at 17:07
  • @berak the image is a TIF. Alright I'll look into that and see if that is possible – BFlint Dec 18 '14 at 17:08
  • no idea, but would it help to compile openCV with `/LARGEADDRESSAWARE` ? http://stackoverflow.com/questions/639540/how-much-memory-can-a-32-bit-process-access-on-a-64-bit-operating-system – Micka Dec 18 '14 at 17:14
  • 1
    I don't know if it is possible to work with images like this. An easy alternative, if you don't need global image to do your math processing, is to split your image in 4 parts for example. And then process on your 4 different parts. You can maybe look some sample algorithm from Android project judging by the fact that it's a common problem on this platform. – Alto Dec 19 '14 at 14:44

3 Answers3

1

One way would be to use HIPI Image processing interface with Hadoop and OpenCv. HIPI (http://hipi.cs.virginia.edu/about.html) can be utilized to cull the images into several smaller parts, run opencv processing and then rebuild the bigger image.

A nice setup guide can be found here :- https://techgimmick.wordpress.com/2015/06/24/how-to-use-opencv-with-hadoop-or-hipi-hadoop-image-processing-interface/

Ayon
  • 315
  • 3
  • 20
1

Libvips is designed for large images.

wl2776
  • 4,099
  • 4
  • 35
  • 77
  • The vips-from-python docs are here: http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/using-from-python.html – jcupitt Oct 11 '15 at 08:42
0

You could use the stream tool which is part of ImageMagick to extract any desired area of any desired band into a binary file like this.

Extract entire Red channel from 25,000x20,000 pixel file bigboy.tif:

stream -map r bigboy.tif red.bin

ls -l
-rw-r--r--  1 mark  staff  500000000  7 Sep 13:55 red.bin

Extract area 100x400 pixels at position 1000,2000 from Blue channel of bigboy.tif:

stream -map b -extract 100x400+1000+2000 bigboy.tif blue.bin
ls -l 
-rw-r--r--    1 mark  staff       40000  7 Sep 13:54 blue.bin

Equally, and maybe even more optimally, you could use vips to extract the Red band like this:

vips im_extract_bands bigboy.tif red.tif 1 1 --vips-leak
memory: high-water mark 241.32 MB

ls -l
-rw-r--r--    1 mark  staff  1000001466  7 Sep 14:35 red.tif
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432