Abstract:
A post-processing method and apparatus to produce focus/defocus effects in computer generated images of three dimensional objects. A convolution filter stores pixel values (V) and associated depth values (Z) with a filter kernel being selected from a look-up table in dependence of the depth of the centre pixel (Z c ) in relation to a specified focus depth (P). To minimize spurious effects where filter kernels overlap objects at different depths in the image, an inhibition function stage varies the amount by which each pixel contributes to the kernel in dependence on that pixel&#39;s depth value (Z) and the centre pixel and focus depth values (Z c  and P). Inhibition profiles over a range of contributing and centre pixel values are provided.

Description:
The present invention relates to a method and apparatus for modifying computer generated images and, in particular, for simulation of focusing/defocusing effects in three-dimensional images for display in two dimensions. 
     BACKGROUND OF THE INVENTION 
     Synthetically generated computer graphics images normally suffer from the deficiency of being uniformly sharp, i.e. all parts of the image appear to be in focus. This is an un-natural effect, but simulating the effects of focus/de-focus is often highly expensive both in terms of computational power and memory bandwidth. An example of such a technique is described in &#34;Synthetic Image Generation with a Lens and Aperture Model&#34; by M. Potmesil and I. Chakravarty, ACM Transactions on Graphics Vol.1, No.2, April 1982 at pp.85-108. The Potmesil technique is an extension of earlier ray-tracing methods (modelling light propagation as infinitely thin rays travelling in straight line paths) that allows the inclusion of a camera/lens/aperture model. This is a computaticnally expensive technique which is impractical for real-time systems: a minimum time to generate an image at minimum distortion (highest aperture number) in excess of two and a half minutes is quoted, with processing time increasing as the aperture number is reduced. 
     An alternative and simpler technique is described in &#34;Two 2D Postprocessing Tools and their Applications to Improvement of 3D Pictures&#34; by J-F. Colonna, The Visual Computer (1994), at pp.239-242. Colonna describes a post-processing tool which uses a variable length convolution filter to provide an impression of depth in an image by increasing variation in filter length at increasing distance along the z-axis (towards foreground or background) from a focus depth. A particular problem likely to be encountered occurs at sharply receding surfaces and depth discontinuities, for example at the edge of a foreground object overlying a distant background: including in the filter kernel pixels of widely differing depth values can lead to inaccuracies and these will become particularly noticeable for objects at or close to the focus depth. 
     Accordingly, it is an object of the present invention to provide a computationally inexpensive technique that does not suffer from effects caused by depth discontinuities. 
     SUMMARY OF THE INVENTION 
     In accordance with the present invention there is provided a method for post-processing a computer-generated image of a three-dimensional object for display as a series of pixels, having a respective depth value for each pixel and a focus depth specified for each image frame, wherein each image pixel is filtered using contributions from other pixels of the image about the image pixel and with filter coefficients determined by the image pixel depth value and focus depth, characterised in that filter contributions are selectively inhibited by an amount determined, for each contributing pixel, by an inhibition function. This inhibition function may suitably relate the contributing pixel depth value, the image pixel depth value, and the focus depth. 
     By controllably varying the level of contributions from pixels the previously mentioned problems at depth discontinuities may be avoided. In order to improve the appearance further, the boundaries of near (out-of-focus) objects with middle-distance focused objects should be somewhat blurred whilst boundaries between middle distance in-focus objects and background (unfocused) objects should be sharp. To achieve this the inhibition function may set a predetermined minimum inhibition level for all filter contributions when the image pixel depth value is less than the focus depth. 
     For image pixel depth values greater than or equal to the focus depth, inhibition is preferably set to a maximum level (such as 1) for contributing pixels having a depth value substantially the same as the focus depth. This however would be reduced as contributing pixel depth diverges from the focus depth until inhibition reaches a predetermined minimum level (suitably 0) or the contributing pixel and image pixel depth values are coincident following which the inhibition level is constant for all contributing pixels further from the focus depth. Such an inhibition profile, together with means for implementing it, will be discussed hereinafter with reference to an exemplary embodiment. 
     A maximum and minimum field depth may be specified (within which range all pixel depth values lie) with reduction in inhibition level being substantially linear from the maximum value at the focus depth to the minimum level at each of the maximum and minimum field depth values. Alternatively, a focus field may be specified with maximum and minimum focus field depth values at respectively greater and lesser depths than the focus depth. With such a focus field, reduction in inhibition level is substantially linear from the maximum value at the focus depth to the minimum value at each of the maximum and minimum focus field depth values. The focus field may suitably be defined in terms of the focus depth, for instance as a predetermined depth range having the focus depth at its centre. This would reduce the amount of recalculation necessary for the inhibition profile as a result of a change in the focus depth. The filtering of each image pixel may suitably comprise convolution filtering, with the filter kernel taking contributions from pixels close to the image pixel. 
     The present invention also relates to image processing apparatus for effecting the above-mentioned method which, together with further features and advantages of the present invention, is described in the following pages of description and claims to which reference should now be made. 
    
    
     BRIEF DESCRIPTION OF THE DRAWINGS 
     Preferred embodiments of the present invention will now be described, by way of example only, and with reference to the accompanying drawings in which: 
     FIG. 1 represents variation in the rate of increase of blurring in relation to field depth; 
     FIG. 2 shows an arrangement of buffer memories in relation to a convolution filter embodying the present invention; 
     FIG. 3 schematically illustrates the operational stages of the filter of FIG. 1; 
     FIG. 4 schematically illustrates further features of the kernel selection stage of FIG. 3; 
     FIGS. 5 and 6 show variation in inhibition of filter kernel pixel contributions in relation to pixel and focus depth; 
     FIG. 7 is a flow chart representing the inhibition selection process in the filter function stage of FIG. 3; and 
     FIG. 8 shows a hardware implementation of the flow chart of FIG. 7. 
    
    
     DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS 
     The following description assumes that an image has been rendered with traditional Z-buffering techniques as described in, for example, &#34;Computer Graphics: Principles and Practice&#34; by Foley, van Dam, Feiner and Hughes, 2nd Edition (1990), published by Addison-Wesley, ISBN 0-201-12110-7, at pages 668-672. Such techniques will be familiar to the skilled practitioner and, for the purposes of illustrating the present invention, it will be sufficient to consider that for each pixel we have a set of values V representing the colour of an individual pixel, and that for that pixel we also have the value Z representing the z, or depth value of that pixel. 
     Specifying a point of focus P (a depth value at the place in the image that the observer is looking at), in order to give the appearance of focus/de-focus it is assumed that for pixels in the image with depth close to that of the point of focus the image should be sharp, but, as the depth of a pixel gets further away from the depth of the point of focus (whether nearer or closer to the position of the observer) then the image should become more blurred. The extent of blurring for any given deviation from the point of focus P would be determined by a further value, the depth of field D. The depth of field D is the difference between the maximum and minimum z-values supported and suitably the increase in the extent of blurring is greater for small magnitudes of D. As shown in FIG. 1, for a specified maximum extent of blurring, the blurring will increase more rapidly for a set shift in depth when the magnitude of D is smaller (D 1  =Z max1  -Z min1 ) than for a larger depth of field (D 2  =Z max2  -Z min2 ). 
     The technique for giving the appearance of focus/de-focus applies a convolution filter at each pixel in the image: an explanation of the general technique of convolution filtering may be found in the above-mentioned textbook of Foley et al at pages 628-634. This filter is chosen, for each pixel, such that at pixels in the image with depth close to that of the point of focus P the filter has little or no effect. As the depth of a pixel gets further away from the depth of the point of focus the filter should blur the image more and more as shown in FIG. 1. This corresponds to applying a variable length (in x and y) blurring filter across the image to the values V at each pixel, with the length of the filter adapting on the basis of a comparison of the depth value of the object of interest with the depth value of the point of focus. 
     We have appreciated that it may not be visually acceptable to apply a filter that combines the values of objects that are not at the same z-value. At a pixel whose depth value differs substantially from P, the convolution filter is chosen to have a large area so that considerable defocusing is attained. However, if the convolution area extends to nearby pixels which represent an object close to the point of focus, such pixels will generally be suppressed from the filter since their image should remain sharply in focus although this does not always hold true as will be described below. Generally, the filter for each pixel is formed based upon whether or not the depth value of the pixels to be included in the convolution filter (Z i ) is similar to that of the depth value of the pixel at which the filter is to be applied (Z c ). Specifically, the coefficient factor of each input pixel to the convolution filter is weighted by an inhibition value determined by a function relating the input pixels Z i  and Z c  and the point of focus P. A suitable function will be described in detail below. 
     The processing required to implement the blurring algorithm is applied as a post-processing technique, that is to say to a complete generated picture. It could be performed, for example, as the image is read out of the display buffer to the screen. In synchronisation, the depth values for the pixels would also be read from the Z-buffer memory. As will be appreciated, this requires that the Z-buffer memory be double-buffered in the same way that the display buffer is, so that Z values remain available for the displayed frame, while the next frame is being generated. 
     FIG. 2 shows the arrangement of the double frame buffer 10, the double Z-buffer 12 and convolution filter 14, with the buffers receiving respective outputs from an image source 16 and the convolution filter 14 outputting a stream of modified output pixel values V&#39; to a display. The frame buffer and Z-buffer have substantially identical capacities: for a 384×256 pixel screen, with 3 bytes per pixel (for RGB), approximately 60k bytes are required to store two full frames. The corresponding 3 bytes (24 bits) allocated per Z-value is sufficient to allow for relatively fine depth resolution. Further inputs 18,20 to the convolution filter 14 are shown for the point of focus P and the depth D respectively. These values may be determined by the system or one or both may be input by a user in which case inputs 18 and 20 would be connected to receive signals from a suitable user input device such as a keyboard. A further (optional) input 38 for a range value R (the function of which will be described below) is shown in dashed lines: as with P and D, R may be set by the system or a user. Typically, the values of P and D (and R) will remain constant for a frame, although it would be possible to alter their values over specific sub-regions of an image if the effect were desired. 
     The action of the convolution filter may be represented by ##EQU1## where V&#39;=output pixel value Z=input pixel depth values 
     F=filter inhibition function 
     i=all input pixels to convolution kernel. 
     V=input pixel value 
     P=point of focus depth value 
     k=coefficient of chosen filter kernel. 
     In block diagrammatic form, the convolution filter 14 is shown in detail in FIG. 3. The convolution kernel is of some arbitrary size, covering i pixels, and might for example be a 5×5 pixel area. Inputs from the V and Z buffers (10,12: FIG. 2) are fed to respective line stores 22,24. Assuming conventional frame-buffer read-out, the line stores are required to have sufficient capacity to hold enough complete display lines of pixels to allow for the filtering operation. 
     The i depth values of the convolution kernel, including that of a current pixel Z c , are read out of the Z line store 24 to a function stage F(Z,P) 26 to be described below. The current pixel value Z c  is also passed to a kernel selection stage 28 together with the input P and D values. 
     The kernel selection stage, shown schematically in FIG. 4, has a first stage 30 determining a relational value between Z c  and P: the stage may comprise a simple divider to output a ratio of the respective depth values. A second stage 32 generates an address based on the first stage output and depth of field D which address is passed to a look-up table (LUT) 34 causing the LUT to output a numerical value to a further LUT 36 of coefficients (FIG. 3). 
     The coefficient look-up table 36 contains an arbitrary number of complete sets of filter kernels, for application to pixels near, far, and further from the point of focus. For pixels at a depth equal to the point of focus P, the kernel would have zero values at all locations other than the centre pixel, which would have a coefficient of unity, and this kernel would thus have no effect on those pixels at the point of focus. Kernels for pixels further from P would have a progressively greater blurring effect. 
     The controlled suppression (inhibition) of filter kernels will now be described with reference to FIGS. 5 and 6 which show the inhibition profiles for kernel centre pixels (also referred to as current or image pixels) having a depth Z c  respectively greater than (or equal to) and less than the focus depth P. The two profiles are necessary to give a visually accurate effect at points where objects at different depths overlap. Specifically, the border between an out-of-focus foreground object and an object in focus at middle distance should be blurred, whereas the border between an in-focus object at middle distance and an out-of-focus background object should be sharp. 
     The inhibition factor I ranges from 0 (no inhibition or reduction in a pixel&#39;s contribution to the kernel) to 1 (full inhibition). For all cases where Z c  is less than P, that is to say filter kernels centred on a foreground out-of-focus object, I=0 and no pixels are inhibited from the kernel, as shown in FIG. 6. 
     Where the kernel is centred on a pixel at or behind the focus depth P, the inhibition profile will follow the form of FIG. 5 in which four profiles (for four different values of Z c ) are shown. For all profiles, inhibition is maximised (I=1) for contributing pixels at the focus depth P: this prevents blurring at the focus depth and, where Z c  is centred on an object behind P, inhibiting contributions from objects at the focus depth maintains the sharp border. Similarly for all profiles, the extent of inhibition of contributions from pixels in front of the focus depth is gradually reduced as the distance from P increases. A linear reduction in I is shown at f1 which is preferred for ease of implementation although a more optically appropriate reduction would be an exponential or similar reduction as shown in dashed lines at f2. 
     For contributing pixels from between P and Z c  the extent of inhibition follows a linear reduction as the distance from P increases until the contributing pixel depth equals Z c  following which all pixels are treated to the same level of inhibition. In this way, pixels in the far background (greatest depth) will have less effect where Z c  is close to P but increasing effect as Z c  recedes towards the blurred background. 
     Whilst the linear reduction of I on either side of P may be effected by ramping down from I=1 at P to I=0 at the foremost (D min ) and rearmost (D max ) extents of the field depth, a preferred alternative is to specify a focus range R over a predetermined range of depth values suitably centred on P. The value of R may be input by a user or calculated by the system, possibly taking into account P (making half of R equal to the distance from P to the nearer of D max  and D min ) or D (specifying R as, for example, 80% of D). Having R centred on P achieves the simplification of having the same reduction gradient (although reversed) on either side of P which gradient does not alter as the focus depth varies. The benefit of this simplification will become more apparent hereinafter in respect of a hardware implementation of the function stage. 
     The operation of the function stage to select and implement the appropriate inhibition profile is shown by the flowchart of FIG. 7. In a first step 100, the special case of Z c  being less than P is checked and, if true, I is set to zero (at 102) for all kernel contributions as in FIG. 6. If step 100 does not hold, a check is made (steps 104,108) to see whether the contributing pixel depth value lies outside the focus range R and, if so, I is set to zero for that pixel (steps 106,110) as can be seen in FIG. 5. The next steps (112,116) determine where the pixel lies in relation to P and Z c  and set I accordingly (at steps 114,118 or 120). Finally, an iteration loop (122,124) causes the process to be repeated from step 104 onwards until the values of I have been determined for all i pixels in the kernel. 
     Accordingly, the inhibition profile of FIG. 5 (for Z c  behind P) may be specified as shown in Table 1 below for increasing values of z from D min  to D max   
     
                       TABLE 1______________________________________z           I______________________________________D.sub.min  to R.sub.min       0R.sub.min  to P       (z - R.sub.min) · 1/(P - R.sub.min)P to Z.sub.c       (R.sub.max  - z) · 1/(R.sub.max  - P)Z.sub.c  to R.sub.max       (R.sub.max  - Z.sub.c) · 1/(R.sub.max  - P)R.sub.max  to D.sub.max       0______________________________________ 
    
     A hardware implementation of the filter (inhibition) function is shown in FIG. 8 comprising five subtractors 130 to 134, four controlled switches or multiplexers MUX 138,140,142,144, a control unit 148 controlling operation of the switches, two inverse value generators (dividers) INV 150,152 and a multiplier 154. Values of z, Z c , P, R max  and R min  are input to the control unit 148 and also to appropriate ones of the subtractors 130 to 134 such that they respectively output values for z-R min , R max  -Z c , R max  -Z, P-R min  and R max  -P. Under control of the control unit 148 and in dependence on the values of z, Z c  and P (analogous to steps 112 and 116 of FIG. 7), switches 138 and 140 select the appropriate numerator and switch 142 (following inverters 150 and 152) the appropriate denominator such that multiplier 154 outputs the appropriate value of I for all values of z between R min  and R max . For the special cases (Z c  less than P, z outside focus range R) the control unit causes switch 144 to select a zero input rather than the output of multiplier 154. The control unit 148 is a simple logical switching circuit and may for example comprise a series of comparators arranged to carry out the determination steps 100,104,108,112 and 116 from FIG. 7 and cause appropriate switching of switches 138,140,142 and 144. 
     With each of the switches 138 to 144 having a pair of inputs A and B as shown in FIG. 8, the switch settings are as shown below in Table 2, with the left-hand values being determined in the order shown, following FIG. 7. Where no setting is shown, the inputs to that switch are not necessary for the output inhibition factor and the switch may take either setting. 
     
                       TABLE 2______________________________________        138  140       142    144______________________________________Z.sub.c  less than P          --     --        --   Az less than R.sub.min          --     --        --   Az greater than R.sub.max          --     --        --   Az less/equal to P          A      --        A    Bz less than Z.sub.c          B      B         B    Bz greater/equal to Z.sub.c          B      A         B    B______________________________________ 
    
     Variations on the circuit of FIG. 8 will be apparent to the skilled practitioner. For example, the two inverse value generators INV 150,152 may be replaced by a single inverter between switch 142 and multiplier 154. Also, as suggested previously, where R is centred on P, the outputs of subtractors 134 and 133 will always be equal and hence subtractor 134, inverter 152 and switch 142 may be omitted. 
     Where R is not specified, and the inhibition profile is determined on the basis of D, the R input to the function stage 26 (FIG. 3) is replaced by input of D, the references to R max  and R min  in the preceding description and FIGS. 7 and 8 are replaced with D max  and D min , and steps 104,106,108 and 110 are omitted from FIG. 7. 
     Returning to FIG. 3, the output inhibition values I of the function stage 26, for the i pixels of the filter kernel, are multiplied (at multiplier 50) by the respective i coefficients k output from the coefficient look-up table 36. The result is summed over the i values by summation circuit 52. The i outputs of multiplier 50 are also input to a further multiplier 54 where they are multiplied by respective ones of the i input pixel values V read out of line store 22. The outputs of multiplier 54 are summed over the i values by a further summation circuit 56. The output of the summation circuit 56 is divided by that from summation circuit 52 by divider 58, the output of which provides the modified pixel value V&#39; to be passed to a display screen. 
     As will be appreciated from the foregoing, the present invention provides a relatively simple and computationally inexpensive (capable of realisation in hardware) technique for providing focus/defocus effects to computer generated graphics. As a post-processing technique, modification of the graphics generator is avoided although the present invention could of course be incorporated into such a generator as an output stage. 
     From reading the present disclosure, other modifications will be apparent to persons skilled in the art. Such modifications may involve other features which already known in the field of graphics manipulating and processing apparatuses and component parts thereof and which may be used instead of or in addition to features already described herein. Although claims have been formulated in this application to particular combinations of features, it should be understood that the scope of the disclosure of the present application also includes any novel feature or any novel combination of features disclosed herein either explicitly or implicitly, whether or not it relates to the same invention as presently claimed in any claim and whether or not it mitigates any or all of the same technical problems as does the present invention. The applicants hereby give notice that new claims may be formulated to such features and/or combinations of such features during the prosecution of the present application or of any further application derived therefrom.