Image processing method, apparatus, device, storage medium and program product
By acquiring images of samples of the same type and sorting their grayscale values, a target image is generated, which solves the problem of low detection accuracy caused by defects in the reference sample and improves the accuracy of sample detection.
Patent Information
- Application Number
- CN202511266639.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-05
- Publication Date
- 2025-12-30
- Estimated Expiration
- 2045-09-05
AI Technical Summary
In the existing technology, when quality inspection is carried out by manually selecting reference samples, the accuracy of the test results is low due to the inconsistency of the process and the presence of defects in the reference samples, which affects the product quality.
Images are acquired from the same location of multiple candidate samples of the same type to obtain candidate images. The gray values of their pixels are sorted, the target gray value that meets the gray value conditions is determined, and the target image is generated to improve detection accuracy.
By sorting the grayscale values of the pixels of candidate samples, a target image that meets the sample conditions is generated, which improves the accuracy of sample detection results.
Smart Images

Figure CN120807493B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of image processing technology, and in particular relates to image processing methods, apparatus, devices, storage media and program products. Background Technology
[0002] With technological advancements, during the product manufacturing process, each sample to be produced is tested, and only those samples that meet the factory conditions are selected to ensure the quality of the final product.
[0003] In related technologies, a reference sample that meets the factory conditions is selected from multiple samples, and other samples are tested for quality based on the reference sample.
[0004] However, for the same type of sample, due to the consistency of the process, the produced reference samples may also have certain defects. Therefore, the reference value corresponding to the manually selected reference samples is low, which will result in low accuracy of the sample test results and thus affect product quality. Summary of the Invention
[0005] This application provides an image processing method, apparatus, device, storage medium, and program product. After acquiring images of the same part of different candidate samples, the gray values of the pixels in the region where the candidate samples are located are sorted, and a target gray value that meets the gray value conditions is selected to generate a target image corresponding to the target sample. This is used to improve the quality of the target sample in the target image, thereby improving the accuracy of sample detection.
[0006] In a first aspect, embodiments of this application provide an image processing method, the method comprising:
[0007] Acquire candidate images corresponding to multiple candidate samples, wherein the multiple candidate samples are samples of the same type, and the candidate image refers to the image obtained after image acquisition of the first part of the candidate sample at a preset angle, wherein the first part corresponding to the multiple candidate samples is the same, and the preset angle corresponding to the multiple candidate samples is the same.
[0008] Obtain the candidate grayscale values corresponding to multiple pixels in the regions where the multiple candidate samples are located in the multiple candidate images;
[0009] Sort multiple candidate grayscale values to obtain sorting results corresponding to each candidate grayscale value;
[0010] Based on the sorting result, multiple target gray values that meet the first gray value condition are determined from the multiple candidate gray values, and a target image is obtained based on the multiple target gray values. The target image includes a target sample, and the target sample meets the first sample condition.
[0011] Optionally, determining multiple target grayscale values that meet the first grayscale condition from the multiple candidate grayscale values based on the sorting result includes:
[0012] From the plurality of candidate gray values, a plurality of candidate gray values that fall within a first range in the sorting result are determined as the plurality of target gray values.
[0013] Optionally, determining from the plurality of candidate grayscale values that fall within a first range in the sorting result, as the plurality of target grayscale values, includes:
[0014] Obtain grayscale value segmentation rules, which are used to classify the multiple candidate grayscale values in the sorting result. The grayscale value segmentation rules include multiple candidate ranges, and the multiple candidate ranges include the first range.
[0015] Based on the sorting results and the multiple candidate ranges, the multiple candidate gray values are numerically classified to obtain the classification results corresponding to the multiple candidate ranges respectively.
[0016] The plurality of candidate grayscale values within the first range are obtained as the plurality of target grayscale values.
[0017] Optionally, the plurality of candidate ranges are arranged in a preset range order, wherein the first range is located at the median position among the plurality of candidate ranges.
[0018] Optionally, determining multiple target grayscale values that meet the first grayscale condition from the multiple candidate grayscale values based on the sorting result includes:
[0019] Based on the sorting result, a first position and a second position are determined. The first position is the starting position for determining the multiple target gray values from the multiple candidate gray values, and the second position is the ending position for determining the multiple target gray values from the multiple candidate gray values.
[0020] Using the first position as the starting position and the second position as the ending position, the plurality of candidate gray values in the sorting result that are between the first position and the second position are determined as the plurality of target gray values.
[0021] Optionally, the plurality of candidate grayscale values includes the i-th candidate grayscale value, where i is a positive integer;
[0022] After sorting the multiple candidate grayscale values to obtain the sorting results corresponding to the multiple candidate grayscale values, the method further includes:
[0023] Obtain the second grayscale condition;
[0024] If the i-th candidate grayscale value does not meet the second grayscale condition, the i-th candidate grayscale value is removed from the sorting result to obtain the adjusted sorting result;
[0025] The step of determining multiple target grayscale values that meet the first grayscale condition from the multiple candidate grayscale values based on the sorting result includes:
[0026] Based on the adjusted sorting results, the plurality of target gray values that meet the first gray value condition are determined from the plurality of candidate gray values.
[0027] Optionally, obtaining the candidate grayscale values corresponding to multiple pixels in the regions where the multiple candidate samples are located in the multiple candidate images includes:
[0028] Image alignment is performed on multiple candidate images to obtain aligned images corresponding to the multiple candidate images respectively, wherein the candidate sample is located in a first region in the aligned image, and the first region in which the multiple candidate samples are located is the same in the multiple aligned images;
[0029] Obtain the candidate grayscale values corresponding to multiple pixels in the first region of the multiple aligned images.
[0030] Secondly, embodiments of this application provide an image processing apparatus, including:
[0031] The acquisition module is used to acquire candidate images corresponding to multiple candidate samples, wherein the multiple candidate samples are samples of the same type, and the candidate image refers to the image obtained after image acquisition of the first part of the candidate sample at a preset angle. The first part corresponding to the multiple candidate samples is the same, and the preset angle corresponding to the multiple candidate samples is the same.
[0032] The acquisition module is further configured to acquire candidate grayscale values corresponding to multiple pixels in the regions where the multiple candidate samples are located in the multiple candidate images.
[0033] The sorting module is used to sort multiple candidate grayscale values to obtain sorting results corresponding to the multiple candidate grayscale values respectively;
[0034] The determining module is configured to determine multiple target gray values that meet a first gray value condition from the multiple candidate gray values based on the sorting result, and obtain a target image based on the multiple target gray values, wherein the target image includes a target sample and the target sample meets the first sample condition.
[0035] Thirdly, embodiments of this application provide a computer device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the image processing method described in any one of the first aspects above.
[0036] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the image processing method described in any one of the first aspects.
[0037] Fifthly, embodiments of this application provide a computer program product that, when run on a computer device, causes the computer device to perform the image processing method described in any one of the first aspects.
[0038] It is understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here.
[0039] The beneficial effects of the technical solutions provided in this application include at least the following:
[0040] Multiple candidate images are obtained by acquiring images of the same location of multiple candidate samples belonging to the same type at the same angle. The grayscale values of the pixels in the regions where the candidate samples are located in these candidate images are then sorted to obtain a sorting result. Finally, based on the sorting result, multiple target grayscale values that meet a first grayscale condition are determined to generate a target image containing the target sample, where the target sample meets the first sample condition. In other words, for sample images corresponding to different samples, the grayscale values of the pixels in the regions where the candidate samples are located in the sample images are sorted, and grayscale values that meet the conditions are selected to generate the target image. This ensures that the sample in the target image meets the sample condition, improving the accuracy of the sample image and thus improving the accuracy of the sample detection results. Attached Figure Description
[0041] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0042] Figure 1 This is a flowchart of an image processing method provided in an embodiment of this application;
[0043] Figure 2 This is a flowchart of an image processing method provided in an embodiment of this application;
[0044] Figure 3 This is a schematic diagram of an image processing method provided in an embodiment of this application;
[0045] Figure 4 This is a structural diagram of the image processing apparatus provided in the embodiments of this application;
[0046] Figure 5 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0047] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0048] It should be understood that, when used in this application specification and the appended claims, the term "comprising" indicates the presence of the described features, integrals, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or a collection thereof.
[0049] It should also be understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.
[0050] As used in this application specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrase "if determined" or "if detected [the described condition or event]" may be interpreted, depending on the context, as meaning "once determined," "in response to determination," "once detected [the described condition or event]," or "in response to detection [the described condition or event]."
[0051] Furthermore, in the description of this application and the appended claims, the terms "first," "second," "third," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0052] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.
[0053] In related technologies, a reference sample that meets the factory conditions is manually selected from multiple samples, and other samples are then tested against this reference sample. However, for the same type of sample, due to the consistency of the process, the produced reference sample may also have certain defects. Therefore, the reference value corresponding to the manually selected reference sample is low, which leads to low accuracy of the sample test results and thus affects product quality.
[0054] Based on this, embodiments of this application provide an image processing method. Multiple candidate images are obtained by acquiring images of the same location of multiple candidate samples of the same type from the same angle. The grayscale values of pixels in the regions where the candidate samples are located in the multiple candidate images are sorted to obtain a sorting result. Finally, multiple target grayscale values that meet a first grayscale condition are determined based on the sorting result to generate a target image containing the target sample, wherein the target sample meets the first sample condition. In other words, for sample images corresponding to different samples, the grayscale values of pixels in the regions where the candidate samples are located in the sample images are sorted, and grayscale values that meet the conditions are selected to generate the target image, so that the sample in the target image meets the sample condition, improving the accuracy of the sample image and thus improving the accuracy of the sample detection results.
[0055] The image processing method provided in the embodiments of this application will be described in detail below. For illustrative purposes, please refer to the following. Figure 1 The diagram illustrates an image processing method provided in an exemplary embodiment of this application, which includes steps 110 to 130.
[0056] Step 110: Obtain candidate images corresponding to multiple candidate samples.
[0057] Among them, multiple candidate samples are samples of the same type, and a candidate image refers to an image obtained after image acquisition of the first part of the candidate sample at a preset angle. The first parts corresponding to multiple candidate samples are the same, and the preset angles corresponding to multiple candidate samples are the same.
[0058] Indicatively, a candidate sample refers to the sample to be tested; or, a candidate sample is a sample that meets the conditions for a second sample after preliminary sample testing.
[0059] In practical applications, the second sample condition can be implemented as the good product condition. For example, if sample 1 meets the good product condition, it means that sample 1 is a good product, which is a product that meets the factory specifications. If sample 2 does not meet the good product condition, it means that sample 2 is a defective product, which is a product that does not meet the factory rules.
[0060] Optionally, the conditions for the second sample can be set from aspects such as product appearance, product performance, product component assembly, and product lifespan. This application embodiment does not limit this.
[0061] For example, regarding product appearance, the second sample condition can be whether the sample has defects, scratches, grooves, marks, etc.; regarding product performance, the second sample condition can be whether the sample can operate normally, the sample's running time, operating power, etc.; regarding the assembly of product components, the second sample condition can be whether the number of components meets the preset quantity threshold, whether the connection between components meets the preset connection conditions, and whether the type of components meets the preset type conditions; regarding product lifespan, the second sample condition can be whether the product lifespan meets the preset usage time threshold.
[0062] As an illustration, the methods for determining whether multiple candidate samples belong to the same type of sample include at least one of the following:
[0063] The first type is product process, that is, multiple candidate samples are made through the same product process. For example, sample 1 and sample 2 are both printed circuit boards produced by spraying process (e.g., spraying glue). Therefore, sample 1 and sample 2 belong to the same type of sample.
[0064] The second type is product type, that is, multiple candidate samples belong to the same product type. For example, both sample 3 and sample 4 belong to power conversion devices (e.g., charging plugs). Therefore, sample 3 and sample 4 belong to the same type of sample.
[0065] The third type is production specifications, which means that multiple candidate samples correspond to the same production specifications. For example, sample 5 is a data cable with a length of 0.8 meters (m), and sample 6 is also a data cable with a length of 0.6 meters. Therefore, sample 5 and sample 6 are products with different production specifications, that is, sample 5 and sample 6 are samples of different types.
[0066] The fourth type is product function, which means that multiple candidate samples achieve the same product function. For example, sample 7 is used to power a specified device and provides a maximum current of 5 amps, and sample 8 is also used to power a specified device and provides a maximum current of 5 amps. Therefore, sample 7 and sample 8 belong to the same type of sample.
[0067] It is worth noting that the above-described method for determining whether multiple candidate samples belong to the same type of sample is merely an illustrative example, and the embodiments of this application do not limit this.
[0068] In illustrative terms, the preset angle refers to the acquisition angle when acquiring images of candidate samples. For example, when using an image acquisition device (e.g., a camera) to acquire images of candidate samples, the shooting angle corresponding to the image acquisition device can be determined based on the relative positional relationship between the image acquisition device and the candidate sample.
[0069] In illustrative terms, the first part refers to a specific part in the candidate sample. Different candidate samples have the same first part. Therefore, the candidate images corresponding to different candidate samples are images that include the same part of different candidate samples.
[0070] It should be understood that since multiple candidate samples belong to the same type of sample, the locations of the candidate samples obtained from image acquisition are also the same locations, and the preset angles used during image acquisition are also the same, multiple candidate images have a certain degree of reference and comparability.
[0071] Optionally, the image acquisition devices used to acquire images of multiple candidate samples may be the same or different.
[0072] Optionally, the image acquisition method includes at least one of the following:
[0073] The first method involves acquiring images of a single candidate sample at a time using an image acquisition device, with the acquisition results including only the first part of the candidate sample.
[0074] The second method involves simultaneously acquiring multiple candidate samples using an image acquisition device (e.g., a camera). The resulting single acquisition result includes the first part corresponding to each of the multiple candidate samples. The acquisition result (e.g., the acquired image) is then cropped according to the position of each candidate sample in the acquisition result, resulting in cropped images corresponding to each of the multiple candidate samples, which serve as candidate images.
[0075] The third method involves capturing images of multiple candidate samples using an image acquisition device (e.g., a camera) to generate video content. In other words, a single video content includes video frames corresponding to multiple candidate samples. The multiple candidate samples in the video content are positioned at the same angle. By extracting the video frames containing the candidate samples from the video content, at least one video frame corresponding to each candidate sample is obtained. The candidate image corresponding to the candidate sample is then determined from the at least one video frame.
[0076] It is worth noting that the above-described image acquisition methods are merely illustrative examples, and the embodiments of this application do not limit them.
[0077] Optionally, for the same candidate sample, a single candidate sample may correspond to one or more candidate images, and this application embodiment does not limit this.
[0078] Optionally, the candidate image is an RGB image, where R represents red, G represents green, and B represents blue; or, the candidate image is a grayscale image, which is not limited in this embodiment.
[0079] Optionally, the candidate images of different candidate samples are of the same image type, for example, all are RGB images, or for example, all are grayscale images; or, the candidate images of different candidate samples are of different image types, for example, the candidate image a corresponding to candidate sample 1 is an RGB image, and the candidate image b corresponding to candidate sample 2 is a grayscale image. This application does not limit this.
[0080] Step 120: Obtain the candidate grayscale values corresponding to the multiple pixels in the regions where the multiple candidate samples are located in the multiple candidate images.
[0081] To illustrate, taking a candidate image corresponding to a single candidate sample as an example, multiple pixels refer to the pixels in the region where the candidate sample is located in the candidate image. For example, candidate image a is the candidate image corresponding to candidate sample 1. Candidate image a includes pixel a and pixel b, where pixel a is the pixel corresponding to the region where candidate sample 1 is located in candidate image a, and pixel b is the pixel corresponding to the background region in candidate image a.
[0082] To illustrate, grayscale values are used to represent the brightness of a pixel; that is, the higher the grayscale value, the brighter the pixel.
[0083] Optionally, the candidate grayscale values can be obtained in at least one of the following ways:
[0084] The first method involves a grayscale image as the candidate image. Pixels in a grayscale image contain only one channel. Therefore, the channel value output through that channel is used as the grayscale value of the pixel.
[0085] The second method involves using an RGB image as the candidate image. Pixels in an RGB image contain three channels: the Red channel outputs red values, the Blue channel outputs blue values, and the Green channel outputs green values. Therefore, by weighting and fusing the red, blue, and green values (e.g., 0.2 × red value + 0.3 × blue value + 0.5 × green value), the calculated result is the grayscale value of the pixel in the RGB image.
[0086] It is worth noting that the above-described methods for obtaining candidate grayscale values are merely illustrative examples, and the embodiments of this application do not limit them.
[0087] Optionally, if a single candidate sample corresponds to a single candidate image, the candidate grayscale value is calculated using either the first or second method described above, depending on the type of the candidate image (RGB image or grayscale image); or, if a single candidate sample corresponds to multiple candidate images, the grayscale value of each pixel in each candidate image is calculated, and the grayscale values corresponding to pixels with the same pixel coordinates are averaged (or weighted averaged) to obtain the candidate grayscale value corresponding to that pixel.
[0088] Optionally, a single pixel may correspond to multiple candidate grayscale values (e.g., a single candidate sample may correspond to multiple candidate images); or, a single pixel may correspond to a single grayscale value. This embodiment of the application does not limit this.
[0089] Step 130: Sort the multiple candidate grayscale values to obtain the sorting results corresponding to the multiple candidate grayscale values.
[0090] In illustrative terms, the sorting result refers to the result obtained after arranging the candidate pixel values corresponding to multiple pixels (including the pixels of multiple candidate samples in the region of their respective candidate images) according to a pre-set sorting rule.
[0091] Optionally, the sorting rules include the following:
[0092] The first method is to sort the candidate pixel values from smallest to largest. In other words, the candidate pixel values are arranged in ascending order to obtain the sorting result.
[0093] The second method is to sort the candidate pixel values from largest to smallest. In other words, the candidate pixel values are arranged in descending order to obtain the sorting result.
[0094] The third method involves pre-setting multiple pixel value thresholds and using these thresholds as classification boundaries. Multiple candidate pixel values are then classified into their closest pixel value thresholds, generating multiple subcategories. Within each subcategory, the values are sorted according to the above-mentioned ascending / descending order. The final sorting results for each subcategory are then used as the sorting results for the multiple candidate grayscale values.
[0095] It is worth noting that the above-mentioned sorting rules are merely illustrative examples, and the embodiments of this application do not limit them.
[0096] Optionally, for a pixel at the same pixel coordinate in multiple candidate images, there are multiple candidate pixel values. Therefore, the sorting result can be achieved by sorting the candidate pixel values corresponding to the same pixel coordinate based on each pixel coordinate, and obtaining the sorting result corresponding to that pixel coordinate; or by sorting according to all candidate pixel values to obtain the sorting result.
[0097] Step 140: Based on the sorting results, determine multiple target gray values that meet the first gray value condition from multiple candidate gray values, and obtain the target image based on the multiple target gray values.
[0098] The target image includes the target sample, which meets the first sample condition.
[0099] Indicatively, the target gray value refers to a specified candidate gray value selected from multiple candidate gray values.
[0100] Indicatively, the pixel corresponding to the target gray value that satisfies the first gray value condition is ultimately used as the pixel in the target image.
[0101] Indicatively, the target image shows a target sample that meets the pre-set first sample conditions. In practical applications, the target sample can be realized as a flawless qualified sample.
[0102] Optionally, the target image is used to compare and detect the candidate images of other candidate samples to determine whether the other candidate samples meet the first sample condition; or, the target image is used as a benchmark to select the specified candidate image that best matches the candidate images corresponding to multiple candidate samples, and the candidate sample displayed in the specified candidate image is used as a benchmark sample for comparing and detecting the candidate images of other candidate samples to determine whether the other candidate samples meet the first sample condition.
[0103] Optionally, the method for selecting the target grayscale value includes at least one of the following methods:
[0104] The first method is to select candidate pixel values within a specified range of pixel values as the target pixel values based on the sorting results. For example, select candidate pixel values between 100 and 180 as the target pixel values.
[0105] The second method is to select candidate pixel values within a specified position range in the sorting position as the target pixel value based on the sorting result. For example, based on the sorting result, select candidate pixel values from the 10th to the 80th position as the target pixel value.
[0106] The third approach addresses the scenario where the sorting result is achieved by sorting candidate pixel values corresponding to the same pixel coordinate based on each pixel coordinate. In this approach, candidate pixel values within a specified range of pixel values or a specified range of positions in the sorting result corresponding to each pixel coordinate are selected based on each pixel coordinate. The target grayscale value corresponding to the pixel coordinate is then determined based on the candidate pixel value, ultimately determining the target grayscale value corresponding to each pixel coordinate.
[0107] It is worth noting that the above-described method for selecting target grayscale values is merely an illustrative example, and the embodiments of this application do not limit it.
[0108] The image processing method provided in this application acquires multiple candidate images by capturing images of the same location of multiple candidate samples of the same type at the same angle. The grayscale values of pixels in the regions where the candidate samples are located in the multiple candidate images are sorted to obtain a sorting result. Finally, based on the sorting result, multiple target grayscale values that meet a first grayscale condition are determined to generate a target image containing the target sample, wherein the target sample meets the first sample condition. In other words, for sample images corresponding to different samples, the grayscale values of pixels in the regions where the candidate samples are located in the sample images are sorted, and grayscale values that meet the conditions are selected to generate the target image, so that the sample in the target image meets the sample condition, improving the accuracy of the sample image and thus improving the accuracy of the sample detection results.
[0109] The image processing methods are explained in detail below. Please refer to the illustrative examples. Figure 2 This illustrates a flowchart of an image processing method provided by an exemplary embodiment of this application. Specifically, step 120 further includes steps 121 and 122, step 130 is followed by steps 1301 and 1302, and step 140 includes step 141, as shown below. Figure 2 As shown, the method includes the following steps.
[0110] Step 121: Perform image alignment operation on multiple candidate images to obtain aligned images corresponding to each candidate image.
[0111] In this context, the candidate sample is located in the first region of the aligned image, and multiple candidate samples are located in the same first region in multiple aligned images.
[0112] To illustrate, the alignment operation is used to place candidate samples in different candidate images in the same region. In other words, the alignment operation makes the pixel coordinates of each candidate sample the same in the region of its respective candidate image.
[0113] Optionally, the multiple aligned images may have the same image size, or the multiple aligned images may have different image sizes.
[0114] Optionally, the alignment operation includes at least one of the following operation rules:
[0115] The first method is position alignment, which means placing candidate samples from different candidate images in the same region.
[0116] The second method is size alignment, which means aligning the regions in different candidate images to the same size.
[0117] It is worth noting that the above-described alignment operation is merely an illustrative example, and the actual implementation does not limit it.
[0118] Step 122: Obtain the candidate grayscale values corresponding to multiple pixels in the first region of multiple aligned images.
[0119] Indicatively, after obtaining multiple aligned images through alignment operations, candidate grayscale values corresponding to multiple pixels in the first region of each aligned image are obtained according to the method in the above embodiment.
[0120] Step 1301: Obtain the second grayscale condition.
[0121] Indicatively, the second grayscale condition is used for the first round of screening of multiple candidate grayscale values.
[0122] In one example, a maximum pixel threshold and / or a minimum pixel threshold are preset as a second grayscale condition.
[0123] Step 1302: If the i-th candidate grayscale value does not meet the second grayscale condition, remove the i-th candidate grayscale value from the sorting result to obtain the adjusted sorting result.
[0124] Among the multiple candidate grayscale values, there is the i-th candidate grayscale value, where i is a positive integer.
[0125] To illustrate, if the i-th candidate gray value among multiple candidate gray values is greater than the maximum pixel threshold or less than the minimum pixel value, then the i-th candidate gray value is determined to be an abnormal gray value. Therefore, the i-th candidate gray value in the sorting result is removed to obtain the adjusted sorting result, thereby achieving further filtering of the sorting result.
[0126] If the i-th candidate gray value is determined to be greater than the maximum pixel threshold or less than the minimum pixel value, then other candidate gray values that are greater than the i-th candidate gray value or less than the i-th candidate gray value will also be removed to improve the screening efficiency.
[0127] Step 141: Determine multiple candidate gray values that are within the first range in the sorting results from multiple candidate gray values, and use them as multiple target gray values.
[0128] Indicatively, the first range is a pre-defined range used to select a subset of candidate grayscale values from the sorting results as multiple target grayscale values.
[0129] In some embodiments, a grayscale value segmentation rule is obtained, which is used to numerically classify multiple candidate grayscale values in the sorting result. The grayscale value segmentation rule includes multiple candidate ranges, among which a first range is included. Based on the sorting result and multiple candidate ranges, multiple candidate grayscale values are numerically classified to obtain classification results corresponding to each of the multiple candidate ranges. Multiple candidate grayscale values within the first range are obtained as multiple target grayscale values.
[0130] In this embodiment, a grayscale value division rule is preset. The grayscale value division rule is used to classify multiple candidate grayscale values in the sorting result. The grayscale value division rule includes multiple candidate ranges, and the multiple candidate ranges include a first range.
[0131] Therefore, the multiple candidate gray values in the sorting results are classified sequentially according to multiple candidate ranges to obtain the classification results corresponding to the multiple candidate gray values. Among them, the multiple candidate gray values in the classification results in the first range are taken as the target gray values.
[0132] In some embodiments, multiple candidate ranges are arranged in a preset range order, wherein the first range is located at the median position among the multiple candidate ranges.
[0133] In this embodiment, the candidate ranges are arranged according to their numerical values. The first range is located at the median of the arranged candidate ranges. For example, if there are five candidate ranges in total, the third candidate range is selected as the first range after arranging them from smallest to largest.
[0134] In some embodiments, a first position and a second position are determined based on the sorting result. The first position is the starting position for determining multiple target gray values from multiple candidate gray values, and the second position is the ending position for determining multiple target gray values from multiple candidate gray values. Using the first position as the starting position and the second position as the ending position, multiple candidate gray values in the sorting result between the first position and the second position are determined as multiple target gray values.
[0135] In this embodiment, the first position is the starting position of the selected target grayscale value, which is the first position of the target grayscale value in the arrangement result, and the second position is the ending position of the selected target grayscale value, which is the last position of the target grayscale value in the arrangement result.
[0136] In this embodiment, starting from the first position, multiple candidate grayscale values between the first position and the second position are selected as the target grayscale value.
[0137] In some embodiments, multiple target gray values that meet the first gray value condition are determined from multiple candidate gray values based on the adjusted sorting results.
[0138] To illustrate, after obtaining the adjusted sorting results, the above method is used to determine multiple target gray values that meet the first gray value condition from multiple candidate gray values.
[0139] The image processing method provided in this application acquires multiple candidate images by capturing images of the same location of multiple candidate samples of the same type at the same angle. The grayscale values of pixels in the regions where the candidate samples are located in the multiple candidate images are sorted to obtain a sorting result. Finally, based on the sorting result, multiple target grayscale values that meet a first grayscale condition are determined to generate a target image containing the target sample, wherein the target sample meets the first sample condition. In other words, for sample images corresponding to different samples, the grayscale values of pixels in the regions where the candidate samples are located in the sample images are sorted, and grayscale values that meet the conditions are selected to generate the target image, so that the sample in the target image meets the sample condition, improving the accuracy of the sample image and thus improving the accuracy of the sample detection results.
[0140] This is illustrative; please refer to it. Figure 3 It illustrates a schematic diagram of an image processing method provided in an exemplary embodiment of this application, such as... Figure 3As shown, candidate images 310 corresponding to multiple candidate samples are obtained, and alignment operations are performed on the multiple candidate images 310 to obtain aligned images 320 corresponding to the multiple candidate images 310. Candidate gray values corresponding to multiple pixels in the first region 330 where the candidate samples are located in the multiple aligned images 320 are obtained. The multiple candidate gray values are sorted to obtain a sorting result 340. Multiple target gray values that meet the first gray value condition are selected from the sorting result 340. A target image 350 is generated based on the target gray values. The target image 350 includes the target sample 351.
[0141] The image processing method provided in this application acquires multiple candidate images by capturing images of the same location of multiple candidate samples of the same type at the same angle. The grayscale values of pixels in the regions where the candidate samples are located in the multiple candidate images are sorted to obtain a sorting result. Finally, based on the sorting result, multiple target grayscale values that meet a first grayscale condition are determined to generate a target image containing the target sample, wherein the target sample meets the first sample condition. In other words, for sample images corresponding to different samples, the grayscale values of pixels in the regions where the candidate samples are located in the sample images are sorted, and grayscale values that meet the conditions are selected to generate the target image, so that the sample in the target image meets the sample condition, improving the accuracy of the sample image and thus improving the accuracy of the sample detection results.
[0142] This application utilizes a multi-image synthesis method to generate more stable and reliable reference images (target images) for use in automated visual inspection systems in industrial production. This improves the accuracy and stability of defect detection and overcomes the limitations of traditional single standard images, which are susceptible to misjudgments due to the influence of multiple variables. Specifically, the most representative samples are automatically selected from a large number of good product images. Then, a sorting and statistical method is used to generate three types of reference images: median, dark area, and bright area. This adapts to factors such as material batch differences, equipment wear, and changes in lighting conditions in the production environment, thereby providing a more accurate reference for defect detection. Simultaneously, the efficient use of computing resources is considered to reduce computational consumption.
[0143] This is illustrative; please refer to it. Figure 4 The diagram illustrates an image processing apparatus provided in an exemplary embodiment of this application, wherein the image processing apparatus may specifically include the following modules:
[0144] The acquisition module 410 is used to acquire candidate images corresponding to multiple candidate samples respectively. The multiple candidate samples are samples of the same type. The candidate image refers to the image obtained after image acquisition of the first part of the candidate sample at a preset angle. The first part corresponding to the multiple candidate samples is the same, and the preset angle corresponding to the multiple candidate samples is the same.
[0145] The acquisition module 420 is further configured to acquire candidate gray values corresponding to multiple pixels in the regions where the multiple candidate samples are located in the multiple candidate images.
[0146] The sorting module 420 is used to sort multiple candidate grayscale values to obtain sorting results corresponding to the multiple candidate grayscale values respectively;
[0147] The determining module 430 is used to determine multiple target gray values that meet the first gray value condition from the multiple candidate gray values based on the sorting result, and to obtain a target image based on the multiple target gray values. The target image includes a target sample, and the target sample meets the first sample condition.
[0148] Optionally, the determining module 430 is used to determine from the plurality of candidate gray values that are within a first range in the sorting result, as the plurality of target gray values.
[0149] Optionally, the determining module 430 is configured to obtain grayscale value segmentation rules, which are used to numerically classify the plurality of candidate grayscale values in the sorting result. The grayscale value segmentation rules include a plurality of candidate ranges, including the first range. Based on the sorting result and the plurality of candidate ranges, the plurality of candidate grayscale values are numerically classified to obtain classification results corresponding to the plurality of candidate ranges respectively. The plurality of candidate grayscale values in the first range are obtained as the plurality of target grayscale values.
[0150] Optionally, the plurality of candidate ranges are arranged in a preset range order, wherein the first range is located at the median position among the plurality of candidate ranges.
[0151] Optionally, the determining module 430 is configured to determine a first position and a second position based on the sorting result, wherein the first position is the starting position for determining the plurality of target gray values from the plurality of candidate gray values, and the second position is the ending position for determining the plurality of target gray values from the plurality of candidate gray values; taking the first position as the starting position and the second position as the ending position, the plurality of candidate gray values in the sorting result located between the first position and the second position are determined as the plurality of target gray values.
[0152] Optionally, the plurality of candidate grayscale values includes the i-th candidate grayscale value, where i is a positive integer;
[0153] Optionally, the determining module 430 is configured to obtain a second grayscale condition; if the i-th candidate grayscale value does not meet the second grayscale condition, remove the i-th candidate grayscale value from the sorting result to obtain an adjusted sorting result; and determine the plurality of target grayscale values that meet the first grayscale condition from the plurality of candidate grayscale values based on the adjusted sorting result.
[0154] Optionally, the acquisition module 410 is used to perform image alignment operation on multiple candidate images to obtain aligned images corresponding to the multiple candidate images respectively, wherein the candidate sample is located in a first region in the aligned image, and the first region in which the multiple candidate samples are located is the same in the multiple aligned images; and to acquire the candidate grayscale values corresponding to multiple pixels in the first region in the multiple aligned images respectively.
[0155] The image processing apparatus provided in this application acquires multiple candidate images of the same location of multiple candidate samples of the same type from the same angle. It then sorts the grayscale values of pixels in the regions where the candidate samples are located within these candidate images, obtaining a sorting result. Finally, based on the sorting result, it determines multiple target grayscale values that meet a first grayscale condition to generate a target image containing the target sample, wherein the target sample meets the first sample condition. In other words, for sample images corresponding to different samples, the grayscale values of pixels in the regions where the candidate samples are located within the sample images are sorted, and grayscale values that meet the conditions are selected to generate the target image. This ensures that the sample in the target image meets the sample condition, improving the accuracy of the sample image and thus improving the accuracy of the sample detection results.
[0156] See Figure 5 This illustration shows a schematic diagram of the structure of a computer device provided in an embodiment of this application. Figure 5 As shown, the computer device 1000 of this embodiment includes: at least one processor 1010 ( Figure 5 (Only one is shown in the image) A processor, a memory 1020, and a computer program 1021 stored in the memory 1020 and executable on at least one processor 1010. When the processor 1010 executes the computer program 1021, it implements the steps in the above-described image processing method embodiments.
[0157] Computer device 1000 can be a desktop computer, laptop, handheld computer, cloud server, or other computing device. This terminal device may include, but is not limited to, processor 1010 and memory 1020. Those skilled in the art will understand that... Figure 5This is merely an example of computer device 1000 and does not constitute a limitation on computer device 1000. It may include more or fewer components than shown in the figure, or combine certain components, or different components, such as input / output devices, network access devices, etc.
[0158] The processor 1010 may be a Central Processing Unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0159] In some embodiments, memory 1020 may be an internal storage unit of computer device 1000, such as a hard disk or memory of computer device 1000. In other embodiments, memory 1020 may be an external storage device of computer device 1000, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc., provided on computer device 1000. Furthermore, memory 1020 may include both internal and external storage units of computer device 1000. Memory 1020 is used to store operating systems, applications, boot loaders, data, and other programs, such as program code for computer programs. Memory 1020 may also be used to temporarily store data that has been output or will be output.
[0160] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0161] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0162] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0163] In the embodiments provided in this application, it should be understood that the disclosed apparatus / computer devices and methods can be implemented in other ways. For example, the apparatus / computer device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.
[0164] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0165] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0166] If an integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, swivel hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.
[0167] The implementation of all or part of the processes in the methods of the above embodiments can also be accomplished by a computer program product. When the computer program product is run on a computer device, the computer device can implement the steps in the various method embodiments described above.
[0168] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. An image processing method, characterized by, The method comprises: obtaining a plurality of candidate images corresponding to a plurality of candidate samples respectively, the plurality of candidate samples being samples of the same type, the candidate image being an image obtained by image acquisition of a first part of the candidate sample at a preset angle, the first part of the plurality of candidate samples corresponding to each other being the same, and the plurality of candidate samples corresponding to each other being the same. Obtain a plurality of pixel points corresponding to a plurality of candidate gray values in the region where the plurality of candidate samples are located in the plurality of candidate images respectively. Sort a plurality of candidate gray values to obtain a sorting result corresponding to the plurality of candidate gray values respectively. Based on the sorting result, a plurality of target gray values meeting a first gray condition are determined from the plurality of candidate gray values, and a target image is obtained based on the plurality of target gray values, the target image including a target sample, the target sample meeting a first sample condition.
2. The method of claim 1, wherein, The method comprises: determining a plurality of candidate gray values in the first range in the sorting result from the plurality of candidate gray values as the plurality of target gray values.
3. The method of claim 2, wherein, The method comprises: obtain a gray value division rule, the gray value division rule being used for numerical classification of the plurality of candidate gray values in the sorting result, the gray value division rule including a plurality of candidate ranges, the plurality of candidate ranges including the first range; based on the sorting result and the plurality of candidate ranges, the plurality of candidate gray values are classified numerically to obtain a classification result corresponding to the plurality of candidate ranges respectively; obtain the plurality of candidate gray values in the first range as the plurality of target gray values.
4. The method of claim 3, wherein: the plurality of candidate ranges are arranged in a preset range order, wherein the first range is at a median position in the plurality of candidate ranges.
5. The method according to any one of claims 1 to 4, characterized in that, The method comprises: based on the sorting result, a first position and a second position are determined, the first position being a starting position for determining the plurality of target gray values from the plurality of candidate gray values, and the second position being a termination position for determining the plurality of target gray values from the plurality of candidate gray values; with the first position as the starting position and the second position as the ending position, the plurality of candidate gray values in the sorting result between the first position and the second position are determined as the plurality of target gray values.
6. The method according to any one of claims 1 to 4, characterized in that, The plurality of candidate gray values include an i-th candidate gray value, i being a positive integer. The method further comprises: obtain a second gray condition; In a case where the i-th candidate gray value does not meet the second gray condition, the i-th candidate gray value is eliminated from the sorting result, to obtain an adjusted sorting result; The determining, based on the sorting result, the multiple target gray values meeting the first gray condition from the multiple candidate gray values comprises: The determining, based on the adjusted sorting result, the multiple target gray values meeting the first gray condition from the multiple candidate gray values.
7. The method according to any one of claims 1 to 4, characterized in that, The obtaining of the candidate gray values respectively corresponding to the multiple pixel points in the region where the multiple candidate samples are respectively located in the multiple candidate images comprises: performing image alignment on the multiple candidate images to obtain multiple aligned images respectively corresponding to the multiple candidate images, wherein the candidate sample is located in a first region in the aligned images, and the multiple candidate samples are respectively located in the same first region in the multiple aligned images; obtaining the candidate gray values respectively corresponding to the multiple pixel points in the first region in the multiple aligned images.
8. An image processing apparatus characterized by comprising: The apparatus comprises: an obtaining module, configured to obtain multiple candidate images respectively corresponding to multiple candidate samples, the multiple candidate samples being samples of the same type, the candidate image being an image obtained by image acquisition of a first part of the candidate sample at a preset angle, the first part of the multiple candidate samples being the same, and the preset angle of the multiple candidate samples being the same; the obtaining module is further configured to obtain candidate gray values respectively corresponding to multiple pixel points in a region where the multiple candidate samples are respectively located in the multiple candidate images; a sorting module, configured to sort multiple candidate gray values to obtain sorting results respectively corresponding to the multiple candidate gray values; a determining module, configured to determine multiple target gray values meeting a first gray condition from the multiple candidate gray values based on the sorting results, and obtain a target image based on the multiple target gray values, the target image comprising a target sample, the target sample meeting a first sample condition.
9. A computer device, comprising: The computer device comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the image processing method of any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to implement the image processing method of any one of claims 1 to 7.
11. A computer program product, characterised in that, The computer program is executed to cause the image processing method of any one of claims 1 to 7 to be executed.
Citation Information
Patent Citations
Image processing method and device, electronic equipment and storage medium
CN114140342A
Image generation method and server
CN116778540A