Method, device, and computer program for detecting boundary of object in image
The present disclosure provides a method of enabling image-based classification in real-time scenarios such as person presence identification, image-based gesture-recognition, real-time object detection, character recognition etc. The present disclosure provides a method and system of contour detection as part of data pre-processing pipeline for training and real-time inferencing of image-based multi-classifier using Machine Learning. A direction-based contour detection method is implemented as part of data pre-processing pipeline for real-time image-based multi-classifier/inferencing using ML algorithms. A parallelized contour detection method is implemented to reduce input feature set, reduce training and prediction time.
1 . An electronic device comprising:
a memory storing instructions; and
at least one processor configured to execute the instructions to:
process an image to output a secondary image;
split the secondary image into a plurality of image segments;
scan the secondary image in a scan direction from a start pixel in each of the plurality of image segments to identify a first boundary pixel found as satisfying a boundary criteria during the scanning of the secondary image;
identify a second boundary pixel satisfying the boundary criteria by rotating the scan direction and scanning pixels in the secondary image along a circumferential direction centered on the first boundary pixel, wherein the scanning of the pixels starts from a pixel that is adjacent to the first boundary pixel, located in the rotated scan direction and adjacent to a direction opposite to the scan direction;
identify one or more next boundary pixels until a respective contour of an object is obtained in each of the plurality of image segments; and
obtain a complete contour of the object in the secondary image based on the respective contours obtained in the plurality of image segments,
wherein scan directions used for at least two different image segments are opposite to each other.
2 . The electronic device of claim 1 , wherein each pixel of the secondary image has a zero color value or non-zero color value, and the boundary criteria is satisfied when a corresponding pixel has the non-zero color value.
3 . The electronic device of claim 1 , wherein the scan direction corresponds to one or more of a west scan direction, an east scan direction, a north scan direction, or a south scan direction.
4 . The electronic device of claim 1 , wherein the start pixel is located at a middle of the secondary image.
5 . The electronic device of claim 1 , wherein the rotated scan direction is one or more of a west scan direction, an east scan direction, a north scan direction, a south scan direction, a north-west scan direction, a north-east scan direction, a south-west scan direction, or a south-east scan direction.
6 . The electronic device of claim 1 , wherein the start pixel is located at a left edge of the secondary image when the scan direction is an east direction, and an updated scan direction is a north-west direction or a south-west direction.
7 . The electronic device of claim 1 , wherein an angle between the rotated scan direction and its previous scan direction is equal to 135° or 225°.
8 . The electronic device of claim 1 , wherein the circumferential direction centered on the first boundary pixel is a clockwise or anticlockwise direction centered on the first boundary pixel.
9 . The electronic device of claim 1 , wherein the at least one processor is further configured to execute the instructions to:
scan at most 8 pixels along the circumferential direction centered on the first boundary pixel identified in the secondary image; and
scan at most 7 pixels along the circumferential direction centered on the second boundary pixel identified in the secondary image.
10 . The electronic device of claim 1 , wherein the complete contour of the object is obtained when a last boundary pixel is identified as satisfying the boundary criteria during the scanning the secondary image.
11 . The electronic device of claim 1 , wherein the at least one processor is further configured to execute the instructions to:
split the secondary image to a plurality of image segments;
obtain, in parallel, a respective contour of the object in each of the plurality of image segments; and
obtain the complete contour of the object in the secondary image based on the respective contour of the object in each of the plurality of image segments.
12 . The electronic device of claim 11 , wherein an edge boundary pixel is excluded from the complete contour of the object, and wherein the edge boundary pixel is located at an intersection edge of each of the plurality of image segments.
13 . The electronic device of claim 11 , wherein the plurality of image segments comprise a first quadrant image segment, a second quadrant image segment, a third quadrant image segment, and a fourth quadrant image segment,
wherein a first scan direction from a first start pixel in the first quadrant image segment and a fourth scan direction from a fourth start pixel in the fourth quadrant image segment are identical,
wherein a second scan direction from a second start pixel in the second quadrant image segment and a third scan direction from a third start pixel in the third quadrant image segment are identical, and
wherein the first scan direction and the second scan direction are opposite.
14 . A method comprising:
processing an image to output a secondary image;
splitting the secondary image into a plurality of image segments;
scanning the secondary image in a scan direction from a start pixel in each of the plurality of image segments to identify a first boundary pixel found as satisfying a boundary criteria during the scanning of the secondary image;
identifying a second boundary pixel satisfying the boundary criteria by rotating the scan direction and scanning pixels in the secondary image along a circumferential direction centered on the first boundary pixel, wherein the scanning of the pixels starts from a pixel that is adjacent to the first boundary pixel, located in the rotated scan direction and adjacent to a direction opposite to the scan direction;
identifying one or more next boundary pixels until a respective contour of an object is obtained in each of the plurality of image segments; and
obtaining a complete contour of the object in the secondary image based on the respective contours obtained in the plurality of image segments,
wherein scan directions used for at least two different image segments are opposite to each other.
15 . A computer program product comprising a non-transitory computer-readable recording medium having recorded thereon a program executable by a computer for performing a method comprising:
processing an image to output a secondary image;
splitting the secondary image into a plurality of image segments;
scanning the secondary image in a scan direction from a start pixel in each of the plurality of image segments to identify a first boundary pixel found as satisfying a boundary criteria during the scanning of the secondary image;
identifying a second boundary pixel satisfying the boundary criteria by rotating the scan direction and scanning pixels in the secondary image along a circumferential direction centered on the first boundary pixel, wherein the scanning of the pixels starts from a pixel that is adjacent to the first boundary pixel, located in the rotated scan direction and adjacent to a direction opposite to the scan direction;
identifying one or more next boundary pixels until a respective contour of an object is obtained in each of the plurality of image segments; and
obtaining a complete contour of the object in the secondary image based on the respective contours obtained in the plurality of image segments,
wherein scan directions used for at least two different image segments are opposite to each other.