In some circumstances, the same image data can be generated twice. Figure 3.6 is a function which finds the mean value of an image, and writes a new image in which pixels less than the mean are set to 0 and images greater than the mean are set to 255.
This seems straightforward -- but consider if image in
were a
"p"
, and represented the output of a large pipeline of operations. The
call to im_avg()
would force the evaluation of the entire pipeline,
and throw it all away, keeping only the average value. The subsequent call to
im_moreconst()
will cause the pipeline to be evaluated a second time.
When designing a program, it is sensible to pay attention to these
issues. It might be faster, in some cases, to output to a file before
calling im_avg()
, find the average of the disc file, and then run
im_moreconst()
from that.