Loading Large Images in Qt
-
Hello,
I am new to Qt and am looking to load an image of 18806 x 19794 pixels (467MB). My objective is to create a software that could manipulate large images.
I tried loading the entire image as a QPixmap inside a scene but I got an "Out of memory exception" and the application crashed.
Is there some kind of function or library for Qt that could handle large images (like tile rendering or something) ? What's the best way of achieving such a task?
Thanks
-
Hi and welcome
That is pretty massive image so you will need 64 bit machine ( for really huge)
and you need a library to help with it.This i never tested myself but heard it loads huge files easy.
http://www.vips.ecs.soton.ac.uk/index.php?title=Libvips#Main_featuresIt says it can manipulated 10 GB image on 32 bit :)
-
@zed962 said in Loading Large Images in Qt:
Is there some kind of function or library for Qt that could handle large images (like tile rendering or something) ? What's the best way of achieving such a task?
Loading the whole image inside a QPixmap (= into memory) is completely overkill and also you probably wouldn't need 99% of the data.
As you already mentioned you might only work on parts of the image currently needed. Such a heavy image-related task goes beyond the purpose of Qt.But if you can with basic support you may want to try QImageReader class. It's capable of reading the image-size and retrieve parts of the image (tiling) by specifying cliprect. But it heavily depends on the image format. Read this.
-
@raven-worx Many thanks for the suggestion! I ended up creating my own tiling process for large images (Reading the image, dissecting it to multiple tiles and loading tiles accordingly). Gonna try QImageReader as it looks promising.
-
@raven-worx QImageReader didn't work for me when it comes to that size of image. I tried it with smaller images and it worked. I think I'll upgrade my machine to 64-bit to support more RAMs on my laptop.
-
@zed962 If your image is JPEG, QImageReader should work if you use QImageReader::setScaledSize and/or QImageReader::setScaledClipRect
For PNG scaled size may not work, though clip rect should. This doesn't mean that huge PNG cannot be loaded with on the fly scaling, the most trivial version of this algorithm is to keep only selected pixels from each line. You can implement it with direct use of libpng, but it will lead to visual artifacts ("moire"). Maybe there is more clever ready to use algorithm somewhere though, but not in Qt
-
@zed962 BTW if you are working with so large images it might be better to use more scalable image format, like JPEG2000, where you can encode low-resolution overview and tiled high-resolution image in the same file without data duplication, and decode them separately. But Qt won't help you with it, it doesn't even support OpenJPEG
-
@Konstantin-Tokarev said in Loading Large Images in Qt:
But Qt won't help you with it, it doesn't even support OpenJPEG
There is a Jpeg2000 imageformat plugin available (it used Jasper lib though)
-
@raven-worx Jasper is dead and supports only subset of J2K format
-
@Konstantin-Tokarev My image is GeoTIFF (mainly a satellite image)
-
This post is deleted!