>
|
|
>
|
|
>
|
|
>
|
|
The memory usage for this 480 x 640 x 3 layer image is
>
|
|
>
|
|
| (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.
>
|
|
Save the current memory usage.
>
|
|
| (2) |
Create the temporary image.
>
|
|
| (3) |
Extract layer 2, increase its gamma, then reinsert it, inplace, into the original image.
>
|
|
>
|
|
| (4) |
>
|
|
| (5) |
>
|
|
| (6) |
Do the same with layer 3, but decrease its gamma.
>
|
|
>
|
|
| (7) |
>
|
|
| (8) |
>
|
|
| (9) |
Compute the additional memory allocated.
>
|
|
| (10) |
Repeat the computation (actually, do its inverse), but use assignment statements rather than inplace and output to assign tmp and img.
>
|
|
| (11) |
>
|
|
>
|
|
| (12) |
>
|
|
| (13) |
>
|
|
| (14) |
>
|
|
>
|
|
| (15) |
>
|
|
| (16) |
>
|
|
| (17) |
>
|
|
| (18) |
The additional memory allocated is about three times that of the previous method, which used the inplace and output options.