Abstract:
A method and system are provided for focusing an imaging device on a liquid sample flowing through a field of view of the imaging device. Objects are segmented in the captured frames and used to account for the fact that the sample is flowing. Object velocities are calculated and used in selecting an appropriate focus value. The calculation of a focus measure takes account of the number of objects in captured frames in order to ensure a consistent calculation of the focus measure.

Description:
RELATED APPLICATIONS 
       [0001]    This application is a continuation of U.S. application Ser. No. 15/515,498 filed Mar. 29, 2017, which is a National Phase entry of PCT Application No. PCT/EP2015/072416, filed Sep. 29, 2015, which claims priority from Great Britain Application No. 1417170.6, filed Sep. 29, 2014, and which claims priority from Portuguese Application No. 107932 U, filed Sep. 29, 2014, the disclosures of which are hereby incorporated by referenced herein in their entirety. 
     
    
     FIELD OF THE INVENTION 
       [0002]    The present invention relates to a method and system for focusing an imaging device on a liquid sampling flowing through a field of view of the imaging device. 
       BACKGROUND OF THE INVENTION 
       [0003]    Many different algorithms are known for focusing imaging devices. It would be desirable to have a robust and efficient focusing algorithm specifically adapted for focusing on a flowing liquid sample. 
       SUMMARY OF THE INVENTION 
       [0004]    Aspects of the invention are set out in the independent claims. Optional features of embodiments of the inventions are set out in the dependent claims, dependent thereon. 
         [0005]    In some embodiments, there is provided a method of focusing an imaging device on a liquid sample flowing through a field of view of the imaging device. A focus mechanism of the imaging device is stepped through a plurality of focus values while capturing frames of a sample containing objects as the same flows through the field of view of the imaging device. Objects in the captured frames are segmented and a focus measure is determined for each focus value from the captured frames. Object velocities of at least one object in at least some of the frames are determined. One of the plurality of focus values is selected based on the determined focus measures and object velocities and the focus mechanism is set using the selected focus value. 
         [0006]    Advantageously, by using the knowledge that objects in the flowing sample are moving, the selection of a focus value that corresponds to a focus plane in which the sample flows (objects move) is facilitated by considering object velocities in the selection of the focus value. 
         [0007]    In some embodiments, selecting a focus value involves selecting a focus value for which the corresponding focus measure is a local extremum and the corresponding object velocity is larger than object velocities at any other local extrema of the determined focus measures. For example, candidate focus values at which the focus measure is at an extremum may be determined and the candidate focus value selected for which a corresponding object velocity determined from frames captured with that focus value is largest. In this way, focus values corresponding to a focus plane having a large focus measure due to artefacts such as a scratch in a cover glass can be distinguished from a focus value corresponding to a focus plane containing the moving objects and hence the flowing sample. Other selection criteria are used in some embodiments, for example the corresponding object velocity exceeding a threshold. By suitable selection of the threshold, it can be ensured that the object velocity associated with the selective focus value is larger than object velocity at any other of the local extremum of the focus measures. The object velocity associated with a given focus value may be the maximum, minimum, average, median or other ensemble measure of the respective object velocities of objects captured at that focus value, or an object or object velocity may be selected from all the objects/object velocities of objects captured at that focus value, at random or in accordance with a predetermined criterion. 
         [0008]    In some embodiments, determining a focus measure for each focus value involves determining the focus measure using image patches around the segmented objects such that the magnitude of the focus measure is independent of the number of objects in each frame. For example, the focus measure may be determined using an average of respective focus measures calculated for each object captured while the focus mechanism is set to that focus value. In some embodiments, a maximum, minimum, median or other ensemble measure is used instead of the average. All or a subset of the segmented objects may be used for this calculation. In some other embodiments, an object/image patch is selected from the objects captured at each focus value, randomly or based on a predetermined criterion. In some embodiments, the focus measure for an image is calculated over the whole image and normalised by a detected number of objects. Thus, more generally, the focus measure for an image may be calculated such that it is independent of the number of objects in the image. 
         [0009]    In some embodiments, the focus measure is a contrast-based focus measure. For example, a Sobel operator may be used to derive the focus measure by convoluting the operator with captured pixels. See for example http://www.researchgate.net/publication/239398674_An_Isotropic_3_3_Image_Gradient_Operator. For example, focus measures may be calculated by convoluting the operator with image patch or patches around segmented objects. In other embodiments, the operator is applied to the whole image. Other operators may also be used to calculate the focus measure, as is well known in the art. 
         [0010]    Advantageously, by calculating focus measures on a per patch/patch averaged basis, the effect of a varying number of objects present in any one captured frame of the flowing sample does not affect the comparison of the focus measures between frames. Hence the corresponding variation of the overall image contrast is accounted for. 
         [0011]    In some embodiments, the selected focus value is refined by stepping the focus values through a plurality of focus values around the selected focus value. The refined focus value is used to set the focus mechanism. In some embodiments, respective focus measures are calculated for each of the plurality of focus values around the selected focus value and the refined focus value is chosen to be that for which the corresponding focus measure is largest (more generally indicating best focus). In these embodiments, setting the focus mechanism using the selected focus value involves refining the focus value as described and using the refined focus value to set the focus mechanism. 
         [0012]    Advantageously, the described refinement procedure allows the focus value to be fine-tuned. In some embodiments, the above steps are repeated to obtain a plurality of selected focus values, with or without refinement. In some embodiments, only the refinement is repeated. The resulting selected (or refined) focus values are combined to find a final focus value for setting the focus mechanism, for example by averaging, taking the median or another ensemble measure. 
     
    
     
       BRIEF DESCRIPTION OF THE FIGURES 
         [0013]    A specific embodiment is now described, by way of example only, with reference to the accompanying drawings, in which: 
           [0014]      FIG. 1  is a schematic illustration of an imaging device for imaging a flowing sample; 
           [0015]      FIG. 2  is a flow diagram of a method of focusing an imaging device such as illustrated in  FIG. 1 . 
       
    
    
     DETAILED DESCRIPTION OF THE INVENTION 
       [0016]    With reference to  FIG. 1 , an imaging device  2  comprises an objective (lens) assembly  4  for forming an image of a field of view  5  inside the imaging device  2 . A focusing mechanism  6  is coupled to the objective assembly  4  to move the objective assembly along an optical axis in order to focus at a given depth inside the field of view. A focus value is a value indicative of where the imaging device  2  is focused. The focus value may be chosen to be a position along the optical axis of the objective assembly  4  relative to the imaging device  2 , a distance of an imaged plane in focus from the imaging device  2 , a value related to the configuration of the focus mechanism (e.g. rotor position of a focus drive motor) or any other value indicative of where the imaging device is focused. 
         [0017]    A processor  8  is coupled to the imaging device  2  and receives images and other signals for processing from the imaging device  2 . In turn, the processor sends control information to the imaging device  2 , including control information to set a focus value and cause the focus mechanism  6  to position (or configure) the objective assembly  4  in accordance with the focus value, as well as to, in some embodiments, control one or more other parameters of the imaging device, for example the imaging gain of an image sensor inside the imaging device  2 . It will be understood that the imaging device  2  and processor  8  may be provided as separate units or may be housed in a single unit. For example, components of the processor  8  and imaging device  2  may be provided on a single integrated circuit. 
         [0018]    A sample conduit  10  carries a flowing sample  12  containing objects  14 . For example, the sample may be a blood sample and the objects may be blood cells, for example white blood cells. The sample conduit  10  is disposed within the field of view  5 , so that the sample  12  and objects  14  can be imaged by the imaging device, for example capturing a time series of frames at a given sample rate. The sample conduit  10  is disposed fixedly relative to the imaging device  2  in a manner not illustrated in  FIG. 1  for clarity. The sample  10  and imaging device  2  may form part of a single device or, for example, the sample conduit  10  may be provided on a microfluidic analysis cartridge which can be inserted into a holder associated with the imaging device  2  to fixedly dispose the sample conduit  10  relative to the imaging device  2 . In some embodiments, the sample conduit  10  is provided on a disk cartridge implementing a lab on a disk device and the imaging device and processor it may be part of a DVD reader like reader device including a mechanism for loading the lab on a disk device. Flow of the sample may be driven by a variety of driving mechanisms, including capillary forces, centrifugal forces, electrophoretic forces and any other suitable driving mechanisms. 
         [0019]    With reference to  FIG. 2 , a process for focusing the objective assembly  4  using the focus mechanism  6  and processor  8  is now described. 
         [0020]    At step  16 , the processor sets a focus value that causes the focusing mechanism to the position the objective assembly  4  accordingly. Subsequently, at step  18 , frames acquired by the imaging device are received by the processor and objects in the acquired frames are segmented at step  20  in accordance with known techniques for image segmentation. 
         [0021]    At step  22 , a focus measure is acquired, associated with the set focus value. An image patch is defined around each segmented object and a Sobel operator is convoluted with each image patch. The results of these convolutions are averaged over image patches to calculate the focus measure for the said focus value. 
         [0022]    In a specific implementation, the following Sobel operator and magnitude calculation is used to derive an average gradient magnitude as a focus measure for each image patch: 
         [0023]    If each image patch is denoted by A, and Gx and Gy define two images patches which at each point contain the horizontal and vertical derivative approximations, the computations are as follows: 
         [0000]    
       
         
           
             
               G 
               x 
             
             = 
             
               
                 
                   [ 
                   
                     
                       
                         
                           - 
                           1 
                         
                       
                       
                         0 
                       
                       
                         
                           + 
                           1 
                         
                       
                     
                     
                       
                         
                           - 
                           2 
                         
                       
                       
                         0 
                       
                       
                         
                           + 
                           2 
                         
                       
                     
                     
                       
                         
                           - 
                           1 
                         
                       
                       
                         0 
                       
                       
                         
                           + 
                           1 
                         
                       
                     
                   
                   ] 
                 
                 * 
                 A 
                  
                 
                     
                 
                  
                 and 
                  
                 
                     
                 
                  
                 
                   G 
                   y 
                 
               
               = 
               
                 
                   [ 
                   
                     
                       
                         
                           + 
                           1 
                         
                       
                       
                         
                           + 
                           2 
                         
                       
                       
                         
                           + 
                           1 
                         
                       
                     
                     
                       
                         0 
                       
                       
                         0 
                       
                       
                         0 
                       
                     
                     
                       
                         
                           - 
                           1 
                         
                       
                       
                         
                           - 
                           2 
                         
                       
                       
                         
                           - 
                           1 
                         
                       
                     
                   
                   ] 
                 
                 * 
                 A 
               
             
           
         
       
     
         [0024]    where * denotes a 2-dimensional convolution operation. 
         [0025]    At each pixel in the image, the resulting gradient approximations can be combined to give the gradient magnitude as the square root of the sum of the squares of Gx and Gy at the pixel, or the sum of the absolute values as an approximation. This quantity is then averaged or summed over the image patch pixels to give the focus measure. 
         [0026]    At step  24 , the processor determines whether a desired number of focus value/measurement pairs have been obtained or whether further pairs need to be obtained. If further pairs are needed, the process loops back to step  16  after the focus value is incremented for example by adding a constant step size or looking up the next focus value in a set of focus values. If the preset number of pairs has been acquired, the focus value is not incremented further but the process proceeds to step  26 . 
         [0027]    At step  26 , local extrema of the focus measure as a function of focus values are found. The skilled person will be familiar with many ways of finding local extrema, one example being a hysteris threshold algorithm. In case that the focus measure increases with increasing quality of focus, the extrema will be maxima and in the case that the focus measure decreases with focus quality, the extremer will be minima. Thus, the extrema are always local maxima of focus (focus quality, focus sharpness, etc.). 
         [0028]    If, at step  26 , only a single extrema is found, the process jumps to step  30 , described in more detail below. If a plurality of focus measure extrema are found, the process proceeds to step  28  and one of the extrema is selected. A plurality of focus extrema may arise, for example, when dust particles on an outer surface of the sample conduit  10 , an air bubble on an inner surface of the sample conduit  10  and possibly a scratch on a opposed outer surface form additional image planes with high contrast features in addition to an image plane containing the objects  14  in the sample  12  flowing in the sample conduit  10 . Only the latter is the plane in which the focus should be placed. This plane can be distinguished from the others in that the objects in question, flowing in the sample, are moving. Therefore, the desired object plane can be identified on the basis of the velocity of the objects in which the focus measures were calculated. 
         [0029]    Accordingly, at step  28 , object velocity is calculated from the frames associated with each pair of focus values/focus measure. Ways of calculating object velocities of objects in captured images are well known. For example, for an object detected in a first frame, it is checked whether there is a single object within a detection radius from the position of the object in the first frame in the next frame. If so, these objects are taken to correspond to the same physical object and a velocity is calculated using the difference between the object positions in the two frames and the sample rate. If more than one object is detected in the radius in the subsequent frame, the calculation for that object is aborted. An overall object velocity is then determined by averaging individual object velocities determined for the relevant frames as described. The extremum (focus value/measurement pair) associated with the highest average object velocity is then selected for subsequent use in focusing (setting the focus mechanism  42 ). 
         [0030]    At step  30 , the selected focus value from step  26  or step  28  is used as a starting point for focus refinement. A set of focus values around the selected focus value is defined, for example a pre-set number of values each side of the selected value with a given step width. The step width will be smaller than the step width of the increment at step  24 , so that the focus value search at steps  16  to  24  represents a coarse initial search and the set of focus values defined at step  30  represent a fine search around the focus value found with the coarse search. Similar to steps  16  to  24 , the processor controls the focus mechanism to step through the set of focus values and acquires frames at each focus value to calculate corresponding focus measures. The focus value of this set of focus values that has the highest/best focus measure is then determined and used at step  32  by the processor to set the focus mechanism to that value. 
         [0031]    It will be appreciated that a specific embodiment has been described by way of illustration only and that various modifications, alterations and juxtapositions of the described features are possible without departing from the invention, as described above and otherwise. In particular, the steps of the process described above with reference to  FIG. 2  can to some extent be changed in order and may be grouped and combined as appropriate. Frames may be captured and received as needed at each step or frame acquisition may be ongoing with only those frames used that are relevant. Where appropriate, step sequences described above may be interchanged for corresponding batch processes, for example steps  16 ,  18  and  24  may be grouped as a batch process to provide sets of frames associated with corresponding focus values and segmentation of objects and calculation of focus measures may be done as a further batch process. 
         [0032]    The described processes can be implemented using any suitable stand-alone or distributed computing environment using any suitable computing platform or processor, for example an integrated circuit, self-contained or in combination with other components of the system, a dedicated computing device housed on an appropriate card together with the other components of the system or otherwise, a standalone computing device such as a personal computer, tablet computer or mobile phone or a server which performs the necessary processes at least in part remotely exchanging data over a network connection.