Reducing Memory Usage in ImageTools - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Graphics : Image Processing : ImageTools Package : ImageTools/reduce_memory

Reducing Memory Usage in ImageTools

 

Introduction

Options

Examples

Introduction

Because an image is stored as an rtable with datatype = float[8], each pixel in each layer requires eight bytes of memory. The memory allocated for large images can be significant. To reduce memory usage, many of the commands in ImageTools have the options inplace and output that permit reusing previously allocated memory. This help page shows how they can be used.

Options

• 

inplace = truefalse

  

Specifies whether the operation is performed in-place. The default is false.

• 

output = Image

  

Specifies a data structure into which the output is written. The size and number of layers must match that of the input. The output image is redimensioned so that its row and column indices match the input. The default is NULL.

Examples

withImageTools:

imgfilecatkerneloptsdatadir,/images/fjords.jpg:

imgReadimgfile:

Embedimg

The memory usage for this 480 x 640 x 3 layer image is

sizelengthimgkernelopts'wordsize''bit':

evalf[2]convertsize,units,mebibyte

7.0mebibyte

(3.1)

Assume that we want to adjust the gamma of layers 2 and 3 of img.  The Gamma command works on all layers, so to do this we need to extract a layer, make the adjustment, and insert the modified layer back into the image.  To reduce memory usage we can allocate a temporary grayscale image that is the size of one layer of the image and then reuse it as needed.  To determine the effect of these options, we compare the memory usage with that when the options are not used.  Assign a procedure that returns the memory allocated by the kernel.

memalloc→evalf[2]convertkernelopts'bytesalloc''byte',units,mebibyte:

Save the current memory usage.

memmemalloc

mem48.mebibyte

(3.2)

Create the temporary image.

tmpCreateHeightimg,Widthimg:memalloc

51.mebibyte

(3.3)

Extract layer 2, increase its gamma, then reinsert it, inplace, into the original image.

layer2:

GetLayerimg,layer,output=tmp:memalloc

51.mebibyte

(3.4)

Gammatmp,1.2,inplace:memalloc

51.mebibyte

(3.5)

SetLayerimg,tmp,layer,inplace:memalloc

51.mebibyte

(3.6)

Do the same with layer 3, but decrease its gamma.

layer3:

GetLayerimg,layer,output=tmp:memalloc

51.mebibyte

(3.7)

Gammatmp,0.8,inplace:memalloc

51.mebibyte

(3.8)

SetLayerimg,tmp,layer,inplace:memalloc

51.mebibyte

(3.9)

Compute the additional memory allocated.

memallocmem

3.mebibyte

(3.10)

Repeat the computation (actually, do its inverse), but use assignment statements rather than inplace and output to assign tmp and img.

memmemalloc

mem51.mebibyte

(3.11)

layer2:

tmpGetLayerimg,layer:memalloc

53.mebibyte

(3.12)

tmpGammatmp,11.2:memalloc

55.mebibyte

(3.13)

imgSetLayerimg,tmp,layer:memalloc

62.mebibyte

(3.14)

layer3:

tmpGetLayerimg,layer:memalloc

65.mebibyte

(3.15)

tmpGammatmp,10.8:memalloc

53.mebibyte

(3.16)

imgSetLayerimg,tmp,layer:memalloc

60.mebibyte

(3.17)

memallocmem

9.mebibyte

(3.18)

The additional memory allocated is about three times that of the previous method, which used the inplace and output options.

See Also

ImageTools

ImageTools[ImageTypes]

 


Download Help Document

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam