Image processing method and device, electronic equipment and computer readable medium
By calculating the segmentation threshold in the grayscale histogram and segmenting the target pixels, the noise problem when the 3D camera scans the pin is solved, and fast and real-time image processing is achieved, avoiding the production of additional template images.
Patent Information
- Application Number
- CN202411263047.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-10
- Publication Date
- 2025-04-25
AI Technical Summary
When industrial 3D cameras scan pins, specular reflections lead to noise generation, and the prior art requires additional template images and time-consuming fitting planes to determine segmentation thresholds.
By generating a grayscale histogram of the grayscale image, a first segmentation threshold and/or a second segmentation threshold are calculated, and the target pixels in the grayscale image are divided by these thresholds to obtain an output image. This method does not require additional template images and can quickly meet real-time requirements.
It realizes rapid and real-time removal of noise in pin images, and does not require additional template images, meeting the real-time requirements of industrial detection.
Smart Images

Figure CN119887795A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image processing method, device, electronic device and computer-readable medium. Background Art
[0002] In industry, 3D cameras can be used to scan pins to detect whether they have defects. Since pins are made of metal, mirror reflections may occur when the camera scans them, generating some unexpected noise. Therefore, before defect detection, it is often necessary to filter and reduce noise in the area near the pins. In addition, in order to detect defects, it is also necessary to remove the bottom area below the pins and the top area above the pins in the image.
[0003] In the prior art, template matching is generally used to locate the position of the entire workpiece, and then the height and posture of the surface above the pin are determined by fitting a plane or similar solutions, and then the optimal segmentation threshold can be further determined. However, template matching requires the production of an additional template image, and since there are many points corresponding to the pin, fitting the plane above the pin takes a lot of time. Summary of the invention
[0004] The content of this application is used to introduce concepts in a brief form, which will be described in detail in the detailed implementation section below. The content of this application is not intended to identify the key features or essential features of the technical solution claimed for protection, nor is it intended to limit the scope of the technical solution claimed for protection.
[0005] Some embodiments of the present application propose methods, devices, electronic devices, and computer-readable media to solve the technical problems mentioned in the above background technology section.
[0006] As a first aspect of the present application, some embodiments of the present application provide an image processing method, including:
[0007] In response to the input grayscale image of the workpiece to be inspected, a grayscale histogram of the grayscale image is generated; the grayscale image includes pixels of the Pin needle and pixels of the upper plane and / or the lower plane;
[0008] Calculating a first segmentation threshold and / or a second segmentation threshold according to the grayscale histogram;
[0009] Segmenting the target pixel in the grayscale image according to the first segmentation threshold and / or the second segmentation threshold to obtain an output image;
[0010] The grayscale value of the first segmentation threshold is smaller than the grayscale value of the second segmentation threshold.
[0011] Optionally, calculating the first segmentation threshold and / or the second segmentation threshold according to the grayscale histogram includes:
[0012] The first segmentation threshold is calculated based on the maximum inter-class variance method or Kapur entropy.
[0013] Optionally, calculating the first segmentation threshold and / or the second segmentation threshold according to the grayscale histogram includes:
[0014] The second segmentation threshold is calculated based on Kapur entropy or maximum inter-class variance method.
[0015] Optionally, calculating the first segmentation threshold based on the maximum inter-class variance method or Kapur entropy includes:
[0016] Calculating the distance between the pin and the lower plane and the distance between the pin and the upper plane;
[0017] When the distance between the Pin needle and the lower plane is smaller than the distance between the Pin needle and the upper plane, calculating the first segmentation threshold based on the Kapur entropy;
[0018] When the distance between the Pin pin and the lower plane is greater than or equal to the distance between the Pin pin and the upper plane, the first segmentation threshold is calculated based on the maximum inter-class variance method.
[0019] Optionally, the calculating the second segmentation threshold based on Kapur entropy or maximum inter-class variance method includes:
[0020] Determining whether the histogram of the upper plane has a multi-peak feature;
[0021] When the histogram of the upper plane has multi-peak features, calculating the second segmentation threshold based on the Kapur entropy;
[0022] When the histogram of the upper plane has only a single-peak feature, the second segmentation threshold is calculated based on the Kapur entropy or the maximum inter-class variance method.
[0023] Optionally, calculating the first segmentation threshold and / or the second segmentation threshold according to the grayscale histogram includes:
[0024] Obtaining the minimum grayscale value and the maximum grayscale value of the grayscale histogram;
[0025] Calculating a first segmentation threshold according to the minimum grayscale value and the maximum grayscale value of the grayscale histogram;
[0026] According to the first segmentation threshold, remove pixels whose grayscale values are lower than the first segmentation threshold;
[0027] A second segmentation threshold is calculated according to the first segmentation threshold and the maximum grayscale value.
[0028] Optionally, the image processing method further includes:
[0029] The output image is filtered and denoised to remove noise points in the output image.
[0030] As a second aspect of the present application, some embodiments of the present application provide an image processing device, including:
[0031] A generating module, for generating a grayscale histogram of the grayscale image in response to an input grayscale image of the workpiece to be detected; the grayscale image includes pixels of the Pin needle and pixels of the upper plane and / or the lower plane;
[0032] A calculation module, used for calculating a first segmentation threshold and / or a second segmentation threshold according to the grayscale histogram;
[0033] The segmentation module is used to segment the target pixels in the grayscale image according to the first segmentation threshold and / or the second segmentation threshold to obtain an output image.
[0034] As the third aspect of the present application, some embodiments of the present application provide an electronic device, comprising: one or more processors; a storage device on which one or more programs are stored, and when the one or more programs are executed by one or more processors, the one or more processors implement the method described in any implementation manner of the above-mentioned first aspect.
[0035] As a fourth aspect of the present application, some embodiments of the present application provide a computer-readable medium on which a computer program is stored, wherein when the program is executed by a processor, the method described in any implementation of the above-mentioned first aspect is implemented.
[0036] The beneficial effects of the present application are: providing an image processing method, device, electronic device and computer-readable medium for directly calculating a segmentation threshold through a grayscale histogram to meet real-time requirements.
[0037] More specifically, some embodiments of the present application may produce the following specific beneficial effects:
[0038] By directly calculating the first segmentation threshold corresponding to the lower plane and the second segmentation threshold corresponding to the upper plane through the grayscale histogram, and using the first segmentation threshold and / or the second segmentation threshold to segment the target pixels in the grayscale image, only the pixels of the Pin are left in the output image. The image processing method of the present application can meet the real-time requirements and does not require the additional production of template images. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] The drawings constituting a part of this application are used to provide a further understanding of this application, so that other features, purposes and advantages of this application become more obvious. The drawings and descriptions of the exemplary embodiments of this application are used to explain this application and do not constitute an improper limitation on this application.
[0040] In addition, throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that the components and elements are not necessarily drawn to scale.
[0041] In the attached picture:
[0042] Figure 1 is a flowchart of the main steps of an image processing method according to an embodiment of the present application;
[0043] Figure 2 is a schematic diagram of a grayscale image input in an image processing method according to an embodiment of the present application;
[0044] Figure 3 yes Figure 2 Schematic diagram of the grayscale image after visualization;
[0045] Figure 4 is a schematic diagram of a grayscale histogram in an image processing method according to an embodiment of the present application;
[0046] Figure 5 is a structural block diagram of an image processing device according to an embodiment of the present application;
[0047] Figure 6 It is a principle block diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0048] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments set forth herein. On the contrary, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0049] It should also be noted that, for ease of description, only the parts related to the invention are shown in the drawings. In the absence of conflict, the embodiments and features in the embodiments of the present disclosure can be combined with each other.
[0050] It should be noted that the concepts such as "first" and "second" mentioned in the present disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0051] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0052] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0053] The present disclosure will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.
[0054] Reference Figure 1 As shown, the present application provides an image processing method, comprising the following main steps:
[0055] S110: generating a grayscale histogram of the grayscale image in response to the input grayscale image of the workpiece to be inspected; the grayscale image includes pixels of the Pin needle and pixels of the upper plane and / or the lower plane;
[0056] S120: Calculate a first segmentation threshold and / or a second segmentation threshold according to the grayscale histogram; the grayscale value of the first segmentation threshold is smaller than the grayscale value of the second segmentation threshold.
[0057] S130: Segmenting target pixels in the grayscale image according to the first segmentation threshold and / or the second segmentation threshold to obtain an output image;
[0058] Specifically, the lower plane may be a bottom plate portion of the workpiece to be inspected, and the upper plane may be a shell portion of the workpiece to be inspected.
[0059] For example, Figure 2 It is a grayscale image (16-bit grayscale image) collected by the camera. The brightness of the image reflects the true height of the object. Figure 3 After visualizing the grayscale image, red represents a higher position and blue represents a lower position. It can be seen that the height of the image is divided into three layers, among which red corresponds to the shell part, blue corresponds to the bottom plate part, and green corresponds to the Pin part.
[0060] Step 130 is to remove the pixels of the lower plane as background and the pixels of the upper plane as foreground. In this way, the pixels of the pin area are retained as target pixels. Figure 4 As shown, the green line represents the first segmentation threshold, the red line represents the second segmentation threshold, and the portion between the green line and the red line is the target pixel.
[0061] By adopting the above scheme, the first segmentation threshold corresponding to the lower plane and the second segmentation threshold corresponding to the upper plane are directly calculated through the grayscale histogram, and the target pixels in the grayscale image are segmented using the first segmentation threshold and / or the second segmentation threshold, so that only the pixels of the Pin needle are left in the output image. The image processing method of the present application can meet the real-time requirements and does not require the additional production of template images.
[0062] In some embodiments, step S120 includes the following specific steps:
[0063] S121: Calculate a first segmentation threshold based on the maximum inter-class variance method or Kapur entropy.
[0064] Specifically, the segmentation threshold calculated by the maximum between-class variance method (Otsu method) refers to the position in the histogram that can maximize the between-class variance (Between-Class Variance) of the background and foreground. When there is a clear bimodal feature in the histogram, it is appropriate to use the Otsu method to solve the segmentation threshold.
[0065] The cost function (i.e., inter-class variance) of the Otsu method is as follows:
[0066] f(t)=σ 2 0+σ 2 1
[0067] in and Represent the variance of background and foreground respectively:
[0068] σ 2 0=ω0(μ0-μ T ) 2
[0069] σ 2 1=ω1(μ1-μ T ) 2
[0070] μ T Represents the average brightness of the entire image, μ T The calculation formula is as follows
[0071]
[0072] L represents the maximum value that a pixel in the image may take (determined by the number of bits of the image, for an 8-bit image, it is 255, for a 16-bit image, it is 65535, and so on).
[0073] i represents a brightness value within the brightness range (for 8-bit images, the value of i is [0,255], for 16-bit images it is [0,65535], and so on).
[0074] p i Indicates the probability of this brightness appearing in the entire image.
[0075] μ0 and μ1 represent the average brightness of background and foreground pixels, ω0 and ω1 represent the ratio of background pixels and foreground pixels to the total number of pixels, and t is the brightness threshold for distinguishing background from foreground (brightness [0, t-1] is background, brightness [t, L] is foreground). The calculation methods are as follows:
[0076]
[0077] The goal of Otsu's method is to find the position t that maximizes the variance between classes. * :
[0078] t * =argmax(f(t))
[0079] The segmentation threshold considered by Kapur's Entropy is the position that maximizes the Kapur's Entropy of the background and foreground.
[0080] f(t)=H0+H1
[0081] Where H0 and H1 represent the information entropy of the foreground and background respectively.
[0082]
[0083] Similar to Otsu's method, Kapur's Entropy method looks for locations that satisfy the following conditions:
[0084] t * =argmax(f(t))
[0085] The Kapur entropy method makes the image foreground and background each have a more concentrated distribution.
[0086] As a specific solution, step S121 includes the following specific steps:
[0087] S121a: Calculate the distance between the pin and the lower plane and the distance between the pin and the upper plane;
[0088] S121b: when the distance between the Pin needle and the lower plane is smaller than the distance between the Pin needle and the upper plane, calculating a first segmentation threshold based on Kapur entropy;
[0089] S121c: When the distance between the Pin pin and the lower plane is greater than or equal to the distance between the Pin pin and the upper plane, a first segmentation threshold is calculated based on the maximum inter-class variance method.
[0090] Specifically, when the distance between the pin and the lower plane is less than the distance between the pin and the upper plane, that is, the pin is short, Kapur's Entropy is used to find the first segmentation threshold (threshold_low) to remove the pixels of the lower plane to prevent the pin area from being treated as the background. When the distance between the pin and the lower plane is greater than or equal to the distance between the pin and the upper plane, that is, the pin has a certain length, the maximum inter-class variance method can be used to calculate the first segmentation threshold (threshold_low).
[0091] By adopting such a solution, the calculation method of the first segmentation threshold is selected by the length of the Pin needle, so as to improve the accuracy of the solved first segmentation threshold and facilitate correct segmentation.
[0092] In some embodiments, step S120 includes the following specific steps:
[0093] S122: Calculate a second segmentation threshold based on Kapur entropy or maximum inter-class variance method.
[0094] As a specific solution, step S122 includes the following specific steps:
[0095] S122a: Determine whether the histogram of the upper plane has multi-peak characteristics;
[0096] S122b: when the histogram of the upper plane has multi-peak features, calculating a second segmentation threshold based on Kapur entropy;
[0097] S122c: When the histogram of the upper plane has only a single-peak feature, a second segmentation threshold is calculated based on Kapur entropy or maximum inter-class variance method.
[0098] Specifically, for the upper plane, in most cases, the effect of using Kapur's Entropy is better than the maximum inter-class variance method (Otsu), because the upper plane pixels are usually far more than the pin needle part, and the local histogram of the upper plane is likely to have multi-peak characteristics, and using Otsu is prone to incorrect segmentation. If the histogram distribution of the upper plane is particularly concentrated, for example, it has only a single-peak feature, the above-mentioned Kapur entropy or maximum inter-class variance method can be used to calculate the second segmentation threshold. The second segmentation threshold obtained by both methods has good accuracy.
[0099] In some embodiments, before step S120, the image processing method further includes the following steps:
[0100] Preprocess the input grayscale image.
[0101] Specifically, when the input grayscale image is a 16-bit image and the histogram of the upper plane has multiple peaks, it can be converted into an 8-bit grayscale image first, so that the histogram of the upper plane will be more concentrated, which is more conducive to correct segmentation.
[0102] In some embodiments, step S120 specifically includes the following specific steps:
[0103] St121: Get the minimum grayscale value and maximum grayscale value of the grayscale histogram;
[0104] St122: Calculate the first segmentation threshold according to the minimum grayscale value and the maximum grayscale value of the grayscale histogram;
[0105] St123: Remove pixels whose grayscale values are lower than the first segmentation threshold according to the first segmentation threshold;
[0106] St124: Calculate the second segmentation threshold based on the first segmentation threshold and the maximum grayscale value.
[0107] Specifically, firstly, the grayscale histogram of the collected grayscale image is obtained, where the lowest grayscale value is 0 and the highest grayscale value is L. For example, for an 8-bit grayscale image, L=255; for a 16-bit single-channel image, L=65535.
[0108] Then solve the first segmentation threshold (threshold_low). Taking the maximum inter-class variance method as an example, the process of solving the first segmentation threshold is: find a value k in the [0,L] interval so that the inter-class variance of the histogram distribution in the [0,k) and (k,L] ranges can be maximized. After solving the first segmentation threshold, remove the pixels below the first segmentation threshold.
[0109] Next, the second segmentation threshold (threshold_high) is solved. Taking Kapur entropy as an example, the process of solving the second segmentation threshold is: find a value p in the interval [k, L] so that the Kapur entropy of the histogram distribution in the range of [k, p) and (p, L] can be maximized. After solving the second segmentation threshold, remove the pixels higher than the second segmentation threshold.
[0110] It should be noted that the calculation of the first segmentation threshold needs to be performed on the complete histogram, while the calculation of the second segmentation threshold needs to be performed on the remaining local histogram. For example, for a histogram on [0,65535], if the first segmentation threshold is 10023, then when solving the second segmentation threshold, it only needs to be calculated on [10024,65535]. In this way, when solving the second segmentation threshold, it will not be disturbed by pixels with brightness lower than the first segmentation threshold.
[0111] As a preferred solution, the first segmentation threshold is calculated based on the maximum inter-class variance method, and the second segmentation threshold is calculated based on Kapur entropy.
[0112] By adopting this scheme, the maximum inter-class variance method is used to calculate the first segmentation threshold, which can effectively remove the pixels of the base part below the pin in the grayscale image. The Kapur entropy is used to calculate the second segmentation threshold, which can cleanly remove the pixels of the shell part above the pin in the grayscale image. Because the shell part has many pixels and is relatively dense, the maximum inter-class variance method is often used for segmentation, while Kapur entropy has almost no such problem.
[0113] In some embodiments, the image processing method further comprises the following steps:
[0114] The output image is filtered and denoised to remove noise in the output image.
[0115] Specifically, statistical filtering can be used to remove discrete noise points in the output image.
[0116] The present application also provides an image processing device, comprising:
[0117] A generating module, for generating a grayscale histogram of the grayscale image in response to an input grayscale image of the workpiece to be detected; the grayscale image includes pixels of the Pin needle and pixels of the upper plane and / or the lower plane;
[0118] A calculation module, used for calculating a first segmentation threshold and / or a second segmentation threshold according to a grayscale histogram;
[0119] The segmentation module is used to segment the target pixels in the grayscale image according to the first segmentation threshold and / or the second segmentation threshold to obtain an output image.
[0120] like Figure 6 As shown, the electronic device 800 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage device 808 into a random access memory (RAM) 803. In the RAM 803, various programs and data required for the operation of the electronic device 800 are also stored. The processing device 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0121] Typically, the following devices may be connected to the I / O interface 805: input devices 806 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 807 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 808 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 809. The communication device 809 may allow the electronic device 800 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 The electronic device 800 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead. Figure 6 Each block shown in the figure may represent one device, or may represent multiple devices as required.
[0122] In particular, according to some embodiments of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, some embodiments of the present disclosure 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 some such embodiments, the computer program can be downloaded and installed from the network through the communication device 809, or installed from the storage device 808, or installed from the ROM 802. When the computer program is executed by the processing device 801, the above-mentioned functions defined in the method of some embodiments of the present disclosure are executed.
[0123] It should be noted that the computer-readable medium described above in some embodiments of the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the 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.
[0124] In some embodiments of the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device, or device. In some embodiments of the present disclosure, 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. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in combination with an instruction execution system, device, or device. The program code contained on the computer-readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0125] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperTextTransferProtocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an adhoc peer-to-peer network), as well as any currently known or future developed network.
[0126] The computer-readable medium may be included in the electronic device, or may exist independently without being assembled into the electronic device. The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device generates a grayscale histogram of the grayscale image in response to the grayscale image of the workpiece to be detected; the grayscale image includes the pixels of the pin and the pixels of the upper plane and / or the lower plane; according to the grayscale histogram, the first segmentation threshold and / or the second segmentation threshold are calculated; according to the first segmentation threshold and / or the second segmentation threshold, the target pixel in the grayscale image is segmented to obtain an output image; wherein the grayscale value of the first segmentation threshold is less than the grayscale value of the second segmentation threshold.
[0127] Computer program code for performing the operations of some embodiments of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0128] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram may represent a module, a program segment, or a part of a code, which contains one or more executable instructions for implementing a specified logical function.
[0129] It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures.
[0130] For example, two boxes shown in succession may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of boxes in the block diagram and / or flow chart, can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.
[0131] The units described in some embodiments of the present disclosure may be implemented by software or hardware. The units described may also be arranged in a processor, for example, may be described as: a processor includes a generation module, a calculation module and a segmentation module. The names of these units do not constitute a limitation on the units themselves in some cases, for example, the calculation module may also be described as "a unit for calculating the first segmentation threshold and / or the second segmentation threshold according to the grayscale histogram".
[0132] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0133] The above descriptions are only some preferred embodiments of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the embodiments of the present disclosure is not limited to the technical solutions formed by a specific combination of the above-mentioned technical features, but should also cover other technical solutions formed by any combination of the above-mentioned technical features or their equivalent features without departing from the above-mentioned inventive concept. For example, the above-mentioned features are replaced with the technical features with similar functions disclosed in the embodiments of the present disclosure (but not limited to) and the technical solutions formed.
Claims
1. An image processing method, characterized in that: include: In response to the input grayscale image of the workpiece to be inspected, a grayscale histogram of the grayscale image is generated; the grayscale image includes pixels of the Pin needle and pixels of the upper plane and / or the lower plane; Calculating a first segmentation threshold and / or a second segmentation threshold according to the grayscale histogram; Segmenting the target pixel in the grayscale image according to the first segmentation threshold and / or the second segmentation threshold to obtain an output image; The grayscale value of the first segmentation threshold is smaller than the grayscale value of the second segmentation threshold.
2. The image processing method according to claim 1, characterized in that: Calculating the first segmentation threshold and / or the second segmentation threshold according to the grayscale histogram includes: The first segmentation threshold is calculated based on the maximum inter-class variance method or Kapur entropy.
3. The image processing method according to claim 1, characterized in that: Calculating the first segmentation threshold and / or the second segmentation threshold according to the grayscale histogram includes: The second segmentation threshold is calculated based on Kapur entropy or maximum inter-class variance method.
4. The image processing method according to claim 2, characterized in that: The calculating the first segmentation threshold based on the maximum inter-class variance method or Kapur entropy includes: Calculating the distance between the pin and the lower plane and the distance between the pin and the upper plane; When the distance between the Pin needle and the lower plane is smaller than the distance between the Pin needle and the upper plane, calculating the first segmentation threshold based on the Kapur entropy; When the distance between the Pin pin and the lower plane is greater than or equal to the distance between the Pin pin and the upper plane, the first segmentation threshold is calculated based on the maximum inter-class variance method.
5. The image processing method according to claim 3, characterized in that: The calculating the second segmentation threshold based on Kapur entropy or maximum inter-class variance method includes: Determining whether the histogram of the upper plane has a multi-peak feature; When the histogram of the upper plane has multi-peak features, calculating the second segmentation threshold based on the Kapur entropy; When the histogram of the upper plane has only a single-peak feature, the second segmentation threshold is calculated based on the Kapur entropy or the maximum inter-class variance method.
6. The image processing method according to claim 1, characterized in that: Calculating the first segmentation threshold and / or the second segmentation threshold according to the grayscale histogram includes: Obtaining the minimum grayscale value and the maximum grayscale value of the grayscale histogram; Calculating a first segmentation threshold according to the minimum grayscale value and the maximum grayscale value of the grayscale histogram; According to the first segmentation threshold, remove pixels whose grayscale values are lower than the first segmentation threshold; A second segmentation threshold is calculated according to the first segmentation threshold and the maximum grayscale value.
7. The image processing method according to claim 1, characterized in that: The image processing method further comprises: The output image is filtered and denoised to remove noise points in the output image.
8. An image processing device, comprising: A generating module, for generating a grayscale histogram of the grayscale image in response to an input grayscale image of the workpiece to be detected; the grayscale image includes pixels of the Pin needle and pixels of the upper plane and / or the lower plane; A calculation module, used for calculating a first segmentation threshold and / or a second segmentation threshold according to the grayscale histogram; The segmentation module is used to segment the target pixels in the grayscale image according to the first segmentation threshold and / or the second segmentation threshold to obtain an output image.
9. An electronic device, comprising: one or more processors; a storage device having one or more programs stored thereon; When the one or more programs are executed by the one or more processors, the processors implement the method according to any one of claims 1 to 7.
10. A computer readable medium having a computer program stored thereon, wherein: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.