Reputation: 21
I downloaded a 150GB satellite .jp2 image, of which I only want a small section at a time. How would I go about tiling the image in manageable chunks? Just extracting a part of the image would also be enough.
As I'm only somewhat familiar with Python, I looked at the Pillow and OpenCV libraries, but without success as the image resolution exceeds their limits. I also looked into Openslide for Python, but couldn't get rid of an error (Could not find module 'libopenslide-0.dll').
Upvotes: 2
Views: 1047
Reputation: 13195
Grok JPEG 2000 toolkit is able to decompress regions of extremely large images such as the 150 GB image you linked to.
Sample command:
grk_decompress -i FOO.jp2 -o FOO.tif -d 10000,10000,15000,15000 -v
to decompress the region (10000,10000,15000,15000)
to TIFF format.
Upvotes: 1
Reputation: 11210
libvips can process huge images efficiently.
For example, with this 2.8gb test image:
$ vipsheader 9235.jp2
9235.jp2: 107568x79650 uchar, 4 bands, srgb, jp2kload
$ ls -l 9235.jp2
-rw-r--r-- 1 john john 2881486848 Mar 1 22:37 9235.jp2
I see:
$ /usr/bin/time -f %M:%e \
vips crop 9235.jp2 x.jpg 10000 10000 1000 1000
190848:0.45
So it takes a 1,000 x 1,000 pixel chunk out of a 110,000 x 80,000 pixel jp2 image in 0.5s and needs under 200mb of memory.
There are bindings for python, ruby, node, etc., so you don't have to use the CLI.
In python you could write:
import pyvips
image = pyvips.Image.new_from_file("9235.jp2")
tile = image.crop(10000, 10000, 1000, 1000)
tile.write_to_file("x.jpg")
It does depend a bit on the jp2 image you are reading. Some are untiled (!!) and it can be very slow to read out a section.
There are windows binaries as well, check the "download" page.
If you're on linux, vipsdisp can view huge images like this very quickly.
Upvotes: 4