Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Ryan_Wong
Beginner
80 Views

Sample code for resizing huge image using tile-based ROI

Is there sample code for showing how to resize huge image (bigger than the system's memory size), when the huge image is stored on the disk and already broken up into 1024x1024 tiles, by using the ROI of ippiResize functions?

Thanks!
0 Kudos
3 Replies
SergeyKostrov
Valued Contributor II
80 Views

Quoting Ryan Wong
Is there sample code for showing how to resize huge image (bigger than the system's memory size), when the huge image is stored on the disk and already broken up into 1024x1024 tiles, by using the ROI of ippiResize functions?

Thanks!


An algorithm could look like thisand it isbasedon a geomatics related project I worked for:

1. There is a database with a list ofgeo-tiles,1024x1024 in total
2. Every geo-tile is 4096x4096 pixels ( 16-bits \4096x4096x2 bytes= 32MB )
3. Every geo-tile has to bedoubled in size( 16-bits \ 8192x8192x2 bytes = 128MB )
2. Allocate memory for 1024x1024 entries ( in-memory table of geo-tiles \ name is 8 bytes \ 8MB)
3. Read the list of geo-tilesfrom the database to the in-memory table of geo-tiles
4. Allocate 32MB buffer for a source geo-tile ( pSrcGeoTile )
5. Allocate128MB buffer for a destination geo-tile ( pDstGeoTile )
4. Start iterationsfor the in-memory table of geo-tiles
5. Load ageo-tile to pSrcGeoTile
6.Call ippiResize( pSrcGeoTile, pDstGeoTile, 2xWidth, 2xHight, INTERPOLATION )
7. Save the destination geo-tile from pDstGeoTile
8. Repeat 5, 6, 7 until end of the in-memory table of geo-tiles
9. Deallocate 128MB buffer
10. Deallocate 32MB buffer
11. Deallocate memory of in-memory table of geo-tiles

Best regards,
Sergey

Ryan_Wong
Beginner
80 Views

My project currently uses OpenCV to do the same.OpenCV provides an interpolation mode "CV_INTER_AREA" which does not require boundary pixels when the ratio between source length and destination length are whole integers.

(As an example, resizing from 4096x4096 to 1024x1024 (downscale by 4 on each dimension), maps each patch of 16x16 source pixel into a 1x1 destination pixel. There is no visible seams (image artifacts) at the tile boundaries.)

We were testing IPP to see if there is any speed improvement. However, since IPP does not implement an equivalent interpolation mode, we have to use the CV_ANTIALIASING mode. Unfortunately this mode has huge memory requirement that we cannot affort.

Two of my main concerns are:

  • Hoping to provide resize capability on arbitrary zoom ratios (not whole integers), with reasonable memory requirement.
  • When the output tiles are put together, they must not have any unpleasant tile seams at the boundary. I can provide the boundary pixels, but the API must have a way to accept them in the first place.

igorastakhov
New Contributor II
80 Views

Hi Ryan,

with current IPP API it is impossible to process a huge image by tiles as each call to Resize primitive will produce boundary artifacts. This inconvinience has been already fixed in the new Resize API version that will be available in the next major IPP release - it has "border" parameter that can be any of "replicate, mirror, const, etc." or "border is available in memory" - that makes possible to stich dst tiles correctly.

Regards,
Igor
Reply