next up previous contents
Next: 3.8.5 Blocking computation Up: 3.8 Joining operations together Previous: 3.8.3 Non-image output   Contents

3.8.4 Calculating twice

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.

Figure 3.6: Threshold an image at the mean value
\begin{figure}\begin{quote}
\begin{verbatim}int
threshold_at_mean( IMAGE *in, ...
... mean ) )
return( -1 );return( 0 );
}\end{verbatim}
\end{quote}
\end{figure}

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.


next up previous contents
Next: 3.8.5 Blocking computation Up: 3.8 Joining operations together Previous: 3.8.3 Non-image output   Contents
John Cupitt 2004-11-02