The invention relates to image processing, in particular methods of extracting a silhouette from an image.
In image processing, edge detection is the usual technique in finding silhouettes in monochrome images. An edge is defined as a location in an image with high grey-level contrasts, i.e. there is a large jump in grey level from one pixel to the next. There are a number of standard algorithms for detecting edges based on, for example the Sobel and Laplace methods.
In edge detection, a threshold is set for a grey-level contrast, so that an edge is formed when the contrast is above that threshold. For the silhouette extraction problem it is very difficult to provide a threshold that is consistent for all situations. If the threshold value is too low, then edges will be indicated everywhere in the image, both inside the object for which the silhouette is being determined and in the background. In this case it will be difficult to extract the silhouette from the myriad of edges.
If the threshold value is too high, then the edge may not be indicated along those parts of the silhouette where the difference in grey level between the edge of the object for which the silhouette is being determined and the background is small. For example in the case of a head-and-upper torso portrait of a person, this may occur when the grey level of hair, skin or clothing is nearly the same as that of the background. Without clearly defining the object edges, the silhouette of the object cannot be found.
As such existing methods rely on the grey levels and textures of the object and the background, as well as the lighting conditions at the time the image is captured and the exposure setting and other characteristics of the camera capturing the image. In order for these edge detection methods to succeed, the colour of the background must be carefully chosen and a sophisticated camera and lighting setup is required. This can be inconvenient, especially when a system used for imaging head-and-upper torso portraits is imaging many people with different hair colour, clothing and complexions.
In comparison with the described edge detection methods above, the invention does not require the detection of edges; actually it makes no use of the contrast in grey level values in the image or picture being processed. Consequently, the invention is immune to the grey level values or textures of the object for which the silhouette is being determined or the background, and also immune to the camera and lighting setups. It works well even when the grey level value at an edge of the object is very close to that of the background.
According to a first broad aspect of the invention, there is provided a method comprising: extracting the silhouette of an object against a fairly plain background in an image comprising a plurality of pixels by processing the image, the processing comprising determining if adjacent pixels of the image have an equal grey level value and the processing is independent of the numerical values of the original grey level values of pixels of the image.
According to a second broad aspect of the invention, there is provided a computer readable medium having computer readable program code means embodied therein for extracting a silhouette against a fairly plain background from an image comprising a plurality of pixels, the computer readable code means comprising: code means for processing the image, the processing comprising determining if adjacent pixels of the image have an equal grey level value and the processing is independent of the numerical values of the original grey level values of pixels of the image.
Other aspects and features of the present invention will become apparent to those ordinarily skilled in the art upon review of the following description of specific embodiments of the invention in conjunction with the accompanying figures.
Preferred embodiments of the invention will now be described with reference to the attached drawings in which:
The embodiments of the present invention disclosed herein provide an alternative to using conventional edge detection techniques for extracting a silhouette of an object with simple boundary from an image. Methods of the invention can be used for extracting the silhouette from an image of the object against a fairly plain background by a single monochrome camera. An example of the object is a head and upper body portion of a person in a head-and-upper torso portrait, such as the type taken for a passport photo or a driver's licence. A silhouette is an outline of the object in an image. In the example above the silhouette is the curve that separates the head-and-upper torso portrait of a person including hair, face, ears, neck and upper body from the background, where the hair, the face, and the upper body are within the boundary of the silhouette. More generally, the image may include any type of object with simple boundary in the image for which the silhouette is to be extracted. A “fairly plain background” is meant to define that the background does not contain any additional objects or people and does not have any distinctive visual patterns, such as lines. A plain wall or backdrop of any color lit by ambient light will satisfy the definition of a “fairly plain background”, even if brightness in the image is not uniform due to uneven lighting. In a case of a portrait of a person where the person is standing in close proximity to a wall, a well-defined shadow of the person's head being cast on the wall by a spot light may produce a distinctive visual pattern in the image that would affect the ability of the method to properly obtain the accurate silhouette of the person.
In some embodiments of the invention the method is expressed as computer implemented program code that is stored on a computer readable medium. The computer implemented program code can be run from the computer readable medium by a processing engine adapted to run such computer implemented program code. Examples of types of computer readable media are portable computer readable media such as 3.5″ floppy disks, compact disc ROM media, or a more fixed location computer readable media such as a hard disk media storage unit in a desktop computer, laptop computer or central server providing memory storage or a workstation.
An image or picture for which embodiments of the invention will operate on is stored in a digital format on a computer readable memory. The image may originate as a digital image from a digital camera or an analog image that has been digitized, for example a photo scanned by a scanner and stored in a computer readable memory.
A camera that captures a monochrome image is capable of producing a single picture in multiple grey levels. A camera that captures a colour image can be used to provide images which can be used with embodiments of the invention by first converting the colour image into a monochrome image by averaging the red, green and blue components of the pixels of the image. Generally, the monochrome picture is considered to be a rectangular array of pixels, where each pixel has an associated grey level.
A method according to an embodiment of the invention will now be described with respect to the flow chart of
Not all steps in the method of
The steps of the method will now be described in more detail.
At step 120, the grey levels of the pixels are modified with the purpose of creating numerous small iso-grey area (IGA) regions along the edge of the silhouette so that the silhouette becomes more prominent. IGA regions are groups of connected pixels having the same grey level value. There are a number of ways to operate on the pixels, for example using statistical, convolution and/or morphology techniques. Two particularly effective operations used in embodiments of the invention are calculating an average grey level for each pixel based on a group of pixels in close proximity to the respective pixel and calculating a median grey level for each pixel based on a group of pixels in close proximity to the respective pixel.
In determining the average grey level of a group of pixels, for each pixel in the image, the average (that is arithmetic mean) grey level of 9 pixels in a 3×3 square around a respective pixel is determined. This determined average grey level value is selected as the new grey level of that pixel. Since grey levels are integers, the average is rounded to the nearest integer value.
In determining the median grey level of a group of pixels, for each pixel in the picture, the median grey level of the 9 pixels in the 3×3 square around a respective pixel is determined and used as the new grey level of that pixel.
Determining the average and/or median grey level is performed based on the original pixel values of the image and not based on the new pixel values determined by the average and/or median calculation.
Pixels along the edges of the image will have fewer pixels around them than make up a complete 3×3 square, but methods for finding the average and the median are similar to pixels with a group of 3×3 pixels around them.
More generally, the number of pixels used in calculating the average or median may be greater than or less than the 3×3 block example described above.
Mathematical operations used in embodiments of the invention that have been found to be preferable for processing the pixels of the image are 1) “Average” only, 2) “Median then Average”, and 3) “Average then Median then Average”. However, alternative forms of these or other mathematical operations that provide appropriate processing are to be considered within the scope of the invention.
One may consider that if the grey levels of the object and the background differ by only a grey level equal to 1 instead of 2, then the above effect will not occur. Strictly speaking, this is true, but the chance of such a case is small. Furthermore, to handle such a case, in some embodiments of the invention the grey levels of all pixels in the image are multiplied by 2 before doing the “Average” operation.
At step 130, the IGA regions are formed in the image that has been altered by the “Average” and/or “Median” operations described above, and denoted as picture P from hereon. Step 130 generates an IGA picture Q from picture P, so that in future steps the silhouette is extracted from picture Q, and not from picture P.
The IGA picture Q has the same size, that is the same numbers of rows and columns, as picture P. Preferably picture Q is also monochrome with usually, but not necessarily, the same grey level granularity as picture P.
Picture P is first partitioned into mutually disjoint “4-connected” regions such that the pixels in each region have equal grey levels. These regions in picture P are called iso-grey regions. A subset of pixels is said to be “4-connected” if any two pixels in the subset are connected by a path that may or may not include other pixels in the subset, such that adjacent pixels with an equal grey level along the path are on the left/right of or above/below each other. In other words, if a pixel is considered a square, a pixel in a “4-connected” subset can only be connected to pixels on one of the four sides of the square. Regions that are “8-connected” allow for diagonal adjacency, as an “8-connected” region includes corner pixels of a 3×3 block of pixels around a given pixel, in addition to the 4 pixels, one on each side, surrounding the given pixel.
There are many ways of partitioning picture P into iso-grey regions. In some embodiments of the invention one method used is called “flooding”. Essentially, it starts with a pixel in an iso-grey region that has not yet been modified to be an iso-grey region and “floods” the neighbouring unmodified pixels that have the same grey level. This same process is repeated recursively for the flooded pixels. The area is augmented each time a pixel is flooded. To cut the overhead cost in recursion and to prevent possible stack overflow, a queue data-structure is used to perform the flooding operation. In some embodiments of the invention, a “breadth-first search” technique is used. Each unmodified pixel is loaded into the queue, and the following steps are repeated until the queue becomes empty: pop the head of the queue, mark it as modified, augment the count, and push those neighbours of the pixel at the head of the queue with the same grey level as the pixel at the head of the queue to the tail of the queue.
The number of pixels in each iso-grey region of picture P are counted. The resulting number of pixels in each region is called the “area” of that region and the region is called an IGA region.
The IGA picture Q is formed by equating the grey level of each pixel in picture Q to the IGA value of the corresponding pixel in picture P.
Referring to
As described above, in
In some embodiments of the invention, all pixels in picture Q whose IGA value is greater than or equal to this threshold are assigned a grey level of “white”, and all other pixels in picture Q will be given a proportionate grey level between black and light grey, for example ⅞ of the total grey level range. For 256 grey levels, this ⅞ portion would be from grey level 0, “black”, to grey level 224. Using light grey instead of white as the lower bound for pixels with IGA values smaller than the threshold may help in identifying the background from the object.
For example, suppose that the original picture P has 256 grey levels and it is desirable to maintain 256 grey levels for picture Q. Setting the area threshold to 100, any pixel in picture Q with an IGA value of 100 or above will be given a grey level of 255 (white). Any pixel in picture Q in a given region with an IGA value of less than the threshold of 100 will be assigned a grey level between 0 and 224 that is proportional to the value between 0 and the threshold value of 100. In this specific example, this is a grey level equal to 32+a*192/100, rounded to the nearest integer, where “a” is the number of pixels of the given region. More generally, any threshold value can be used in place of the value of 100 used in the example above.
Note that after the IGA picture Q is obtained from picture P, picture P is no longer used. All future processing is based on picture Q and not on picture P. The method only checks whether adjacent pixels in picture P have the same or different grey levels, and uses this information to create the IGA picture and find the silhouette. The actual numeric grey level values of the pixels in P are not used beyond this point in determining the silhouette. Therefore, the method is immune to brightness of the object, ambient lighting when the image is captured, setting of the camera used to capture the image and many other image dependent characteristics.
In step 140, the area of picture Q outside the object having the silhouette that is to be extracted, is processed. The silhouette is more apparent in the IGA picture than in the original picture. In order to extract the silhouette from the IGA picture, the image is analyzed using a disc shaped collision detector to define a coarse boundary around the object by analyzing the area outside the object and marking the coarse boundary. The disc shaped collision detector is moved around within an area of the image outside of the object of which the silhouette is to be determined to determine pixels that are not a part of the background.
In some embodiments of the invention, the collision detector is a circular disc whose radius is not too large to get trapped in the background, and not too small so that detector enters into the interior of the object of which the silhouette is to be determined. In some embodiments of the invention the radius of the detector is mainly dictated by the degree of uniformity in the grey level of the background. In a particular embodiment, a detector disc radius of approximately 6.5 times the pixel-width is an appropriate size to avoid the problems identified above.
It is to be understood that the disc shaped collision detector is one example of a detector that is moved around the image external to the object. Other shapes for the detector may be utilized, such as a square for instance.
The following is an example of how the disc shaped collision detector is used to process the area outside the object. The detector is initially positioned on the IGA picture so that its centre is at a “white” pixel somewhere near a top edge of the picture close to the top left corner. It is then advanced to the pixel below it. The detector moves in all directions (except where it came from) over the course of processing making sure that its edge does not hit any non-“white” pixel or a pixel that has already been visited. Each pixel that is encountered by the detector as it moves around the picture is identified in some appropriate manner as having been encountered, and each encountered “white” pixel will be “marked”. The motion of the detector stops when it is no longer able to move without hitting non-“white” pixels or pixels identified as previously encountered.
There are many ways of implementing the movement of the collision detector. A particular method is recursion. In some embodiments of the invention, to reduce overhead cost of the recursion method and to prevent possible stack overflow in the processor during implementation, a “breadth-first search” technique with a queue data-structure is used in the same way as in the flooding process described above.
In a particular embodiment of the invention, for example to be used when processing a head-and-upper torso portrait image, moving the collision detector is repeated with the detector starting from 3 other locations, namely a “white” pixel somewhere on the top edge close to the top right corner (moving downwards), a “white” pixel somewhere on the left edge (moving rightwards), and a white pixel somewhere on the right edge (moving leftwards). The third and fourth starting positions should be such that they are in the background, (e.g. above the shoulder for the person in the portrait). Preferably, during each repetition, the detector does not traverse pixels that have been visited previously and can be so determined by the appropriate identification mentioned above. It is to be understood that the repetitions of moving the detector are application specific and the number of repetitions and the starting position of the collision detector are selected as desired. Normally, one or two repetitions may be sufficient; the last few repetitions may not even start if all of the edges have been encountered by earlier repetitions.
A problem known to occur with this method is, if the top of the silhouette object is very close to the top edge of the picture and the width of the gap between the silhouette object and the top edge of the picture is less than the radius of the collision detector, the detector cannot advance past the top of the silhouette object. This problem is easily solved by creating a “buffer” area above the silhouette object for the disc to pass through.
After the collision detector has completed the repetitions of movement outside of the object, the interior of the object should be left “unmarked”. It may be advantageous to halve the grey levels of the “unmarked” pixels in the IGA picture, so as to distinguish them clearly from the “marked” ones.
Step 140 of moving the collision detector outside the object is used to identify the interior of the silhouette object (or more correctly, to identify those places that are not in the interior). However, as a result the interior of the object is often defined to be slightly larger than the silhouette of the actual object due to the nature of the movement of the detector. The result can be improved by performing some additional processing, step 150, on the image output from step 140. For example, applying a dilation operation twice on the picture produces good results. More generally, one or more than one dilation operation may be applied. Dilation is a morphology operation in which the grey level of each pixel is replaced by the maximum grey level of the 9 pixels around it. The dilation operation causes a slight shrinkage of the object. While dilation is one specifically described operation performed at step 150, using other image processing techniques is considered to be within the scope of the invention. One such example of other image processing techniques is combining dilations with morphological opening or closing. Opening is erosion followed by dilation, and closing is dilation followed by erosion, where erosion is an operation that replaces the grey level of each pixel by the minimum grey level of the 9 pixels around it.
Step 160 further aids in defining the silhouette of the object by analyzing the area within the coarse boundary established in step 140. Step 160 involves moving another collision detector within the interior of the silhouette object. The detector may be of a similar type to the disc shaped detector described above or it may have different parameters such as size or shape.
The following is an example of how the disc shaped collision detector is used to process the area within the silhouette object. The detector is initially located at a position where it is believed that the object is located. For example, in the case of the head-and-upper torso portrait, the silhouette object is generally centered in the image with the upper body filling most of the bottom edge of the image. Therefore, the detector is located at a midpoint between the side edges of the image near the bottom edge. The detector is allowed to move freely over “non-white” pixels within the currently identified boundaries of the silhouette object. Whenever an edge of the detector encounters a “white” pixel, (which should be just outside the silhouette object by virtue of markers set in step 140), the detector cannot proceed further, and the encountered pixel will be labelled as a boundary pixel of the silhouette.
In this way, the silhouette of the silhouette object is obtained by collecting all of the labelled boundary pixels.
The radius of the disc shaped region should not be set too small or it may escape into the area outside the silhouette object of the image. Similarly it should not be set too large else details in the curvature of the silhouette may be lost.
In some embodiments of the invention, as with processing outside the silhouette object at step 140, breadth-first search with a queue data-structure is used instead of recursion to implement the inside the silhouette object processing.
In a particular embodiment of the invention the silhouette image is output with a set of silhouette boundary pixels identifying the silhouette, where distances between adjacent boundary pixels are no less than some user-specified value d. To produce such an output, whenever the collision detector contacts a white pixel: a circle of radius d is drawn about the white pixel and every white pixel inside the circle (excluding the white pixel itself) is converted into a black pixel. In this way, it is ensured that the next contacted pixel will be at distance d from the white pixel. If desired, these silhouette boundary pixels can then be arranged so that they run along the silhouette in order.
The output at step 190 is an order set of silhouette boundary pixels, given by their row and column numbers. These pixels may be continuous or evenly spaced.
The IGA picture of the image of
The dotted silhouette of the original image from
In the above example, the method successfully generated the silhouette of the black-haired mannequin against a black background. If a person has fine hair that sticks out from their head, the method will produce a silhouette enclosing the fine pieces of hair.
If the user wants to tighter the silhouette around the hairline, further processing can be performed on the image, as indicated in
The method of
Other factors that can affect the method are narrow and sporadic protrubances from the main object for which the silhouette is desired. For example, if a person has flamboyant hair with thin portions of hair directed away from the head, or if the person wears a long ornament like earrings.
Furthermore, an exact representation of the silhouette may not be possible if some part of the person's hair, skin or clothing on the boundary between the silhouette and the background has a constant grey level that is exactly identical to the background. In the case of hair in particular, this is improbable because hair is made of many individual hair strands which usually differ by at least one grey level.
Since the above-described factors are unlikely or can be avoided easily, the method is robust in most situations.
The speed of the proposed method is comparable to the existing methods, as they roughly have the same degree of complexity.
The method as described with respect to
A potential use of the method is to replace blue (or green) screens in the movie industry. Blue screening is presently the standard method for producing special effects: an actor acts in front of a blue screen, and all the blue colour within some brightness range is replaced by a different background. Some limitations of the bluescreen technique are that the captured images are typically filmed in a studio with a specially painted blue wall and floor; it requires careful lighting setup; there should be no similar blue colour on the actor's wardrobe; and there are problems with shadows and “blue spills” onto the actor creating a blue tinge around the edges. Embodiments of the invention do not have similar problems. The shooting can be done in a studio with ordinary walls or in an outdoor environment.
Embodiments of the invention can also be used in surveillance and security systems, where a silhouette helps in singling out a person or a face for facial recognition.
For stereoscopic imaging of a person, the silhouettes obtained for the left and right images can be used to generate the position of the person using stereo disparity techniques on the silhouettes.
Numerous modifications and variations of the present invention are possible in light of the above teachings. It is therefore to be understood that within the scope of the appended claims, the invention may be practised otherwise than as specifically described herein.
Filing Document | Filing Date | Country | Kind | 371c Date |
---|---|---|---|---|
PCT/CA05/01059 | 7/7/2005 | WO | 00 | 4/11/2006 |