How to efficiently display a 600 megapixel image

I have a process creating images with high resolution 600+ MP. These images are about 2 GB when loaded into RAM (40 MB with a high compression ratio). I index them and make them available through a PHP web application.

I have data that tells me areas of interest in pixel units, so I'm curious if there is a method in which I could read a specific area of ​​the image without loading all the stuff into memory. This is like navigating a file pointer, but a choice to read. The goal would be to create a small picture of the area of ​​interest.

I know that in PHP there are several image processing libraries, and for Python there are several, but I really do not know what the right question to ask regarding libraries.

I am really looking for a solution in PHP or Python specifically

+4
source share
2 answers

php-vips will only read the part you need when possible. It is usually 3x to 5x faster than imagemagick and requires much less memory.

Many image formats do not allow random access. JPEG, PNG, GIF, and many others will make you decompress at least the pixels in front of the pixels you want for the huge sorting images you process will be very slow.

TIFF JPEG. ( ) 256x256 . TIFF , .

, JPEG JPEG libvips, :

$ time vips copy wac_nearside.jpg wac_nearside.tif[tile,compression=jpeg]
real    0m3.891s
user    0m6.332s
sys     0m0.198s
peak RES 40mb

, :

$ ls -l wac_nearside.* 
-rw-r--r-- 1 john john 74661771 May  7  2015 wac_nearside.jpg
-rw-r--r-- 1 john john 76049323 Feb 24 15:39 wac_nearside.tif
$ vipsheader wac_nearside.jpg wac_nearside.jpg: 24000x24000 uchar, 1 band, b-w, jpegload

PHP :

#!/usr/bin/env php
<?php

require __DIR__ . '/vendor/autoload.php';

use Jcupitt\Vips;

$image = Vips\Image::newFromFile($argv[1]);

$region_width = 100;
$region_height = 100;

for ($i = 0; $i < 100; $i++) {
    $left = rand(0, $image->width - $region_width - 1);
    $top = rand(0, $image->height - $region_height - 1);
    $region = $image->crop($left, $top, $region_width, $region_height);
    $region->writeToFile($i . ".jpg");
}

:

$ time ./crop.php ~/pics/wac_nearside.tif 
real    0m0.207s
user    0m0.181s
sys     0m0.042s
peak RES 36mb

, ( ) 100 JPEG 0.2 .

+1

, ImageMagick, Java , - .

, , , " " https://www.imagemagick.org/script/command-line-processing.php , ( AoI ).

+2

Source: https://habr.com/ru/post/1693955/


All Articles