Camera stain detection method and related device
By performing brightness image processing on the target image captured by the camera, including edge detection and brightness screening, and combining images to obtain a stain detection map, the problem of low accuracy of stain detection in the prior art is solved, and more efficient stain detection is achieved.
Patent Information
- Application Number
- CN202111531731.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-14
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2041-12-14
AI Technical Summary
Existing camera stain detection methods are prone to detect halos or blind angles as stains, resulting in low detection accuracy.
By acquiring the target image taken by the camera on the target area, converting it into a brightness image, and performing edge detection and brightness filtering on the brightness image, combining the edge expansion map and the dark pixel map to obtain a stain detection map.
It improves the accuracy of stain detection, reduces missed detection, reduces the possibility that halos or blind angles are mistakenly detected as stains, and improves detection efficiency.
Smart Images

Figure CN114359575B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image detection technology, and in particular to a camera stain detection method and related devices. Background Art
[0002] In order to detect whether there are spots in the camera lens, the camera is mainly used to shoot at the uniform light-emitting panel to obtain a detection image, and then the stains are detected by edge detection. This method is prone to detect partial halos or dark corners as stains or cannot detect stains with unclear brightness changes, resulting in low stain detection accuracy. Summary of the invention
[0003] The main technical problem solved by the present application is to provide a camera spot detection method and related devices, which can improve the accuracy of spot detection.
[0004] To solve the above technical problems, a technical solution adopted in the present application is: to provide a camera spot detection method, comprising: obtaining a target image obtained by shooting a target area with a camera, and converting the target image into a brightness image; wherein the surface of the target area is flat and has the same color; performing edge detection on the brightness image to obtain an edge expansion map, and performing brightness screening on the brightness image to obtain a dark pixel map; merging the edge expansion map and the dark pixel map to obtain a spot detection map.
[0005] To solve the above technical problems, another technical solution adopted in the present application is: to provide an electronic device, comprising a memory and a processor coupled to each other, wherein the memory stores program instructions, and the processor is used to execute the program instructions to implement the camera stain detection method in the above technical solution.
[0006] In order to solve the above technical problem, another technical solution adopted by the present application is: providing a storage device storing program instructions that can be executed by a processor, wherein the program instructions are used to implement the camera stain detection method in the above technical solution.
[0007] The beneficial effect of the present application is: different from the prior art, the present application converts the target image into a brightness image, processes the brightness image to obtain an edge expansion map and a dark pixel map, and merges the edge expansion map and the dark pixel map to realize the detection of stains. This method can improve the accuracy of stain detection, reduce the missed detection of stains, and reduce the possibility of detecting halos or dark corners as stains, thereby improving the efficiency of stain detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0008] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. Among them:
[0009] Figure 1 It is a flow chart of an implementation method of a camera stain detection method of the present application;
[0010] Figure 2 yes Figure 1 A schematic diagram of a flow chart of an implementation method in step S102;
[0011] Figure 3 yes Figure 1 A schematic diagram of a flow chart of another implementation method in step S102;
[0012] Figure 4 It is a schematic diagram of the distribution method of the second sub-block in this application;
[0013] Figure 5 It is a structural schematic diagram of an embodiment of a camera stain detection device of the present application;
[0014] Figure 6 It is a structural schematic diagram of an embodiment of the electronic device of the present application;
[0015] Figure 7 It is a structural diagram of an implementation method of a storage device of the present application. DETAILED DESCRIPTION
[0016] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0017] See also Figure 1 , Figure 1 : is a flow chart of an embodiment of a camera stain detection method of the present application, the method comprising:
[0018] S101: Acquire a target image obtained by photographing a target area with a camera, and convert the target image into a brightness image.
[0019] Specifically, the specific implementation process of the above step S101 includes: placing the camera as close to the target area as possible so that the acquired target image does not have the edge information of the target area; wherein the surface of the target area is flat and has the same color, and no stains can appear in the target area to ensure that the stains detected subsequently are stains of the camera itself. Preferably, a white uniform light-emitting panel can be selected as the target area. Further, brightness extraction is performed on the target image to obtain a brightness image. The target image can be in YUV format or RGB format; if the target image is in YUV format, the Y channel of the YUV format is used as the brightness image; if the target image is in RGB format, the channel with the largest brightness value among the three RGB channels is selected as the brightness image.
[0020] S102: Perform edge detection on the brightness image to obtain an edge expansion map, and perform brightness screening on the brightness image to obtain a dark pixel map.
[0021] See also Figure 2 , Figure 2 This is a schematic flow chart of an implementation method of performing edge expansion on the brightness image to obtain an edge expansion map in the above step S102. The method includes:
[0022] S201: Divide a luminance image into a plurality of first sub-blocks.
[0023] Specifically, the specific implementation process of the above step S201 includes: evenly dividing the brightness image obtained in the above step S101 into multiple first sub-blocks, and the size of each first sub-block can be 1 / 5000 of the number of pixels in the brightness image. Dividing the brightness image into multiple first sub-blocks helps to execute step S202 and improve the accuracy of stain detection. Optionally, the size of the first sub-block can also be adjusted according to different detection requirements; if each first sub-block is smaller, the number of first sub-blocks contained in the brightness image is more, then the number of pixels contained in each first sub-block is less, and the accuracy of stain detection is higher.
[0024] S202: Perform edge detection on each first sub-block to obtain a corresponding edge detection map.
[0025] The specific implementation process of the above step S202 includes: obtaining the maximum brightness value of the current first sub-block, and setting the first brightness threshold based on the maximum brightness value. Specifically, according to the corresponding brightness value of each pixel in each first sub-block, the maximum brightness value in each first sub-block is obtained, and the above first brightness threshold is the difference between the corresponding maximum brightness value in each first sub-block and the parameter threshold. According to multiple experiments, the parameter threshold is set to 7 in this embodiment, that is, the first brightness threshold is the maximum brightness value in the current first sub-block minus 7. For example, if the maximum brightness value in one of the first sub-blocks in the brightness image is 200, the first brightness threshold corresponding to the first sub-block is 193.
[0026] Further, the brightness of the pixels in the current first sub-block whose brightness is lower than the first brightness threshold is reset to the first value, and the brightness of the pixels in the current first sub-block whose brightness is greater than or equal to the first brightness threshold is reset to the second value, so as to obtain an edge detection map; wherein the first value is different from the second value. In this embodiment, the first value is taken as 255, and the second value is taken as 0. Specifically, in this step, the brightness of the pixels in each first sub-block whose brightness is lower than the first brightness threshold corresponding to the first sub-block is reset to 255, and the brightness of the pixels in each first sub-block whose brightness is higher than or equal to the first brightness threshold corresponding to the first sub-block is reset to 0, so as to obtain the edge detection map corresponding to each first sub-block. According to the first brightness threshold, the maximum brightness value in each first sub-block is subtracted from the parameter threshold, and the parameter threshold is 7, that is, the brightness of the pixels in each first sub-block whose brightness value differs from the maximum brightness value in the first sub-block by more than 7 is reset to 255, and the brightness of the pixels whose brightness value differs from the maximum brightness value in the first sub-block by less than or equal to 7 is reset to 0. For example, if the maximum brightness value in a first sub-block is 200, the brightness of the pixels in the first sub-block whose brightness value is less than 193 is reset to 255, and the brightness of the pixels in the first sub-block whose brightness value is greater than or equal to 193 is reset to 0. In this step, the brightness of the pixels in each first sub-block whose brightness value is greatly different from that of other pixels is reset to 255, and the pixels whose brightness value after reset is 255 are considered as stain pixels, so as to help detect stain areas in the image.
[0027] S203: Perform expansion and corrosion processing on all edge detection images to obtain edge expansion images.
[0028] Specifically, the specific implementation process of step S203 includes: merging all edge detection images obtained in the above step S202, and first performing an expansion operation on the merged edge detection image to fill the stain pixels; then performing an erosion operation to remove interfering pixels; and finally connecting the stain pixels into stain blocks to generate an edge expansion image. Among them, the expansion and erosion operations are more common methods in image processing and are not described here. Optionally, the stain pixels can also be connected into stain blocks by a method of local image filling. This step processes the edge detection image obtained in the above step S202 to obtain a stain area to help execute step S103.
[0029] See also Figure 3 , Figure 3 This is a schematic diagram of an implementation process of performing brightness screening on the brightness image to obtain a dark pixel image in the above step S102. The method includes:
[0030] S301: Divide a luminance image into a plurality of second sub-blocks.
[0031] Specifically, the specific implementation process of the above step S301 includes: dividing the brightness image into five second sub-blocks; wherein the four second sub-blocks are located at the four corners of the brightness image, and the rest of the brightness image is the remaining second sub-block. In this embodiment, the image blocks with a size of 1 / 3 of the width and 1 / 2 of the height of the brightness image are used as the second sub-blocks located at the four corners of the brightness image, and the rest of the brightness image is the central second sub-block. For details, please refer to Figure 4 , Figure 4 This is a schematic diagram of the distribution of the second sub-block in the present application, where the brightness image 80 is divided into a second sub-block 21, a second sub-block 22, a second sub-block 23, a second sub-block 24 and a second sub-block 25; wherein the second sub-block 21, the second sub-block 22, the second sub-block 23 and the second sub-block 24 are located at the four corners of the brightness image 80, and the width of these four second sub-blocks is 1 / 3 of the width of the brightness image, and the height is 1 / 2 of the height of the brightness image, and the remaining middle part of the brightness image 80 is the central second sub-block 25. By dividing the brightness image into four corner blocks and a central block, it is helpful to detect dark corners and / or halos to avoid detecting dark corners and / or halos as stains. Optionally, the size of the second sub-block can also be adjusted according to the different degrees of halos and dark corners in the image captured by the camera.
[0032] S302: Obtain an intermediate image corresponding to each second sub-block.
[0033] The specific implementation process of the above step S302 includes: for each second sub-block, obtaining the average brightness value of the current second sub-block, and obtaining the center brightness value that exceeds the average brightness value and appears the most times from the second sub-block; resetting the brightness of the pixel points whose brightness is lower than the center brightness value in the current second sub-block to the first value, and resetting the brightness of the pixel points whose brightness is greater than or equal to the center brightness value in the current second sub-block to the second value, so as to obtain the intermediate image; wherein the first value is different from the second value. In this embodiment, the first value is taken as 255, and the second value is taken as 0. Specifically, the average brightness value of each second sub-block is first calculated, that is, the brightness values corresponding to all the pixels in each second sub-block are averaged to obtain five average brightness values corresponding to five second sub-blocks. Then, the brightness histogram of each second sub-block is counted to obtain the number of occurrences of each brightness value in each second sub-block, and the brightness value in each second sub-block that is higher than the average brightness value of the second sub-block and appears the most times is taken as the center brightness value of the second sub-block. Finally, the brightness of the pixels in each second sub-block whose brightness value is lower than the central brightness value of the second sub-block is reset to 255, and the brightness of the pixels in each second sub-block whose brightness value is higher than the central brightness value of the second sub-block is reset to 0, so as to obtain the intermediate image corresponding to each second sub-block. This step performs brightness screening on the brightness values of the pixels in each second sub-block, resets the brightness values of the pixels with lower brightness values to 255, and resets the brightness of the remaining pixels to 0, so as to facilitate the execution of step S303.
[0034] S303: performing stitching processing on all the intermediate images to obtain a dark pixel image.
[0035] Specifically, the specific implementation process of the above step S303 includes: splicing all the intermediate images obtained in the above step S302 to process the original brightness image to obtain the corresponding dark pixel image, and the dark pixel image resets the brightness values corresponding to the pixels that may be the stain area to 255 to highlight the area that may be the stain, which helps to avoid detecting the halo in the target image as a stain, and helps to improve the accuracy of stain detection.
[0036] S103: Merge the edge expansion image and the dark pixel image to obtain a stain detection image.
[0037] The specific implementation process of the above step S103 includes: merging the edge expansion map obtained in the above step S203 and the dark pixel map obtained in the above step S303 to obtain a stain detection map. Specifically, the edge expansion map and the dark pixel map are merged to obtain the stain detection map, and in response to the brightness at the same pixel position in the edge expansion map and the dark pixel map being different, the brightness at the corresponding pixel position in the stain detection map is marked as a second value; and in response to the brightness at the same pixel position in the edge expansion map and the dark pixel map being both the first value, the brightness at the corresponding pixel position in the stain detection map is marked as a first value; and in response to the brightness at the same pixel position in the edge expansion map and the dark pixel map being both the second value, the brightness at the corresponding pixel position in the stain detection map is marked as a second value. In this embodiment, the first value is 255 and the second value is 0, that is, if the brightness of the corresponding pixel position in the edge expansion map and the dark pixel map is 255, the brightness of the corresponding pixel position in the stain detection map is also marked as 255; if the brightness of the corresponding pixel position in the edge expansion map and the dark pixel map is 0 or the brightness of the corresponding pixel position is different, the brightness of the corresponding pixel position in the stain detection map is marked as 0. This step combines the edge expansion map and the dark pixel map to obtain the stain detection map, which improves the accuracy of stain detection.
[0038] Furthermore, multiple connected areas formed by connecting pixels of the first value in the stain detection image are obtained; in response to the area of the connected area being less than a threshold value, the brightness of the pixels at the position of the connected area is reset to a second value. Specifically, this step further processes the stain detection image obtained above, connects the pixels with a brightness value of 255 in the stain detection image to form multiple connected areas, and resets the brightness of the pixels in the connected areas whose areas are less than the threshold value to 0, and the connected areas formed by connecting the pixels with the remaining brightness value of 255 are the stain areas finally detected. This step reduces interference and improves the accuracy of stain detection by obtaining multiple stain connected areas and screening the connected areas to remove the connected areas with smaller areas. The above threshold can be obtained by estimation or by inference from multiple test results.
[0039] In the above embodiment, the camera spot detection method proposed in the present application converts the target image into a brightness image, processes the brightness image to obtain an edge expansion image and a dark pixel image, and merges the edge expansion image and the dark pixel image to obtain a spot detection image. This method can improve the accuracy of spot detection, avoid missed detection of spots, and reduce the possibility of detecting halos or dark corners as spots, thereby improving the efficiency of spot detection.
[0040] Please participate Figure 5 , Figure 5 This is a schematic diagram of the structure of an embodiment of a camera spot detection device of the present application, and the device includes: a first acquisition module 11, a second acquisition module 12 and a third acquisition module 13. The first acquisition module 11 is used to obtain a target image obtained by shooting a target area with a camera, and convert the target image into a brightness image; wherein the surface of the target area is flat and has the same color; the second acquisition module 12 is used to perform edge detection on multiple brightness images to obtain an edge expansion map, and to perform brightness screening on the brightness image to obtain a dark pixel map; the third acquisition module 13 is used to merge the edge expansion map and the dark pixel map to obtain a spot detection map.
[0041] See also Figure 6 , Figure 6 This is a structural diagram of an embodiment of an electronic device of the present application, and the electronic device includes: a memory 30 and a processor 20 coupled to each other, the memory 30 stores program instructions, and the processor 20 is used to execute the program instructions to implement any of the above-mentioned camera stain detection method steps. Specifically, the electronic device includes but is not limited to: a desktop computer, a laptop computer, a tablet computer, a server, etc., which are not limited here. In addition, the processor 20 can also be called a CPU (Center Processing Unit). The processor 20 may be an integrated circuit chip with signal processing capabilities. The processor 20 can also be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 20 can be implemented by an integrated circuit chip.
[0042] See also Figure 7 , Figure 7 This is a schematic diagram of the structure of an embodiment of a storage device of the present application. The storage device 50 stores program instructions 60 that can be executed by a processor. The program instructions 60 are used to implement the steps in any of the above-mentioned camera stain detection methods.
[0043] The above description is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly used in other related technical fields, are also included in the patent protection scope of the present application.
Claims
1. A camera spot detection method, characterized in that: include: Acquire a target image obtained by photographing the target area with a camera, and convert the target image into a brightness image; wherein the surface of the target area is flat and has the same color; Performing edge detection on the brightness image to obtain an edge expansion map, and performing brightness screening on the brightness image to obtain a dark pixel map; Merging the edge expansion map and the dark pixel map to obtain a stain detection map; The step of performing brightness screening on the brightness image to obtain a dark pixel map includes: dividing the brightness image into a plurality of second sub-blocks; for each of the second sub-blocks, obtaining an average brightness value of the current second sub-block, and obtaining a center brightness value that exceeds the average brightness value and occurs the most times from the second sub-block; resetting the brightness of pixels in the current second sub-block whose brightness is lower than the center brightness value to a first value, and resetting the brightness of pixels in the current second sub-block whose brightness is greater than or equal to the center brightness value to a second value, so as to obtain an intermediate map; wherein the first value is different from the second value; and performing splicing processing on all the intermediate maps to obtain the dark pixel map.
2. The camera spot detection method according to claim 1, characterized in that: The step of performing edge detection on the brightness image to obtain an edge expansion map comprises: Dividing the brightness image into a plurality of first sub-blocks; Performing edge detection on each of the first sub-blocks to obtain a corresponding edge detection map; A dilation and erosion process is performed on all the edge detection images to obtain the edge expansion images.
3. The camera spot detection method according to claim 2, characterized in that: The step of performing edge detection on each of the first sub-blocks to obtain a corresponding edge detection map comprises: Obtaining a maximum brightness value of the current first sub-block, and setting a first brightness threshold based on the maximum brightness value; The brightness of the pixel points whose brightness in the current first sub-block is lower than the first brightness threshold is reset to a first value, and the brightness of the pixel points whose brightness in the current first sub-block is greater than or equal to the first brightness threshold is reset to a second value, so as to obtain the edge detection image; wherein the first value is different from the second value.
4. The camera spot detection method according to claim 1, characterized in that: The step of merging the edge expansion map and the dark pixel map to obtain a stain detection map comprises: In response to the brightness of the same pixel position in the edge expansion map and the dark pixel map being different, marking the brightness of the pixel position in the stain detection map as a second value; and In response to the brightness at the same pixel position in the edge expansion map and the dark pixel map being both the first value, marking the brightness at the pixel position in the stain detection map as the first value; and In response to the brightness at the same pixel position in the edge expansion map and the dark pixel map being both the second value, the brightness at the pixel position in the stain detection map is marked as the second value.
5. The camera spot detection method according to any one of claims 3-4, characterized in that: The first value is 255, and the second value is 0.
6. The camera spot detection method according to claim 1, characterized in that: The step of dividing the brightness image into a plurality of second sub-blocks comprises: The brightness image is divided into five second sub-blocks; wherein four of the second sub-blocks are located at four corners of the brightness image, and the rest of the brightness image is the remaining second sub-blocks.
7. The camera spot detection method according to claim 4, characterized in that: After the step of merging the edge expansion map and the dark pixel map to obtain a stain detection map, the method further comprises: Obtain a plurality of connected regions formed by connecting the pixel points having the first value in the stain detection image; In response to the area of the connected region being smaller than a threshold, the brightness of the pixel point at the position of the connected region is reset to the second value.
8. An electronic device, characterized in that: It comprises a memory and a processor coupled to each other, wherein the memory stores program instructions, and the processor is used to execute the program instructions to implement the camera stain detection method according to any one of claims 1 to 7.
9. A storage device, characterized in that: Program instructions that can be executed by a processor are stored, and the program instructions are used to implement the camera stain detection method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Stain detection and classification method and device for sensor of digital camera
CN104867159A
Brightness adjustment method, device and electronic device
CN109035183A
Image stain detection method, device and system and storage medium
CN111369491A