Method and device for image subject recognition
Through technologies such as region growing and ray judgment, image subjects are automatically identified, which solves the problems of time-consuming manual processing and inaccurate edge processing, and achieves efficient and accurate image subject recognition and annotation sample generation.
Patent Information
- Application Number
- CN201911288847.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-12-12
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2039-12-12
AI Technical Summary
Existing image subject recognition methods rely on manual processing, are labor-intensive, slow, and cannot achieve pixel-level accuracy. In addition, methods such as background subtraction and binarization are computationally intensive and edge processing is not precise enough, making it impossible to accurately identify images. the subject in.
Obtain the non-background area through the area growing method, set the target area to filter the target growth area that intersects with it, determine the image subject, use ray judgment and RGB value judgment criteria to improve the accuracy of edge processing, and fuse the subject image with the preset background to generate Label image samples.
It realizes automatic image subject recognition, reduces the amount of calculation, improves the accuracy of edge processing, avoids the shortcomings of manual annotation, and provides high-quality annotated samples for machine learning.
Smart Images

Figure CN113066039B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for image subject recognition. Background Art
[0002] Image subject recognition is a pre-algorithm for many image algorithms. The main methods for subject recognition at this stage are: machine learning, automatic annotation system, and separation of subject and background by background subtraction, binarization, etc. Machine learning requires annotated data, which is mainly done manually. Automatic annotation systems are usually semi-manually processed, such as manually selecting contour points on the contour of the object in the picture, and then the program generates annotated pictures based on these contour points. The focus of using background subtraction, binarization, etc. to separate subject and background is that they are applicable to any picture.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:
[0004] Manual processing is labor-intensive, slow, inefficient in responding to new images, and often fails to reach pixel level;
[0005] The focus of using background subtraction, binarization and other methods to separate the subject and the background is that they are applicable to any picture, but have the following defects: large amount of calculation; inaccurate edge processing; and inability to accurately find the subject that is really to be highlighted in the picture. Summary of the invention
[0006] In view of this, an embodiment of the present invention provides a method and device for image subject recognition, which can automatically complete image subject recognition and avoid problems such as manpower consumption, slow speed, insufficient response speed to new images, and often failing to reach pixel level due to manual processing.
[0007] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for identifying an image subject is provided, comprising:
[0008] Perform region growth on the image to be processed to obtain each growth region containing non-background;
[0009] A target area is set in the image to be processed, and a target growth area that intersects with the target area is selected from the various growth areas; the target area is used to indicate the range of the area where the subject in the image to be processed is located;
[0010] A main image in the picture to be processed is determined according to each of the target growth regions.
[0011] Optionally, before performing region growing on the image to be processed, the method further includes: screening the image to be processed from each image according to the following steps:
[0012] Starting from the center point of the image, a first ray is made in the positive and negative directions of a preset angle respectively, and it is determined whether the straight line where the first ray is located meets the preset condition; if so, the straight line where the first ray is located is used as a main image frame of the image; otherwise, two first rays are moved along the directions of (preset angle + 90°) and (preset angle - 90°) respectively until the straight line where the first ray is located after the movement meets the preset condition, and the straight line where each first ray is located after the movement is used as a main image frame of the image; wherein the preset condition is that the number of continuous background pixel points including the endpoints of the first ray is greater than or equal to the preset number threshold;
[0013] The one preset angle is replaced by another preset angle, and then the above steps are repeated until a preset stop condition is reached, and the picture that can reach the preset stop condition among the pictures is used as the picture to be processed;
[0014] The preset stop condition is: the straight line where the ray is located is not blocked by the subject pixel points, and has two intersections with other subject image frames.
[0015] Optionally, the method of the embodiment of the present invention further includes: determining the number of preset subject image borders, denoted as M; and taking angles obtained by equally dividing 180° by M / 2 as the preset angles.
[0016] Optionally, region growing is performed on the image to be processed to obtain various growing regions containing non-background, including:
[0017] Search a pixel point containing non-background as a non-background pixel point from the image to be processed, and put the non-background pixel point into a first set; traverse the adjacent pixel points of the non-background pixel point, and put the adjacent pixel points containing non-background into the first set; grow the adjacent pixel points put into the first set as new non-background pixel points, until all the adjacent pixel points containing non-background in the non-background pixel points put into the first set are put into the first set, thereby obtaining a growth area;
[0018] The pixel values of the pixels corresponding to the growth area in the image to be processed are set as background pixel values, and then the above step of obtaining the one growth area is performed to obtain another growth area; this step is repeated until all the pixels in the image to be processed are set as background pixel values to obtain various growth areas containing non-background.
[0019] Optionally, determining a main image in the to-be-processed picture according to each of the target growth regions includes:
[0020] The pixel values of all pixels in the image to be processed are set as background pixel values, and then merged with the target growth area to obtain a candidate image;
[0021] Searching for a pixel point containing the background from the candidate image as the background pixel point, and putting the background pixel point into the second set; traversing the adjacent pixel points of the background pixel point, and putting the adjacent pixel points containing the background into the second set; growing the adjacent pixel points put into the second set as new background pixel points, until all the adjacent pixel points containing the background among the background pixel points put into the second set are put into the second set, thereby obtaining the background area;
[0022] Pixels corresponding to the background area in the candidate image are filtered out, and each of the target growth areas after filtering is used as a main image.
[0023] Optionally, the method of the embodiment of the present invention further includes: for any pixel point, determining whether the any pixel point is a non-background pixel point or a background pixel point according to the following steps:
[0024] Determine the sum of the RGB values of any one pixel, and then determine the relationship between the sum of the RGB values of any one pixel and a preset minimum error value and a preset maximum error value; wherein,
[0025] If the sum of the RGB of any one of the pixels is less than or equal to the preset minimum error value, the any one of the pixels is determined to be a non-background pixel;
[0026] If the sum of the RGB of any one of the pixels is greater than the preset maximum error value, the any one of the pixels is determined to be a background pixel;
[0027] If the sum of the RGB of any one pixel is greater than the preset minimum error value and less than or equal to the preset maximum error value, the preset minimum error value is adjusted based on the sum of the RGB of the eight adjacent pixels of the any one pixel to obtain the corrected minimum error value; determine whether the sum of the RGB of any one pixel is less than or equal to the corrected minimum error value; if so, determine that the any one pixel is a non-background pixel; otherwise, determine that the any one pixel is a background pixel.
[0028] Optionally, the preset minimum error value is adjusted according to the following formula:
[0029] Z′=Z+D×Y
[0030] Wherein, Z′ represents the minimum value of the correction error, Z represents the minimum value of the preset error, D represents the sum of the RGB values of eight adjacent pixels, and Y represents the preset error increase.
[0031] Optionally, after determining the main image in the to-be-processed picture according to each of the target growth areas, the method further includes:
[0032] The main image is merged with a preset background image to obtain a labeled image sample corresponding to the image to be processed.
[0033] According to a second aspect of an embodiment of the present invention, there is provided a device for image subject recognition, comprising:
[0034] A region growing unit performs region growing on the image to be processed to obtain each growing region containing non-background;
[0035] A subject determination unit is configured to set a target area in the image to be processed, and select a target growth area that intersects with the target area from the various growth areas; the target area is used to indicate a range of an area where a subject in the image to be processed is located;
[0036] A subject determination unit determines a subject image in the to-be-processed picture according to each of the target growth regions.
[0037] Optionally, the image processing device of the embodiment of the present invention further includes an image determination unit, which is used to: before performing region growing on the image to be processed, filter out the image to be processed from various images according to the following steps:
[0038] Starting from the center point of the image, a first ray is made in the positive and negative directions of a preset angle respectively, and it is determined whether the straight line where the first ray is located meets the preset condition; if so, the straight line where the first ray is located is used as a main image frame of the image; otherwise, two first rays are moved along the directions of (preset angle + 90°) and (preset angle - 90°) respectively until the straight line where the first ray is located after the movement meets the preset condition, and the straight line where each first ray is located after the movement is used as a main image frame of the image; wherein the preset condition is that the number of continuous background pixel points including the endpoints of the first ray is greater than or equal to the preset number threshold;
[0039] The one preset angle is replaced by another preset angle, and then the above steps are repeated until a preset stop condition is reached, and the picture that can reach the preset stop condition among the pictures is used as the picture to be processed;
[0040] The preset stop condition is: the straight line where the ray is located is not blocked by the subject pixel points, and has two intersections with other subject image frames.
[0041] Optionally, the image determination unit is further used to: determine the number of preset subject image borders, recorded as M; and take each angle obtained by equally dividing 180° by M / 2 as each of the preset angles.
[0042] Optionally, the region growing unit performs region growing on the image to be processed to obtain each growing region containing non-background, including:
[0043] Search a pixel point containing non-background as a non-background pixel point from the image to be processed, and put the non-background pixel point into a first set; traverse the adjacent pixel points of the non-background pixel point, and put the adjacent pixel points containing non-background into the first set; grow the adjacent pixel points put into the first set as new non-background pixel points, until all the adjacent pixel points containing non-background in the non-background pixel points put into the first set are put into the first set, thereby obtaining a growth area;
[0044] The pixel values of the pixels corresponding to the growth area in the image to be processed are set as background pixel values, and then the above step of obtaining the one growth area is performed to obtain another growth area; this step is repeated until all the pixels in the image to be processed are set as background pixel values to obtain various growth areas containing non-background.
[0045] Optionally, the subject determination unit determines a subject image in the to-be-processed picture according to each of the target growth regions, including:
[0046] The pixel values of all pixels in the image to be processed are set as background pixel values, and then merged with the target growth area to obtain a candidate image;
[0047] Searching for a pixel point containing the background from the candidate image as the background pixel point, and putting the background pixel point into the second set; traversing the adjacent pixel points of the background pixel point, and putting the adjacent pixel points containing the background into the second set; growing the adjacent pixel points put into the second set as new background pixel points, until all the adjacent pixel points containing the background among the background pixel points put into the second set are put into the second set, thereby obtaining the background area;
[0048] Pixels corresponding to the background area in the candidate image are filtered out, and each of the target growth areas after filtering is used as a main image.
[0049] Optionally, the region growing unit or the subject determination unit is further configured to:
[0050] For any pixel point, determine whether the pixel point is a non-background pixel point or a background pixel point according to the following steps:
[0051] Determine the sum of the RGB values of any one pixel, and then determine the relationship between the sum of the RGB values of any one pixel and a preset minimum error value and a preset maximum error value; wherein,
[0052] If the sum of the RGB of any one of the pixels is less than or equal to the preset minimum error value, the any one of the pixels is determined to be a non-background pixel;
[0053] If the sum of the RGB of any one of the pixels is greater than the preset maximum error value, the any one of the pixels is determined to be a background pixel;
[0054] If the sum of the RGB of any one pixel is greater than the preset minimum error value and less than or equal to the preset maximum error value, the preset minimum error value is adjusted based on the sum of the RGB of the eight adjacent pixels of the any one pixel to obtain the corrected minimum error value; determine whether the sum of the RGB of any one pixel is less than or equal to the corrected minimum error value; if so, determine that the any one pixel is a non-background pixel; otherwise, determine that the any one pixel is a background pixel.
[0055] Optionally, the preset minimum error value is adjusted according to the following formula:
[0056] Z′=Z+D×Y
[0057] Wherein, Z′ represents the minimum value of the correction error, Z represents the minimum value of the preset error, D represents the sum of the RGB values of eight adjacent pixels, and Y represents the preset error increase.
[0058] Optionally, the image subject recognition device of an embodiment of the present invention further includes: a sample labeling unit, which is used to: after determining the subject image in the image to be processed according to each of the target growth areas, fuse the subject image with a preset background image to obtain a labeled image sample corresponding to the image to be processed.
[0059] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for image subject recognition, comprising:
[0060] one or more processors;
[0061] a storage device for storing one or more programs,
[0062] When the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in the first aspect of the embodiment of the present invention.
[0063] According to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method provided by the first aspect of the embodiment of the present invention is implemented.
[0064] An embodiment of the above invention has the following advantages or beneficial effects: the present invention obtains a growth area through region growth, determines a theme image according to a target growth area that intersects with a target area, and can automatically complete image subject recognition, avoiding problems such as labor-intensive, slow, insufficient response speed to new images, and often failing to reach pixel level due to manual processing. By determining the target area in the image to be processed, the subject that the image really wants to highlight can be accurately found. By screening the image to be processed through the provided judgment method, and adopting the provided region growth method and region growth judgment criteria, the amount of calculation for image subject recognition in subsequent steps can be reduced, and the accuracy of edge processing can be improved. By fusing the determined subject image with the preset background image, a labeled image sample can be obtained, providing a sample for machine learning, avoiding problems such as labor-intensive, slow, insufficient response speed to new images, and often failing to reach pixel level due to manual labeling of machine learning samples.
[0065] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0066] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0067] Figure 1 is a schematic diagram of the main process of the method for image subject recognition in an embodiment of the present invention;
[0068] Figure 2 is a schematic diagram of the main process of the method for screening pictures to be processed in an embodiment of the present invention;
[0069] Figure 3 is a schematic diagram of a main image frame in an embodiment of the present invention;
[0070] Figure 4 is a schematic diagram of the main process of the method for performing region growing on a processed image in an embodiment of the present invention;
[0071] Figure 5 is a schematic diagram of a regional growth judgment criterion in an embodiment of the present invention;
[0072] Figure 6 It is a schematic diagram of the main process of performing reverse region growth on the target growth region in an embodiment of the present invention;
[0073] Figure 7 is a schematic diagram of the main components of an apparatus for image subject recognition according to an embodiment of the present invention;
[0074] Figure 8 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0075] Fig. 9 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0076] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0077] According to one aspect of an embodiment of the present invention, a method for identifying an image subject is provided.
[0078] Figure 1 FIG. 1 is a schematic diagram of the main process of the method for image subject recognition in an embodiment of the present invention. Figure 1 As shown, the method for image subject recognition includes:
[0079] Step S101, performing region growing on the image to be processed to obtain each growing region including non-background;
[0080] Step S102, setting a target area in the image to be processed, and selecting a target growing area that intersects with the target area from the various growing areas; the target area is used to indicate the range of the area where the subject in the image to be processed is located;
[0081] Step S103: determining a main image in the picture to be processed according to each of the target growth regions.
[0082] The method of the embodiment of the present invention is suitable for processing images with a solid color background and a subject surrounded by the background. By obtaining a growth area through region growth and determining a subject image according to a target growth area that intersects with a target area, the subject recognition of the image can be automatically completed, avoiding problems such as labor-intensive, slow speed, insufficient response speed to new images, and often failing to reach pixel level caused by manual processing.
[0083] The setting of the target area depends on the characteristics of the image to be processed. Taking the product display pictures in the e-commerce field as an example, in the product display pictures, the main product to be displayed is often placed near the middle of the image. Therefore, a target area can be set in the middle area of the image to be processed. Of course, when the subject is usually set in other positions in other images to be processed, such as the upper left corner, the lower right corner, etc., a target area can be set in the corresponding area of the image to be processed. The size of the target area can be selectively determined according to the actual situation, for example, the length and width of the target area are each set to 5% of the length and width of the image to be processed. In this step, all the growth areas obtained in step S101 are traversed, each growth area is judged, and the growth area that intersects with the target area is selected as the target growth area. Usually, a target growth area corresponds to a subject. If there are two or more subjects corresponding to the situation, it can be screened through multi-subject campaigns. The specific implementation method of multi-subject campaigns can be selectively determined according to the actual situation, which will not be repeated here. The present invention can accurately find the subject that the image really wants to highlight by determining the target area in the image to be processed.
[0084] The method for image subject recognition of the embodiment of the present invention is particularly suitable for the image to be processed with a solid background color. Optionally, before performing region growth on the image to be processed, the method further includes: selecting the image to be processed from each image according to the following steps:
[0085] Starting from the center point of the image, a first ray is made in the positive and negative directions of a preset angle respectively, and it is determined whether the straight line where the first ray is located meets the preset condition; if so, the straight line where the first ray is located is used as a main image frame of the image; otherwise, two first rays are moved along the directions of (preset angle + 90°) and (preset angle - 90°) respectively until the straight line where the first ray is located after the movement meets the preset condition, and the straight line where each first ray is located after the movement is used as a main image frame of the image; wherein the preset condition is that the number of continuous background pixel points including the endpoints of the first ray is greater than or equal to the preset number threshold;
[0086] The one preset angle is replaced by another preset angle, and then the above steps are repeated until a preset stop condition is reached, and the picture that can reach the preset stop condition among the pictures is used as the picture to be processed;
[0087] The preset stop condition is: the straight line where the ray is located is not blocked by the subject pixel points, and has two intersections with other subject image frames.
[0088] Figure 2 Schematic diagram of the main process of the method for selecting images to be processed in an embodiment of the present invention. For any image, the following steps are followed to determine whether it can be used as an image to be processed:
[0089] Step S201, starting from the center point of the image, make two first rays in the positive and negative directions of the i-th preset angle; i represents a positive integer, and under the initial condition, i=1; jump to step S202;
[0090] Step S202, determining whether the number of continuous background pixel points including the first ray endpoint in the straight line where the first ray is located is greater than or equal to a preset number threshold; if so, jump to step S204; otherwise, jump to step S203;
[0091] Step S203, moving one first ray along the direction of (preset angle + 90°), moving another first ray along the direction of (preset angle - 90°), and then jumping to step S202;
[0092] Step S204, taking the straight line where the first ray is located as a main image frame of the picture; jumping to step S205;
[0093] Step S205, determine whether the preset stop condition is met; if so, jump to step S206; otherwise, i+1, and then jump to step S201;
[0094] Step S206: determine that the image can be used as the image to be processed, and the process ends.
[0095] Background pixels refer to pixels that contain the background. Performing image subject recognition based on a to-be-processed image with a pure color background can reduce the amount of computation required for image subject recognition in subsequent steps and greatly improve the recognition speed. Performing image subject recognition based on a to-be-processed image with a pure color background and obtaining annotated image samples can greatly improve the speed of annotating samples and enable the annotated image samples to reach the pixel level.
[0096] The size and number of preset angles can be selectively determined according to actual conditions. For example, there are 4 preset angles, namely 0°, 90°, 45°, and 135°. Optionally, the image processing method of an embodiment of the present invention further includes: determining the number of preset subject image borders, recorded as M; taking each angle obtained by dividing 180° by M / 2 as each of the preset angles. Exemplarily, the number of preset subject image borders X=8, X / 2=4, so the preset angles are 0°, 90°, 45°, and 135°, which are 180° divided into 4 equal parts.
[0097] If the number of preset main image borders is increased and removed Figure 2 The stop condition in the screening process shown can determine the boundary of the subject image closer to the subject image itself. However, due to the irregularity of the subject, it is impossible to completely fit the boundary of the subject image. Figure 2 The stop condition in the screening process shown can screen out more images to be processed, but the amount of computation for subject recognition and labeling based on the screened images to be processed will also increase.
[0098] The present invention determines by screening whether an image can be used as the image to be processed in this embodiment for subsequent subject image recognition and annotation. In order to reduce the amount of calculation, the number of preset subject image borders can be set to a smaller value, such as 8, so that a considerable number of images to be processed can be determined with a very small amount of calculation.
[0099] By equally dividing each preset angle, it is easy to adjust the actual number of frames. It should be noted that although the number of preset main image frames is determined in this example, it does not mean that the number of main image frames finally obtained is the preset number. Figure 2 When the method shown is used for screening, if the preset stop condition is reached, the process will stop even if the number of subject image borders obtained is less than the preset number.
[0100] Figure 3 It is a schematic diagram of the main image frame in an embodiment of the present invention. In the figure, A1, A2, A3, A4 and A5 represent a main image frame respectively. In this example, rays are made in the positive and negative directions of 0° to form two main image frames formed by translating in the direction of 0°+90°=90° and 0°-90°=-90°, which are recorded as A1 and A2. Rays are made in the positive and negative directions of 90° to form two main image frames formed by translating in the direction of 90°+90°=180° and 90°-90°=0°, which are recorded as A3 and A4. At this time, A1 and A3 are blocked by the main pixel points in the picture respectively, and fail to form two intersections with other main image frames. Therefore, another ray is made in the positive and negative directions of 45°, and a main image frame is formed by translating in the direction of 45°+90°=135°, which is recorded as A5. At this point, each of A1, A2, A3, A4, and A5 forms an intersection with the other two subject image frames, reaching the stop condition, exiting the loop, and the subject in the image is judged to be surrounded by the background and can be used as a to-be-processed image.
[0101] Optionally, region growing is performed on the image to be processed to obtain various growing regions containing non-background, including:
[0102] Search a pixel point containing non-background as a non-background pixel point from the image to be processed, and put the non-background pixel point into a first set; traverse the adjacent pixel points of the non-background pixel point, and put the adjacent pixel points containing non-background into the first set; grow the adjacent pixel points put into the first set as new non-background pixel points, until all the adjacent pixel points containing non-background in the non-background pixel points put into the first set are put into the first set, thereby obtaining a growth area;
[0103] The pixel values of the pixels corresponding to the growth area in the image to be processed are set as background pixel values, and then the above step of obtaining the one growth area is performed to obtain another growth area; this step is repeated until all the pixels in the image to be processed are set as background pixel values to obtain various growth areas containing non-background.
[0104] Figure 4 FIG. 1 is a schematic diagram of the main process of the method for performing region growing on a processed image in an embodiment of the present invention. Figure 4 As shown in Figure 2, the main process of regional growth is:
[0105] Step S401, searching a pixel point containing non-background as a non-background pixel point from the image to be processed, and putting the non-background pixel point into a first set; jumping to step S402;
[0106] Step S402, traverse the adjacent pixels of the non-background pixel, and put the adjacent pixels containing the non-background into the first set; jump to step S403;
[0107] Step S403, taking the adjacent pixel points put into the first set as new non-background pixel points; jumping to step S404;
[0108] Step S404, determine whether all the non-background pixels among the adjacent pixels are put into the first set; if so, jump to step S405; otherwise, jump to step S402;
[0109] Step S405, determine whether all pixels in the image to be processed are set to background pixel values; if so, jump to step S406; otherwise, x+1, jump to step S401;
[0110] Step S406: Obtain each growth region including non-background.
[0111] Non-background pixel points refer to pixel points other than background pixel points. In actual application, when a pixel point is determined not to be a background pixel point, the pixel point can be determined to be a non-background pixel point. Background pixel points refer to pixel points containing background. Background pixel values refer to pixel values of background pixel points. Each region formed in the first set is a growth region, and each growth region corresponds to a subject. The region growth method provided by the present invention can find out all growth regions containing non-background.
[0112] Alternatively, if Figure 6 As shown, for each target growth area, determining the main image in the to-be-processed picture according to the target growth area includes:
[0113] Step S601, setting the pixel values of all pixels in the image to be processed as background pixel values, and then merging them with the target growth area to obtain a candidate image;
[0114] Step S602: searching for a pixel point containing a background from the candidate image as a background pixel point, and putting the background pixel point into a second set;
[0115] Step S603, traversing the adjacent pixel points of the background pixel point, and putting the adjacent pixel points containing the background into a second set;
[0116] Step S604: taking the adjacent pixel points put into the second set as new background pixel points;
[0117] Step S605, judging whether all the pixels including the background in the adjacent pixels of the background pixels put into the second set are put into the second set; if so, obtaining the background area, and then jumping to step S606; otherwise, jumping to step S603;
[0118] Step S606: Filter out the pixel points corresponding to each of the background areas in the candidate images, and use each of the candidate images after filtering as a main image, and the process ends.
[0119] The present invention can remove background pixels in the candidate image through reverse region growth, thereby further improving the accuracy of edge processing.
[0120] Optionally, for any pixel point, determine whether the any pixel point is a non-background pixel point or a background pixel point according to the following steps:
[0121] Determine the sum of the RGB values of any one pixel, and then determine the relationship between the sum of the RGB values of any one pixel and a preset minimum error value and a preset maximum error value; wherein,
[0122] If the sum of the RGB of any one of the pixels is less than or equal to the preset minimum error value, the any one of the pixels is determined to be a non-background pixel;
[0123] If the sum of the RGB of any one of the pixels is greater than the preset maximum error value, the any one of the pixels is determined to be a background pixel;
[0124] If the sum of the RGB of any one pixel is greater than the preset minimum error value and less than or equal to the preset maximum error value, the preset minimum error value is adjusted based on the sum of the RGB of the eight adjacent pixels of the any one pixel to obtain the corrected minimum error value; determine whether the sum of the RGB of any one pixel is less than or equal to the corrected minimum error value; if so, determine that the any one pixel is a non-background pixel; otherwise, determine that the any one pixel is a background pixel.
[0125] The values of the preset minimum error value and the preset maximum error value can be selectively determined according to actual conditions, and will not be repeated here. The present invention can accurately determine whether a certain pixel point is a main pixel point or a background pixel point through the above-mentioned region growth judgment criterion, thereby improving the accuracy of edge processing.
[0126] Optionally, the preset minimum error value is adjusted according to the following formula:
[0127] Z′=Z+D×Y
[0128] Wherein, Z′ represents the minimum value of the correction error, Z represents the minimum value of the preset error, D represents the sum of the RGB values of eight adjacent pixels, and Y represents the preset error increase.
[0129] For example, Figure 5 As shown, the step of determining whether a pixel is a non-background pixel includes:
[0130] Step S501, determining the sum of the RGB values of the pixel, denoted as C;
[0131] Step S502, determine the relationship between the sum C of the RGB values of the pixel, the preset minimum error value (recorded as Z), and the preset maximum error value (recorded as X); if C>X, jump to step S503; if C≤Z, jump to step S504; if Z<C is less than or equal to X, jump to step S505;
[0132] Step S503, determining that the one pixel is a background pixel;
[0133] Step S504, determining that the one pixel is a non-background pixel;
[0134] Step S505, Z′=Z+D×Y, then jump to step S506;
[0135] Step S506, determine whether C≤Z′ is established; if so, jump to step S507; otherwise, jump to step S508;
[0136] Step S507, determining that the one pixel is a non-background pixel;
[0137] Step S508: determine that the one pixel is a background pixel.
[0138] By adjusting the preset minimum error value based on the sum of RGB of eight adjacent pixels, the accuracy of subject recognition and the precision of edge processing can be improved.
[0139] Optionally, after determining the main image in the picture to be processed according to each of the target growth areas, it also includes: fusing the main image with a preset background image to obtain an annotated image sample corresponding to the picture to be processed. When performing image fusion, the subject image can be reduced to a specified size that is smaller than the preset background image. Then, the area to be fused on the preset background image is selected, and the pixel values of the pixels corresponding to the main image in the area to be fused are replaced with the pixel values of the corresponding pixels on the subject image. All pixel positions occupied by the main image in the fused image are retained as annotated data, and the annotated image samples formed by the fusion are added, which is the annotated data that can be used as machine learning samples.
[0140] Compared with the prior art of manually labeling samples, the present invention can automatically complete image subject recognition, avoid the problems of labor-intensive, slow speed, insufficient response to new images, and often failing to reach pixel level caused by manual processing, and improve the accuracy of edge processing.
[0141] In the embodiment of the present invention, each picture used to screen the pictures to be processed can be a product display picture in the field of e-commerce. Although the implementation of the present invention does not use all pictures as pictures to be processed, but screens out the pictures to be processed from each picture, the product display pictures in the field of e-commerce are often massive (billions or even tens of billions of levels), and even for the same product, there are often multiple e-commerce platforms selling it, and different e-commerce platforms process the product display pictures differently. Even if only one of the 100 pictures is suitable, the annotation data of the screened pictures to be processed after processing is far greater than the annotation amount required for machine learning. In addition, since the processing of the product display pictures in the field of e-commerce can be reflected at the pixel level, it is not necessary to find the picture boundary without a large number of operations such as gradual, gradient, local maximum or convolution, so that the calculation amount of image subject recognition can be reduced, and the recognition and annotation speed can be improved. A product display picture often mainly displays 1 to 2 kinds of goods, making it extremely simple to determine the subject to be screened out. The main products reflected in the product display picture are often artificially placed in the center of the picture, which is convenient for accurately finding the subject to be expressed by the picture.
[0142] According to a second aspect of an embodiment of the present invention, a device for implementing the above method is provided.
[0143] Figure 7 FIG. 1 is a schematic diagram of the main components of an apparatus for image subject recognition according to an embodiment of the present invention. Figure 7 As shown, the image subject recognition device 700 includes:
[0144] A region growing unit 701 performs region growing on the image to be processed to obtain each growing region including non-background;
[0145] The subject determination unit 702 sets a target area in the image to be processed, and selects a target growing area that intersects with the target area from the various growing areas; the target area is used to indicate the range of the area where the subject in the image to be processed is located;
[0146] The subject determination unit 703 determines a subject image in the to-be-processed picture according to each of the target growth regions.
[0147] Optionally, the image processing device of the embodiment of the present invention further includes an image determination unit, which is used to: before performing region growing on the image to be processed, filter out the image to be processed from various images according to the following steps:
[0148] Starting from the center point of the image, a first ray is made in the positive and negative directions of a preset angle respectively, and it is determined whether the straight line where the first ray is located meets the preset condition; if so, the straight line where the first ray is located is used as a main image frame of the image; otherwise, two first rays are moved along the directions of (preset angle + 90°) and (preset angle - 90°) respectively until the straight line where the first ray is located after the movement meets the preset condition, and the straight line where each first ray is located after the movement is used as a main image frame of the image; wherein the preset condition is that the number of continuous background pixel points including the endpoints of the first ray is greater than or equal to the preset number threshold;
[0149] The one preset angle is replaced by another preset angle, and then the above steps are repeated until a preset stop condition is reached, and the picture that can reach the preset stop condition among the pictures is used as the picture to be processed;
[0150] The preset stop condition is: the straight line where the ray is located is not blocked by the subject pixel points, and has two intersections with other subject image frames.
[0151] Optionally, the image determination unit is further used to: determine the number of preset subject image borders, recorded as M; and take each angle obtained by equally dividing 180° by M / 2 as each of the preset angles.
[0152] Optionally, the region growing unit performs region growing on the image to be processed to obtain each growing region containing non-background, including:
[0153] Search a pixel point containing non-background as a non-background pixel point from the image to be processed, and put the non-background pixel point into a first set; traverse the adjacent pixel points of the non-background pixel point, and put the adjacent pixel points containing non-background into the first set; grow the adjacent pixel points put into the first set as new non-background pixel points, until all the adjacent pixel points containing non-background in the non-background pixel points put into the first set are put into the first set, thereby obtaining a growth area;
[0154] The pixel values of the pixels corresponding to the growth area in the image to be processed are set as background pixel values, and then the above step of obtaining the one growth area is performed to obtain another growth area; this step is repeated until all the pixels in the image to be processed are set as background pixel values to obtain various growth areas containing non-background.
[0155] Optionally, the subject determination unit determines a subject image in the to-be-processed picture according to each of the target growth regions, including:
[0156] The pixel values of all pixels in the image to be processed are set as background pixel values, and then merged with the target growth area to obtain a candidate image;
[0157] Searching for a pixel point containing the background from the candidate image as the background pixel point, and putting the background pixel point into the second set; traversing the adjacent pixel points of the background pixel point, and putting the adjacent pixel points containing the background into the second set; growing the adjacent pixel points put into the second set as new background pixel points, until all the adjacent pixel points containing the background among the background pixel points put into the second set are put into the second set, thereby obtaining the background area;
[0158] Pixels corresponding to the background area in the candidate image are filtered out, and each of the target growth areas after filtering is used as a main image.
[0159] Optionally, the region growing unit or the subject determination unit is further configured to: for any pixel point, determine whether the any pixel point is a non-background pixel point or a background pixel point according to the following steps:
[0160] Determine the sum of the RGB values of any one pixel, and then determine the relationship between the sum of the RGB values of any one pixel and a preset minimum error value and a preset maximum error value; wherein,
[0161] If the sum of the RGB of any one of the pixels is less than or equal to the preset minimum error value, the any one of the pixels is determined to be a non-background pixel;
[0162] If the sum of the RGB of any one of the pixels is greater than the preset maximum error value, the any one of the pixels is determined to be a background pixel;
[0163] If the sum of the RGB of any one pixel is greater than the preset minimum error value and less than or equal to the preset maximum error value, the preset minimum error value is adjusted based on the sum of the RGB of the eight adjacent pixels of the any one pixel to obtain the corrected minimum error value; determine whether the sum of the RGB of any one pixel is less than or equal to the corrected minimum error value; if so, determine that the any one pixel is a non-background pixel; otherwise, determine that the any one pixel is a background pixel.
[0164] Optionally, the region growing unit or the subject determination unit adjusts the preset minimum error value according to the following formula:
[0165] Z′=Z+D×Y
[0166] Wherein, Z′ represents the minimum value of the correction error, Z represents the minimum value of the preset error, D represents the sum of the RGB values of eight adjacent pixels, and Y represents the preset error increase.
[0167] Optionally, the image subject recognition device of an embodiment of the present invention further includes: a sample labeling unit, which is used to: after determining the subject image in the image to be processed according to each of the target growth areas, fuse the subject image with a preset background image to obtain a labeled image sample corresponding to the image to be processed.
[0168] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for image subject recognition, comprising:
[0169] one or more processors;
[0170] a storage device for storing one or more programs,
[0171] When the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in the first aspect of the embodiment of the present invention.
[0172] According to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method provided by the first aspect of the embodiment of the present invention is implemented.
[0173] Figure 8 An exemplary system architecture 800 is shown to which the method or apparatus for image subject recognition according to the embodiments of the present invention may be applied.
[0174] like Figure 8 As shown, system architecture 800 may include terminal devices 801, 802, 803, a network 804, and a server 805. Network 804 is used to provide a medium for communication links between terminal devices 801, 802, 803 and server 805. Network 804 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0175] Users can use terminal devices 801, 802, and 803 to interact with server 805 through network 804 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 801, 802, and 803, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0176] The terminal devices 801 , 802 , and 803 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0177] The server 805 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 801, 802, and 803. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.
[0178] It should be noted that the method for image subject recognition provided in the embodiment of the present invention is generally executed by the server 805 , and accordingly, the image subject recognition device is generally disposed in the server 805 .
[0179] It should be understood that Figure 8 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0180] Reference below Fig. 9 , which shows a schematic diagram of the structure of a computer system 900 of a terminal device suitable for implementing an embodiment of the present invention. Fig. 9 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0181] like Fig. 9 As shown, the computer system 900 includes a central processing unit (CPU) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage part 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the system 900 are also stored. The CPU 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0182] The following components are connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed, so that a computer program read therefrom is installed into the storage section 908 as needed.
[0183] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 909, and / or installed from the removable medium 911. When the computer program is executed by the central processing unit (CPU) 901, the above-mentioned functions defined in the system of the present invention are executed.
[0184] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0185] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0186] The units involved in the embodiments of the present invention may be implemented in software or hardware. The units described may also be set in a processor, for example, may be described as: a processor comprising: a region growth unit, which performs region growth on the image to be processed and obtains various growth regions containing non-background; a subject determination unit, which sets a target region in the image to be processed and selects target growth regions that intersect with the target region from the various growth regions; the target region is used to indicate the range of the region where the subject in the image to be processed is located; a subject determination unit, which determines the subject image in the image to be processed according to each target growth region. Among them, the names of these units do not constitute a limitation on the unit itself in some cases. For example, the region growth unit may also be described as "a unit that determines the subject image in the image to be processed according to each target growth region".
[0187] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently and not be assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: performing region growth on the image to be processed, obtaining various growth regions containing non-background; setting a target region in the image to be processed, and screening target growth regions that have intersections with the target region from the various growth regions; the target region is used to indicate the range of the region where the subject in the image to be processed is located; and determining the subject image in the image to be processed according to each of the target growth regions.
[0188] According to the technical solution of the embodiment of the present invention, by obtaining the growth area through regional growth and determining the theme image according to the target growth area that intersects with the target area, the image subject recognition can be automatically completed, avoiding the problems of labor-consuming, slow speed, insufficient response speed to new images, and often failing to reach the pixel level due to manual processing. By determining the target area in the image to be processed, the subject that the image really wants to highlight can be accurately found. By screening the image to be processed through the provided judgment method, and adopting the provided regional growth method and regional growth judgment criterion, the amount of calculation for image subject recognition in subsequent steps can be reduced, and the accuracy of edge processing can be improved. By fusing the determined subject image with the preset background image, a labeled image sample can be obtained to provide a sample for machine learning, avoiding the problems of labor-consuming, slow speed, insufficient response speed to new images, and often failing to reach the pixel level due to manual labeling of machine learning samples.
[0189] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for identifying an image subject, It is characterized in that include: Perform region growth on the image to be processed to obtain each growth region containing non-background; Setting a target area in the image to be processed, and selecting a target growth area that intersects with the target area from the various growth areas; The target area is used to indicate the range of the area where the subject in the image to be processed is located; Determine a main image in the picture to be processed according to each of the target growth areas; Performing region growth on the image to be processed to obtain various growth regions containing non-background, including: searching a pixel point containing non-background as a non-background pixel point from the image to be processed, and placing the non-background pixel point into a first set; traversing the adjacent pixel points of the non-background pixel point, and placing the adjacent pixel points containing non-background into the first set; growing the adjacent pixel points placed in the first set as new non-background pixel points, until all the adjacent pixel points containing non-background pixels placed in the first set are placed in the first set, thereby obtaining a growth region; setting the pixel values of the pixel points corresponding to the growth region in the image to be processed as background pixel values, and then executing the above step of obtaining the one growth region to obtain another growth region; repeating this step until all the pixel points in the image to be processed are set as background pixel values, thereby obtaining various growth regions containing non-background; Determine the main image in the image to be processed according to each of the target growth areas, including: setting the pixel values of all pixels in the image to be processed as background pixel values, and then fusing them with the target growth area to obtain a candidate image; searching for a pixel containing the background from the candidate image as a background pixel, and putting the background pixel into a second set; traversing the adjacent pixels of the background pixel, and putting the adjacent pixels containing the background into the second set; growing the adjacent pixels put into the second set as new background pixels, until all the adjacent pixels containing the background among the background pixels put into the second set are put into the second set to obtain a background area; and filtering out the pixels corresponding to the background area in the candidate image, and taking each of the target growth areas after filtering out as a main image.
2. The method according to claim 1, It is characterized in that Before performing region growing on the image to be processed, the method further includes: selecting the image to be processed from each image according to the following steps: Starting from the center point of the image, a first ray is made in the positive and negative directions of a preset angle respectively, and it is determined whether the straight line where the first ray is located meets the preset condition; if so, the straight line where the first ray is located is used as a main image frame of the image; otherwise, two first rays are moved along the directions of (preset angle + 90°) and (preset angle - 90°) respectively until the straight line where the first ray is located after the movement meets the preset condition, and the straight line where each first ray is located after the movement is used as a main image frame of the image; wherein the preset condition is that the number of continuous background pixel points including the endpoints of the first ray is greater than or equal to the preset number threshold; The one preset angle is replaced by another preset angle, and then the above steps are repeated until a preset stop condition is reached, and the picture that can reach the preset stop condition among the pictures is used as the picture to be processed; The preset stop condition is: the straight line where the ray is located is not blocked by the subject pixel points, and has two intersections with other subject image frames.
3. The method according to claim 2, It is characterized in that Also includes: The number of preset subject image frames is determined, which is recorded as M; and each angle obtained by equally dividing 180° by M / 2 is used as each of the preset angles.
4. The method according to claim 1, It is characterized in that Also includes: For any pixel point, determine whether the pixel point is a non-background pixel point or a background pixel point according to the following steps: Determine the sum of the RGB values of any one pixel, and then determine the relationship between the sum of the RGB values of any one pixel and a preset minimum error value and a preset maximum error value; wherein, If the sum of the RGB of any one of the pixels is less than or equal to the preset minimum error value, the any one of the pixels is determined to be a non-background pixel; If the sum of the RGB of any one of the pixels is greater than the preset maximum error value, the any one of the pixels is determined to be a background pixel; If the sum of the RGB of any one pixel is greater than the preset minimum error value and less than or equal to the preset maximum error value, the preset minimum error value is adjusted based on the sum of the RGB of the eight adjacent pixels of the any one pixel to obtain the corrected minimum error value; determine whether the sum of the RGB of any one pixel is less than or equal to the corrected minimum error value; if so, determine that the any one pixel is a non-background pixel; otherwise, determine that the any one pixel is a background pixel.
5. The method according to claim 4, It is characterized in that The preset minimum error value is adjusted according to the following formula: Z′=ZZ+DXY Wherein, Z′ represents the minimum value of the correction error, Z represents the minimum value of the preset error, D represents the sum of the RGB values of eight adjacent pixels, and Y represents the preset error increase.
6. The method according to claim 1, It is characterized in that After determining the main image in the to-be-processed picture according to each of the target growth areas, the method further includes: The main image is merged with a preset background image to obtain a labeled image sample corresponding to the image to be processed.
7. A device for identifying an image subject, It is characterized in that include: A region growing unit performs region growing on the image to be processed to obtain each growing region containing non-background; A subject determination unit is configured to set a target area in the image to be processed, and select a target growth area that intersects with the target area from the various growth areas; the target area is used to indicate a range of an area where a subject in the image to be processed is located; A subject determination unit, which determines a subject image in the picture to be processed according to each target growth area; Performing region growth on the image to be processed to obtain various growth regions containing non-background, including: searching a pixel point containing non-background as a non-background pixel point from the image to be processed, and placing the non-background pixel point into a first set; traversing the adjacent pixel points of the non-background pixel point, and placing the adjacent pixel points containing non-background into the first set; growing the adjacent pixel points placed in the first set as new non-background pixel points, until all the adjacent pixel points containing non-background pixels placed in the first set are placed in the first set, thereby obtaining a growth region; setting the pixel values of the pixel points corresponding to the growth region in the image to be processed as background pixel values, and then executing the above step of obtaining the one growth region to obtain another growth region; repeating this step until all the pixel points in the image to be processed are set as background pixel values, thereby obtaining various growth regions containing non-background; Determine the main image in the image to be processed according to each of the target growth areas, including: setting the pixel values of all pixels in the image to be processed as background pixel values, and then fusing them with the target growth area to obtain a candidate image; searching for a pixel containing the background from the candidate image as a background pixel, and putting the background pixel into a second set; traversing the adjacent pixels of the background pixel, and putting the adjacent pixels containing the background into the second set; growing the adjacent pixels put into the second set as new background pixels, until all the adjacent pixels containing the background among the background pixels put into the second set are put into the second set to obtain a background area; and filtering out the pixels corresponding to the background area in the candidate image, and taking each of the target growth areas after filtering out as a main image.
8. An electronic device for image subject recognition, It is characterized in that include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.
9. A computer readable medium having a computer program stored thereon, It is characterized in that When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
