An endoscope-based automatic exposure calculation method
By employing an automatic endoscopic exposure calculation method, sensor defects are accurately marked, adaptive circular masks are dynamically generated, and four-zone division and adaptive determination of illumination intervals are implemented. This solves the problems of slow response speed and inaccurate calculation in traditional endoscopic exposure algorithms under complex environments, thereby improving image quality and diagnostic reliability.
Patent Information
- Application Number
- CN202611316772.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-28
- Publication Date
- 2026-11-27
AI Technical Summary
Traditional endoscopic automatic exposure algorithms are slow to respond in complex and dynamic imaging scenarios and are difficult to adapt to. Furthermore, the circular lens causes completely black areas in the image to interfere with the exposure calculation, resulting in inaccurate exposure calculations.
An endoscope-based automatic exposure calculation method is adopted. Sensor defects are accurately marked through a multi-condition hierarchical defect identification mechanism, an adaptive circular mask is dynamically generated, the imaging area is divided into four zones, and a closed-loop automatic exposure control is formed by combining zone priority sorting and illumination interval adaptive determination.
It improves image quality and diagnostic reliability, avoids interference from bad pixels and invalid background on photometry, and enhances imaging stability and diagnostic accuracy.
Smart Images

Figure CN123185437A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of endoscopic imaging exposure control technology, and in particular to an automatic exposure calculation method based on an endoscope. Background Technology
[0002] Endoscopes are core visual instruments for clinical medical diagnosis and minimally invasive interventional surgery. During procedures, they must continuously output clear, stable, and detailed images in the complex environment of uneven lighting, mucosal reflections, localized shadows, and dynamic changes in the field of vision. This provides reliable visual support for doctors to observe lesions, diagnose conditions, and perform surgical procedures. Exposure control, as a core technology of endoscopic imaging systems, directly determines the uniformity of image brightness, the integrity of details, and image stability, playing a decisive role in the accuracy of clinical diagnosis.
[0003] Current traditional endoscopic automatic exposure (AE) algorithms mostly employ global fixed threshold adjustment and global pixel mean statistics, which have many inherent technical shortcomings and are difficult to adapt to complex dynamic imaging scenarios during surgery. Furthermore, existing methods have slow response speeds in dynamic environments, making it difficult to meet the requirements of real-time image adjustment. In addition, since endoscope lenses are typically circular, the area outside the circular region is completely black, which may interfere with traditional automatic exposure calculation methods, leading to inaccurate exposure calculations. Therefore, there is an urgent need for an efficient automatic exposure calculation method for endoscopic applications to improve image quality and diagnostic reliability. Summary of the Invention
[0004] To overcome the shortcomings of the prior art, the present invention provides an automatic exposure calculation method based on endoscope.
[0005] This invention provides an automatic exposure calculation method based on an endoscope, the method comprising:
[0006] Step S1: Acquire raw image data, and initially extract pixel values of the blue channel, odd-numbered green channel, even-numbered green channel, and red channel from the raw image data to obtain initial extracted pixel values to be tested. Based on the initial extracted pixel values to be tested, compare the pixel values of the four channels B, Gb, Gr, and R at the same coordinates pixel by pixel. If the difference between the pixel value of a single channel and the pixel values of the other three channels all exceed the defective pixel judgment threshold, or if the difference between the pixel value of a single channel of each of the three channels and the pixel values of the other three channels all exceed the defective pixel judgment threshold, or if the difference between the pixel value of each of the two channels and the pixel value of one of the other two channels exceeds the defective pixel judgment threshold, mark the corresponding coordinate sensor defective pixels to be tested and remove defective pixels. Based on the defective pixels to be tested and the initially extracted pixel values to be tested, obtain a preprocessed brightness map based on the standard RGB to Y brightness weighted grayscale formula.
[0007] Step S2: Based on the preprocessed brightness map, create an initial binary map, preset the zoom magnification-mask radius mapping function, assign values to the circular region of the initial binary map according to the zoom magnification-mask radius mapping function to obtain an adaptive circular mask binary map, divide the overall image region of the adaptive circular mask binary map into four independent scanning regions, obtain four test partitions, and sort the four test partitions by priority according to the marked valid pixels in the four test partitions to obtain a partition priority sequence;
[0008] Step S3: According to the partition priority sequence, the adaptive circular mask binary image is partitioned and grown to obtain the target binary image. Based on the brightness value of the corresponding pixel in the preprocessed brightness image and the preset target brightness value, the level adjustment amount is obtained based on the linear deviation quantization level conversion. Based on the level adjustment amount, the preset exposure parameter table is matched, retrieved, and the sensor drive configuration is processed to obtain the current frame exposure adjustment result.
[0009] Preferably, raw image data in BGGR format is acquired, the pixel coordinates of each pixel in the raw image data are counted to obtain the coordinates of the pixel to be tested, and the blue channel pixel value, odd-numbered row green channel pixel value, even-numbered row green channel pixel value and red channel pixel value corresponding to the pixel coordinates to be tested are extracted from the raw image data to obtain the initial extracted pixel value to be tested;
[0010] Based on the initial extracted pixel values to be tested, the pixel values of the four channels B, Gb, Gr, and R at the same coordinate are compared pixel by pixel. The difference between the pixel value of a single channel and the pixel values of the other three channels is calculated to obtain the pixel difference to be judged.
[0011] A preset defective pixel detection threshold is set. If the difference between the pixel value of a single channel and the pixel values of the other three channels exceeds the defective pixel detection threshold, or if the difference between the pixel value of a single channel and the pixel values of the other three channels exceeds the defective pixel detection threshold, then the corresponding coordinate is determined to be a sensor defective pixel, and it is marked, and the defective pixel marking result 1 is output.
[0012] If the difference between the pixel values of two channels and the pixel values of one of the other two channels exceeds the defective pixel detection threshold, and they are adjacent in position, then the corresponding coordinates are determined to be sensor defects, and they are marked, and defective pixel marking result two is output.
[0013] Preferably, if the difference between the pixel values of two channels and one of the pixel values of the other two channels exceeds the defective pixel determination threshold, and they are not in an adjacent position relationship, then the two channel pixel values are marked as abnormal channel pixel values to be judged.
[0014] Obtain the four-channel mean parameters of the 8 neighboring pixels around the abnormal coordinates, output the neighboring parameters to be tested, and calculate the mean of the same channel in the neighboring area based on the neighboring parameters to be tested. Calculate the deviation difference between the two abnormal channel pixel values in the undetermined abnormal channel pixel values and the mean of the same channel in the neighboring area.
[0015] A preset neighborhood normal deviation threshold is set. If the deviation difference is greater than or equal to the neighborhood normal deviation threshold, the corresponding coordinates of the pixel value of the abnormal channel to be judged are determined to be sensor bad pixels, and they are marked. The bad pixel verification marking result three is output.
[0016] One of the following results, namely bad pixel marking result one, bad pixel marking result two, and bad pixel verification marking result three, is collectively referred to as the bad pixel to be removed from the test.
[0017] Based on the defective pixels to be removed, the initially extracted pixel values to be tested are filtered to obtain the effective pixel values to be tested;
[0018] Based on the standard RGB to Y brightness-weighted grayscale conversion formula, the brightness value of each effective pixel to be measured is solved pixel by pixel to obtain a preprocessed brightness map of the same size as the original image data.
[0019] Preferably, based on the preprocessed brightness map, an initial binary map is created with the same size as the preprocessed brightness map and all pixels are initially assigned a value of 0.
[0020] The zoom ratio analog signal output in real time from the endoscope zoom lens is acquired, and the zoom ratio analog signal is analyzed based on ADC analog-to-digital conversion to obtain real-time lens zoom ratio data.
[0021] A preset zoom ratio-mask radius mapping function is used to match the real-time lens zoom ratio data to obtain the target circular radius. The target circular radius is increased or decreased synchronously when the lens is in zoom-in or zoom-out mode.
[0022] Based on the original image data and the radius of the target circle, the initial binary image is assigned a circular region value to obtain an adaptive circular mask binary image.
[0023] Preferably, taking the center of the adaptive circular mask binary image as a reference, the overall image area of the adaptive circular mask binary image is divided into four independent scanning areas: upper left partition, upper right partition, lower left partition, and lower right partition, to obtain four test partitions. The marked effective pixels in the test partitions are counted to obtain the total number of effective pixels in each partition and the average brightness data of the partition.
[0024] Based on the total number of effective pixels and the average brightness data of each partition, the four partitions to be tested are prioritized to obtain a partition priority sequence.
[0025] Preferably, the current frame image information and the current imaging environment lighting conditions are obtained. Based on the current frame image information, if the current frame is the initial frame, the current imaging environment lighting conditions are determined to be a medium brightness conventional scene lighting range, and the lighting range determination category one is output.
[0026] If the current frame is not the initial frame, then the average brightness value of the previous frame corresponding to the current frame is calculated.
[0027] Based on the average brightness value of the previous frame image, the current imaging environment lighting conditions are divided into low-brightness dark scene lighting range, medium-brightness normal scene lighting range, and high-brightness strong light scene lighting range, and the lighting range determination category two is output.
[0028] One of the results of the illumination interval determination category one and the illumination interval determination category two is named the preprocessed illumination interval category;
[0029] A preset brightness connectivity difference threshold is used. Based on the preprocessed illumination interval category, the brightness connectivity difference threshold is matched and retrieved to obtain a dynamic brightness difference threshold that is adapted to the current imaging environment illumination conditions.
[0030] A fixed scanning direction is preset for each partition. Based on the fixed scanning direction of each partition, the partition priority sequence and the dynamic brightness difference threshold, pixel connectivity is determined for the adaptive circular mask binary image to obtain the connected pixel determination result.
[0031] Based on the connected pixel determination results, the adaptive circular mask binary image is partitioned and grown to obtain the target binary image.
[0032] Preferably, all valid pixels with a value of 1 in the target binary image are filtered to obtain preprocessed valid pixels, and the final total number of valid pixels is obtained based on the preprocessed valid pixels;
[0033] Extract the brightness values of the corresponding pixels in the preprocessed brightness map to obtain the brightness values of the preprocessed effective pixels. Sum the brightness values of the preprocessed effective pixels and divide them by the average of the total number of final effective pixels to obtain the average brightness value of the preprocessed image.
[0034] A target brightness value is preset, and the absolute value of the difference between the average brightness value of the preprocessed image and the target brightness value is calculated to obtain the absolute value to be measured.
[0035] A preset exposure adjustment dead zone threshold is set. If the absolute value to be measured is less than or equal to the exposure adjustment dead zone threshold, it is determined that the current exposure state of the image meets the standard and no exposure adjustment is required. The result of the exposure adjustment not required is output.
[0036] If the absolute value to be measured is greater than the exposure adjustment dead zone threshold, the gear adjustment amount is obtained by quantizing the gear conversion based on the gear boundary value and the absolute value to be measured, according to the linear deviation.
[0037] A preset exposure parameter table, initial exposure level, and matching exposure parameters are used as the base exposure level. Based on the initial exposure level and matching exposure parameters, the base exposure level is adjusted by increasing or decreasing according to the level adjustment amount to obtain the exposure update level.
[0038] Based on the exposure update level, the preset exposure parameter table is matched and retrieved, and the sensor drive configuration is processed to output the exposure adjustment result of the current frame.
[0039] Compared with the prior art, the present invention has the following characteristics and beneficial effects:
[0040] By designing a multi-condition hierarchical defect detection mechanism for the original images of the BGGR Bayer array, this mechanism distinguishes between three types of defect scenarios: severe single-channel jumps, coupling interference between adjacent channels, and discrete anomalies in non-adjacent channels. It also utilizes secondary verification with the mean of neighboring channels to differentiate between real device defects and transient noise interference. This allows for accurate marking of sensor defects and their removal before brightness calculation, preventing defective pixels from directly influencing brightness calculations and causing metering distortion, thus improving the reliability of basic data for automatic exposure. Based on the zoom ratio data obtained in real-time from the endoscope zoom lens, an adaptive circular mask is dynamically generated using a preset zoom ratio-mask radius mapping function. This mask can synchronously adjust the radius of the effective imaging area as the lens zooms in or out, automatically shielding invalid black background pixels outside the imaging circle and eliminating interference from invalid background pixels caused by zoom changes on metering statistics. Furthermore, by dividing the imaging area within the mask into four zones and prioritizing each zone based on the number of effective pixels and the average brightness of each zone, a differentiated approach is adopted. The traversal scheduling strategy prioritizes scanning high-value regions and reduces the traversal frequency of regions with low effective pixels. It achieves adaptive determination of illumination intervals by distinguishing between initial frames and loop frames. The initial frame uses default normal illumination as a fallback, while subsequent frames reuse the average brightness of the previous frame to divide illumination intervals into three categories: dark, normal, and strong light. Based on the illumination interval, a dynamic brightness connectivity difference threshold is retrieved to adapt to different mucosal brightness characteristics for pixel connectivity determination and region growing, improving the accuracy of effective tissue region segmentation and reducing problems such as tissue breakage in dark areas and missegmentation due to high-brightness reflections. After the target binary map is obtained through region growing convergence, the average image brightness is calculated only based on the effective tissue pixels retained from the segmentation. This brightness deviation is used as a basis for calculating the exposure level adjustment by combining linear deviation quantization. The initial exposure level is used as the dimming benchmark, and the preset exposure parameter table is linked to output sensor drive configuration, forming a closed-loop automatic exposure control that effectively avoids metering deviations caused by invalid backgrounds, bad pixels, and reflective noise. Attached Figure Description
[0041] Figure 1 This is a flowchart illustrating the steps of an automatic exposure calculation method based on an endoscope, which is the main feature of this embodiment. Detailed Implementation
[0042] The present invention will be further described in detail below with reference to the following embodiments.
[0043] Reference Figure 1 An automatic exposure calculation method based on endoscopy, the method comprising the following steps:
[0044] Step S1: Acquire raw image data. Initially extract pixel values from the blue channel, odd-numbered green channel, even-numbered green channel, and red channel of the raw image data to obtain initial extracted pixel values to be tested. Based on the initial extracted pixel values to be tested, compare the pixel values of the four channels B, Gb, Gr, and R at the same coordinates pixel by pixel. If the difference between the pixel value of a single channel and the pixel values of the other three channels all exceed the defective pixel judgment threshold, or if the difference between the pixel value of each of the three channels and the pixel value of the other three channels all exceed the defective pixel judgment threshold, or if the difference between the pixel value of each of the two channels and the pixel value of one of the other two channels exceeds the defective pixel judgment threshold, mark the corresponding coordinate sensor defective pixels to be tested and remove defective pixels. Based on the defective pixels to be tested and the initially extracted pixel values to be tested, obtain the preprocessed brightness map based on the standard RGB to Y brightness weighted grayscale formula.
[0045] Step S2: Based on the preprocessed brightness map, create an initial binary map, preset the zoom magnification-mask radius mapping function, assign values to the circular regions of the initial binary map according to the zoom magnification-mask radius mapping function to obtain an adaptive circular mask binary map, divide the overall image region of the adaptive circular mask binary map into four independent scanning regions, obtain four test partitions, and sort the four test partitions by priority according to the marked valid pixels in the four test partitions to obtain a partition priority sequence.
[0046] Step S3: Based on the partition priority sequence, perform partition region growth on the adaptive circular mask binary image to obtain the target binary image. Based on the brightness value of the corresponding pixel in the preprocessed brightness image and the preset target brightness value, perform level conversion based on linear deviation quantization to obtain the level adjustment amount. Based on the level adjustment amount, perform parameter matching retrieval and sensor drive configuration processing on the preset exposure parameter table to obtain the current frame exposure adjustment result.
[0047] Specifically, a multi-condition hierarchical defect identification mechanism is designed for the original images of the BGGR Bayer array. This mechanism distinguishes between three types of defect scenarios: severe single-channel jumps, coupling interference between adjacent channels, and discrete anomalies in non-adjacent channels. It also uses secondary verification with the mean of neighboring channels to differentiate between real device defects and transient noise interference. This allows for accurate marking of sensor defects and their removal before brightness calculation, preventing defective pixels from directly influencing brightness calculations and causing metering distortion, thus improving the reliability of basic data for automatic exposure. Based on the zoom ratio data obtained in real-time from the endoscope's zoom lens, an adaptive circular mask is dynamically generated using a preset zoom ratio-mask radius mapping function. This mask can synchronously adjust the radius of the effective imaging area as the lens zooms in or out, automatically shielding invalid black background pixels outside the imaging circle and eliminating interference from invalid background pixels caused by zoom changes on metering statistics. Furthermore, by dividing the imaging area within the mask into four zones and prioritizing each zone based on the number of effective pixels and the average brightness of each zone, a method is adopted. A differentiated traversal scheduling strategy prioritizes scanning high-value regions and reduces the traversal frequency of regions with low effective pixels. Illumination interval adaptive determination is achieved by distinguishing between initial frames and loop frames. The initial frame uses default normal illumination as a fallback, while subsequent frames reuse the average brightness of the previous frame to divide into three illumination intervals: dark, normal, or strong light. A dynamic brightness connectivity difference threshold is retrieved based on the illumination interval to adapt to different mucosal brightness characteristics for pixel connectivity determination and region growing, improving the accuracy of effective tissue region segmentation and reducing tissue breakage in dark areas and missegmentation due to high-light reflections. After the target binary image is obtained through region growing convergence, the average image brightness is calculated only based on the effective tissue pixels retained from the segmentation. This brightness deviation is used as a basis for calculating the exposure level adjustment using linear deviation quantization. The initial exposure level is used as the dimming benchmark, and the preset exposure parameter table is linked to output sensor drive configuration, forming a closed-loop automatic exposure control that effectively avoids metering deviations caused by invalid backgrounds, bad pixels, and reflective noise.
[0048] The specific step S1 includes the following sub-steps:
[0049] Acquire raw image data in BGGR format, count the pixel coordinates of the raw image data to obtain the coordinates of the pixel to be measured, and extract the blue channel pixel values, odd-numbered green channel pixel values, even-numbered green channel pixel values, and red channel pixel values corresponding to the pixel coordinates to be measured from the raw image data to obtain the initial extracted pixel values to be measured.
[0050] Based on the initial extracted pixel values, the pixel values of the four channels B, Gb, Gr, and R at the same coordinate are compared pixel by pixel. The difference between the pixel value of a single channel and the pixel values of the other three channels is calculated to obtain the pixel difference to be judged.
[0051] A preset defective pixel detection threshold is set. If the difference between the pixel value of a single channel and the pixel values of the other three channels all exceed the defective pixel detection threshold, or if the difference between the pixel value of a single channel and the pixel values of the other three channels in each of the three channels all exceed the defective pixel detection threshold, then the corresponding coordinate is determined to be a sensor defective pixel, and it is marked, and the defective pixel marking result 1 is output.
[0052] If the difference between the pixel values of two channels and the pixel values of one of the other two channels exceeds the defective pixel detection threshold, and they are adjacent in position, then the corresponding coordinates are determined to be sensor defects, and they are marked, and defective pixel marking result two is output.
[0053] If the difference between the pixel values of two channels and one of the pixel values of the other two channels exceeds the defective pixel determination threshold, and they are not in an adjacent position relationship, then the two channel pixel values are marked as abnormal channel pixel values to be judged.
[0054] Obtain the four-channel mean parameters of the eight neighboring pixels around the abnormal coordinates, output the parameters of the neighboring area to be tested, and calculate the mean value of the same channel in the neighboring area based on the parameters of the neighboring area to be tested. Calculate the deviation difference between the pixel values of the two abnormal channels in the pixel values of the undetermined abnormal channel and the mean value of the same channel in the neighboring area.
[0055] A preset neighborhood normal deviation threshold is set. If the deviation difference is greater than or equal to the neighborhood normal deviation threshold, the corresponding coordinates of the pixel value of the abnormal channel to be judged are determined to be sensor bad pixels, and they are marked. The bad pixel verification marking result three is output.
[0056] One of the following results—bad pixel marking result 1, bad pixel marking result 2, and bad pixel verification marking result 3—is collectively referred to as the bad pixel to be removed from the test.
[0057] Based on the defective pixels to be tested, the initially extracted pixel values are filtered to obtain the valid pixel values to be tested.
[0058] Based on the standard RGB to Y brightness-weighted grayscale conversion formula, the brightness value of each effective pixel to be measured is solved pixel by pixel to obtain a preprocessed brightness map of the same size as the original image data.
[0059] Specifically, the process involves acquiring raw image data in BGGR format (using a CMOS image sensor mounted on the endoscope (standard imaging hardware for existing medical endoscopes) to acquire RAW images of the in vivo scene in real time; the sensor hardware outputs raw data in BGGR Bayer array arrangement, i.e., raw image data in BGGR format), initially extracting the pixel values to be tested (e.g., using raw RAW image channel separation and analysis technology to traverse the raw image pixel by pixel, splitting the blue channel, odd-numbered rows of green channel Gb, even-numbered rows of green channel Gr, and red channel R values according to the BGGR array position), presetting the bad pixel judgment threshold (e.g., under normal light sensitivity of a medical CMOS sensor, the brightness difference range of the four channels of the same pixel, the channel jump amplitude threshold caused by circuit crosstalk, combined with offline calibration and storage of the normal imaging pixel fluctuation range of the in vivo mucosa), and outputting the bad pixel marking result (e.g., the B channel value of a certain pixel is much higher than the Gb, Gr, and R channels, and the difference between the single channel and the other three channels all exceed the bad pixel judgment). A threshold is set, and the pixel is determined to be a single-channel failure of the sensor. A bad pixel label result 1 is generated. This type of determination is used to accurately screen for completely failed pixels with severe single-channel jumps and three-channel synchronous deviations, avoiding brightness calculation distortion caused by extreme abnormal pixels. A bad pixel label result 2 is generated. (The pixels of the Gb and Gr channels of a certain adjacent Bayer array jump synchronously. The difference between the two channels and the other channels exceeds the threshold. The two channels are physically adjacent. It is determined to be a bad pixel with photosensitive unit coupling interference. A bad pixel label result 2 is generated. This type of determination is adapted to the channel arrangement characteristics of the BGGR Bayer array. It specifically identifies the linked abnormal pixels caused by circuit crosstalk and photosensitive unit coupling interference in adjacent channels of the array, and solves the problem of local imaging distortion caused by the failure of adjacent channels.)
[0060] For example, using the image 8-neighborhood window traversal statistical technique (existing neighborhood pixel calculation technique), eight surrounding pixels are extracted centered on the abnormal pixel coordinates. The four-channel values of each pixel are statistically analyzed and averaged to output the neighborhood parameters to be tested. A preset neighborhood normal deviation threshold is set (such as the fluctuation range of normal mucosal pixels in the same channel, the upper limit of pixel deviation caused by instantaneous environmental noise, and fixed storage is performed offline). For example, if the B and R channel values of a pixel are abnormal and the array positions of the two channels are not adjacent, after retrieving the average values of the same channels in the eight surrounding neighborhoods, the deviation difference between the B and R channels and the neighborhood average value both exceed the neighborhood normal deviation threshold, which is determined to be a real device damage. The output shows the third bad pixel verification result. This secondary verification can effectively distinguish between real device damage and instantaneous environmental noise interference in non-adjacent channels, avoiding the accidental removal of normal valid pixels, and accurately locating discrete local bad pixels. It iterates through all pixel coordinates in the entire image, removing all coordinates with any one of the bad pixel verification results (one, two, or three). The remaining unmarked pixels are the valid pixels to be tested. Based on the standard RGB-to-Y brightness weighted grayscale formula, combined with the BGGR Bayer array dual-channel green channel characteristics, it performs equivalent deformation and pixel-by-pixel calculation to obtain the preprocessed brightness map (internationally accepted standard RGB-to-Y brightness conversion (ITU-R)). The original standard formula for BT.601 is: (Y=0.2990R+0.5870G+0.1140B). The original image data in BGGR format splits the green channel into odd-numbered green channels Gb and even-numbered green channels Gr. The average value of the two green channels is taken as the equivalent standard single channel G, and then substituted into the standard brightness weight to complete the calculation. That is, the modified adaptation calculation formula is: Y=0.2990*R+0.5870*0.5*(Gr+Gb)+0.1140*B. The brightness value is calculated point by point through all the effective pixels to be measured, and a preprocessed brightness map with the same size as the original image is generated.
[0061] The specific step S2 includes the following sub-steps:
[0062] Based on the preprocessed luminance map, create an initial binary map with the same size as the preprocessed luminance map, and with all pixels initially set to 0.
[0063] The real-time zoom ratio analog signal output by the endoscope zoom lens is acquired, and the zoom ratio analog signal is analyzed and processed based on ADC analog-to-digital conversion to obtain the real-time lens zoom ratio data.
[0064] A preset zoom ratio-mask radius mapping function is used to match the real-time lens zoom ratio data to obtain the target circular radius. The target circular radius is increased or decreased synchronously when the lens is in zoom-in or zoom-out mode.
[0065] Based on the original image data and the radius of the target circle, the initial binary image is assigned a circular region value to obtain an adaptive circular mask binary image.
[0066] Using the center of the adaptive circular mask binary image as a reference, the overall image area of the adaptive circular mask binary image is divided into four independent scanning areas: upper left, upper right, lower left, and lower right, resulting in four test areas. The marked effective pixels in the test areas are counted to obtain the total number of effective pixels and the average brightness data of each area.
[0067] Based on the total number of effective pixels in each partition and the average brightness data of each partition, the four partitions to be tested are prioritized to obtain the partition priority sequence.
[0068] Specifically, this involves creating an initial binary image with all pixels set to 0 based on a preprocessed brightness map (e.g., a preprocessed brightness map with a resolution of 1280×720, creating a blank binary image of the same size with all pixels uniformly set to 0); real-time lens zoom ratio data (e.g., the endoscope zoom drive motor outputs a continuous analog voltage signal, which is sampled, quantized, and encoded using an ADC analog-to-digital converter (such as successive approximation SAR-ADC analog-to-digital conversion technology) to convert and output a digital format real-time zoom ratio, i.e., real-time lens zoom ratio data); and pre-setting a zoom ratio-mask radius mapping function, which is then substituted into the magnification matching to obtain the target circular radius (e.g., a rigid endoscope). Zoom optical characteristics—When the lens zooms in, the circular field of view expands and the black circle at the edge of the image shrinks; when the lens zooms out, the field of view contracts and the black circle at the edge increases. A mapping function is obtained by fitting multiple sets of measured data on zoom levels and the radius of the black circle and stored offline. When the lens zooms in, the mapping function is used to calculate a larger target circular radius; when the lens zooms out, a smaller target circular radius is calculated. For example, let the mapping function be: R = k * M + b, where M is the real-time zoom ratio, R is the target circular radius, and k and b are fitting calibration constants. When the lens zooms in, if the zoom ratio M = 4, substituting into the function yields R = 320, with the center of the image as the center and a radius of 320. Draw a circular mask; zoom out, if the zoom ratio M=1, substitute into the function to calculate R=160, and the radius of the mask circle will shrink accordingly); adaptive circular mask binary image (for example, draw a circular area with the center point of the original image as the center and the radius of the target circle, assign all binary image pixels inside the circle to 1, and keep the outside 0, automatically masking the completely black invalid background outside the lens imaging circle).
[0069] Using the center of the adaptive circular mask binary image as the dividing point, the circular imaging area is equally divided into four independent scanning regions: the upper left region, the upper right region, the lower left region, and the lower right region. The total number of effective pixels and the average brightness of each region are calculated: for example, using a region pixel traversal and statistical technique (existing image block processing technique), pixels with a mask value of 1 within each region are traversed individually, the total number of pixels is counted, and the average brightness of the region is calculated. A region priority sequence is also established (e.g., the higher the percentage of effective pixels, the closer the average brightness of the region is to the preset target brightness, and the more effective information about human tissue the region contains, the more priority it needs to be given to fine traversal; for example, the upper left region has many mucosal tissue pixels and its brightness matches the target brightness, so it is ranked as the first priority; the lower right region has a large area of black background and few effective pixels, so it is ranked as the lowest priority).
[0070] The specific step S3 includes the following sub-steps:
[0071] Obtain the current frame image information and the current imaging environment lighting conditions. Based on the current frame image information, if the current frame is the initial frame, determine the current imaging environment lighting conditions as a medium brightness normal scene lighting range and output the lighting range determination category one.
[0072] If the current frame is not the initial frame, then the average brightness value of the previous frame corresponding to the current frame is calculated.
[0073] Based on the average brightness value of the previous frame image, the current imaging environment lighting conditions are divided into low-brightness dark scene lighting range, medium-brightness normal scene lighting range, and high-brightness strong light scene lighting range, and the second category of lighting range determination is output.
[0074] One of the results from illumination interval determination category one and illumination interval determination category two is named the preprocessed illumination interval category.
[0075] A preset brightness connectivity difference threshold is used. Based on the preprocessed illumination interval category, the brightness connectivity difference threshold is matched and retrieved to obtain a dynamic brightness difference threshold that is adapted to the current imaging environment illumination conditions.
[0076] A fixed scanning direction is preset for each partition. Based on the fixed scanning direction of each partition, the partition priority sequence, and the dynamic brightness difference threshold, pixel connectivity is determined for the adaptive circular mask binary image to obtain the connected pixel determination result.
[0077] Based on the connected pixel determination results, the adaptive circular mask binary image is partitioned and grown to obtain the target binary image.
[0078] Filter all valid pixels with a value of 1 within the target binary image to obtain preprocessed valid pixels. Based on the preprocessed valid pixels, obtain the final total number of valid pixels.
[0079] Extract the brightness values of the corresponding pixels in the preprocessed brightness map to obtain the brightness values of the effective pixels in the preprocessed image. Sum the brightness values of the effective pixels in the preprocessed image and divide them by the average of the total number of effective pixels in the final image to obtain the average brightness value of the preprocessed image.
[0080] A target brightness value is preset, and the absolute value of the difference between the average brightness value of the preprocessed image and the target brightness value is calculated to obtain the absolute value to be measured.
[0081] A preset exposure adjustment dead zone threshold is set. If the absolute value to be measured is less than or equal to the exposure adjustment dead zone threshold, the current exposure status of the image is determined to be up to standard, and no exposure adjustment is required. The result of the exposure adjustment not required is output.
[0082] If the absolute value to be measured is greater than the exposure adjustment dead zone threshold, the gear level conversion is calculated based on the gear level boundary value and the absolute value to be measured, and the gear level adjustment amount is obtained.
[0083] The system includes a preset exposure parameter table, an initial exposure level, and corresponding exposure parameters. Using the initial exposure level and corresponding exposure parameters as the baseline exposure level, the system adjusts the baseline exposure level by increasing or decreasing it based on the adjustment amount to obtain the updated exposure level.
[0084] Based on the exposure update level, the preset exposure parameter table is matched and retrieved, and the sensor drive configuration is processed to output the exposure adjustment result of the current frame.
[0085] Specifically, there are two types of illumination interval determination categories: Category 1 (e.g., the mucous membrane of a normal human body cavity is at medium brightness, serving as the default scenario for power-on fallback; for example, when the endoscope is powered on and acquires the first frame image, there is no historical frame brightness data, so it is preset to be a normal scene with medium brightness, and the output is Category 1 of illumination interval determination); and Category 2 of illumination interval determination (when a non-initial frame image is acquired and the illumination condition determination stage is entered, the average brightness value of the previous frame preprocessed image stored in the cache unit is read through cache reading technology. This value is calculated after the previous round of filtering all effective human tissue pixels through bad pixel removal, adaptive mask filtering, and region growing; two fixed brightness thresholds are preset, and the three types of illumination intervals are divided based on the average brightness value of the previous frame image read. If the average brightness of the previous frame is below the low brightness threshold, the current imaging environment is determined to be a low-brightness dark scene; if the average brightness of the previous frame is between the low brightness threshold and the high brightness threshold, the current imaging environment is determined to be a medium-brightness normal scene; if the average brightness of the previous frame is above the high brightness threshold, the current imaging environment is determined to be a high-brightness bright scene. The preset fixed brightness thresholds at both ends are obtained through offline statistical calibration of clinical in vivo imaging samples from medical endoscopes. A large number of effective endoscopic tissue images were collected under different body cavity environments, and the pretreatment corresponding to mucosal dark areas, normal mucosa, and highly reflective areas of mucus or blood vessels was statistically analyzed. The average brightness distribution range of the image is analyzed, and the critical brightness values of the intervals are extracted as the original reference values for the two-segment boundary thresholds. Below the low brightness boundary threshold: dark cavities and deep mucous membranes in the body have large fluctuations in pixel brightness, so the brightness connectivity difference threshold needs to be increased to prevent dark tissues from being mis-segmented and removed by the region growing algorithm. In the middle range between the two thresholds: regular body cavity mucous membranes have gentle brightness fluctuations, and the standard difference threshold can accurately segment human tissues. Above the high brightness boundary threshold: mucus bubble reflections and bright reflections from blood vessels have drastic changes in pixel brightness, so the connectivity difference threshold needs to be reduced to avoid misidentifying reflective noise as valid tissue areas. A preset brightness connectivity difference threshold is used, and a dynamic brightness difference threshold is retrieved according to the illumination interval (e.g., for mucous membrane images in low-brightness dark scenes). Large fluctuations in pixel brightness necessitate amplifying the difference threshold to prevent tissue segmentation and breakage. Conversely, in high-brightness, strong-light scenes with minimal fluctuations in reflected pixels, the difference threshold needs to be reduced to prevent misjudgment of tissue by reflected light. Three sets of fixed thresholds—dark, normal, and strong-light—are stored offline. For example, if the current frame is determined to be a low-brightness, dark scene, the amplified dynamic brightness difference threshold is retrieved for connectivity determination. If the base threshold for a low-brightness, dark scene is 12, and the endoscope is inserted into the deep folds of the intestine, and the average brightness of the previous frame is below the low-brightness boundary threshold, it is determined to be a low-brightness, dark scene, and threshold 12 is retrieved as the dynamic brightness difference threshold. When performing partition region growth, the four partitions (top left, top right, bottom left, bottom right) are traversed, and the brightness of the four neighboring regions (top, bottom, left, and right) is compared, centered on the pixel with a value of 1 within the mask.Adjacent mucosa areas exhibit significant brightness differences due to insufficient illumination, with a brightness difference of 9. Since 9 < 12, the connectivity condition is met, and the pixels in the neighboring binary image are changed from 0 to 1, ensuring complete connectivity of the entire mucosa without tissue segmentation. However, if a conventional threshold of 5 is used, the difference of 9 would exceed the threshold, causing the algorithm to mistakenly split the continuous mucosa into multiple independent small blocks, resulting in fewer effective pixels and darker exposure. A fixed scanning direction is preset for each partition (e.g., offline preset: upper left partition from right to left, from bottom to top; upper right partition from left to right, from bottom to top; lower left partition from right to left, from top to bottom; lower right partition from left to right, from top to bottom). For example, each partition is traversed according to its priority, and the brightness difference between the current pixel and its four neighboring pixels (up, down, left, right, and right) is compared. If the difference is less than the dynamic brightness difference threshold, the 0 pixels in the neighboring binary image are updated to 1. This process is iterated until no pixel values change across the entire image, and the target binary image of the region growth convergence is output.
[0086] The preprocessed image average brightness value (using global pixel traversal statistical techniques, only extracting the effective pixels of the tissue marked by the mask after region growth; for example, summing all effective pixel brightness values and dividing by the final total number of effective pixels to obtain the average brightness of a single frame image, i.e., the preprocessed image average brightness value, where this preprocessed image average brightness value is used for frame buffering and for determining the illumination range of the next frame image); preset target brightness value, exposure adjustment dead zone threshold Ty, and level division value T (such as the brightness of a medical endoscope that is comfortable for human eyes to observe as the target brightness; the area of minute brightness fluctuations that are imperceptible to the human eye). The system includes: a dead zone threshold Ty; a step size for converting brightness deviation to exposure level adjustment; a level boundary value T, all preset offline based on clinical imaging needs; level adjustment amount (e.g., if the absolute value D is greater than Ty, the adjustment amount a = (D-Ty) / T; if the average image brightness is lower than the target brightness, the exposure level is increased; if it is higher than the target brightness, the exposure level is decreased); a preset exposure parameter table; initial exposure level; and matching exposure parameters (e.g., CMOS sensor light sensitivity limit, hardware exposure time and adjustable gain range; multiple sets of one-to-one matching exposure time and light sensitivity gain parameters are stored offline). The initial exposure level is the default base level when the device is powered on. Based on the initial exposure level loaded upon power-on, an adjustment amount 'a' is added to obtain the updated exposure level: If the average brightness < target brightness: the image is too dark, add the base exposure level + the adjustment amount 'a' to obtain the updated exposure level; if the average brightness > target brightness: the image is too bright, subtract the adjustment amount 'a' from the base exposure level to obtain the updated exposure level. For example, the exposure parameter table: levels 1 to 20 correspond to increasing exposure time and light sensitivity, with a preset initial exposure level (base exposure level = 8; matching exposure parameters: exposure time 1 / 60s). With a light sensitivity gain of 1.2x, a preset target brightness of 128, an exposure adjustment dead zone threshold of Ty = 10, and a level cutoff value of T = 20; if the scene is: the overall image is too dark, requiring increased exposure, and the average brightness of the pre-processed image in the current frame is 88; calculate the absolute value of the brightness difference D = |88−128| = 40, D > Ty = 10, requiring dimming; calculate the level adjustment amount a = (D−Ty)÷T = (40−10)÷20 = 1.5, round up a = 2; the average brightness 88 < the target brightness 128, the image is too dark, and the base level adjustment amount is increased: exposure update level = 8+2=10. When the camera starts, it loads the pre-set exposure table and the initial exposure level and exposure parameters; the exposure adjustment result of the current frame (such as looking up the table to retrieve the corresponding exposure parameters for level 10, sending them to the FPGA automatic exposure calculation core, extending the exposure time, increasing the light sensitivity gain, generating CMOS sensor drive control signals, completing the exposure adjustment of the current frame, and jumping to the next frame for cyclic acquisition after the adjustment is completed).
[0087] The above are all preferred embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Therefore, all equivalent changes made in accordance with the structure, shape and principle of the present invention should be covered within the scope of protection of the present invention.
Claims
1. An automatic exposure calculation method based on endoscopy, characterized in that, Includes the following steps: Step S1: Acquire raw image data, and initially extract pixel values of the blue channel, odd-numbered green channel, even-numbered green channel, and red channel from the raw image data to obtain initial extracted pixel values to be tested. Based on the initial extracted pixel values to be tested, compare the pixel values of the four channels B, Gb, Gr, and R at the same coordinates pixel by pixel. If the difference between the pixel value of a single channel and the pixel values of the other three channels all exceed the defective pixel judgment threshold, or if the difference between the pixel value of a single channel of each of the three channels and the pixel values of the other three channels all exceed the defective pixel judgment threshold, or if the difference between the pixel value of each of the two channels and the pixel value of one of the other two channels exceeds the defective pixel judgment threshold, mark the corresponding coordinate sensor defective pixels to be tested and remove defective pixels. Based on the defective pixels to be tested and the initially extracted pixel values to be tested, obtain a preprocessed brightness map based on the standard RGB to Y brightness weighted grayscale formula. Step S2: Based on the preprocessed brightness map, create an initial binary map, preset the zoom magnification-mask radius mapping function, assign values to the circular region of the initial binary map according to the zoom magnification-mask radius mapping function to obtain an adaptive circular mask binary map, divide the overall image region of the adaptive circular mask binary map into four independent scanning regions, obtain four test partitions, and sort the four test partitions by priority according to the marked valid pixels in the four test partitions to obtain a partition priority sequence; Step S3: According to the partition priority sequence, the adaptive circular mask binary image is partitioned and grown to obtain the target binary image. Based on the brightness value of the corresponding pixel in the preprocessed brightness image and the preset target brightness value, the level adjustment amount is obtained based on the linear deviation quantization level conversion. Based on the level adjustment amount, the preset exposure parameter table is matched, retrieved, and the sensor drive configuration is processed to obtain the current frame exposure adjustment result.
2. The automatic exposure calculation method based on endoscope according to claim 1, characterized in that, Step S1 includes: Acquire raw image data in BGGR format, count the pixel coordinates of the raw image data to obtain the coordinates of the pixel to be measured, and extract the blue channel pixel value, odd-numbered row green channel pixel value, even-numbered row green channel pixel value and red channel pixel value corresponding to the pixel coordinates to be measured from the raw image data to obtain the initial extracted pixel value to be measured. Based on the initial extracted pixel values to be tested, the pixel values of the four channels B, Gb, Gr, and R at the same coordinate are compared pixel by pixel. The difference between the pixel value of a single channel and the pixel values of the other three channels is calculated to obtain the pixel difference to be judged. A preset defective pixel detection threshold is set. If the difference between the pixel value of a single channel and the pixel values of the other three channels exceeds the defective pixel detection threshold, or if the difference between the pixel value of a single channel and the pixel values of the other three channels exceeds the defective pixel detection threshold, then the corresponding coordinate is determined to be a sensor defective pixel, and it is marked, and the defective pixel marking result 1 is output. If the difference between the pixel values of two channels and the pixel values of one of the other two channels exceeds the defective pixel detection threshold, and they are adjacent in position, then the corresponding coordinates are determined to be sensor defects, and they are marked, and defective pixel marking result two is output.
3. The automatic exposure calculation method based on endoscope according to claim 2, characterized in that, Step S1 also includes: If the difference between the pixel values of two channels and one of the pixel values of the other two channels exceeds the defective pixel judgment threshold, and they are not adjacent in position, then the two channel pixel values are marked as abnormal channel pixel values to be judged. Obtain the four-channel mean parameters of the 8 neighboring pixels around the abnormal coordinates, output the neighboring parameters to be tested, and calculate the mean of the same channel in the neighboring area based on the neighboring parameters to be tested. Calculate the deviation difference between the two abnormal channel pixel values in the undetermined abnormal channel pixel values and the mean of the same channel in the neighboring area. A preset neighborhood normal deviation threshold is set. If the deviation difference is greater than or equal to the neighborhood normal deviation threshold, the corresponding coordinates of the pixel value of the abnormal channel to be judged are determined to be sensor bad pixels, and they are marked. The bad pixel verification marking result three is output. One of the following results, namely bad pixel marking result one, bad pixel marking result two, and bad pixel verification marking result three, is collectively referred to as the bad pixel to be removed from the test. Based on the defective pixels to be removed, the initially extracted pixel values to be tested are filtered to obtain the effective pixel values to be tested; Based on the standard RGB to Y brightness-weighted grayscale conversion formula, the brightness value of each effective pixel to be measured is solved pixel by pixel to obtain a preprocessed brightness map of the same size as the original image data.
4. The automatic exposure calculation method based on endoscope according to claim 3, characterized in that, Step S2 includes: Based on the preprocessed brightness map, create an initial binary map with the same size as the preprocessed brightness map and with all pixels initially set to 0. The zoom ratio analog signal output in real time from the endoscope zoom lens is acquired, and the zoom ratio analog signal is analyzed based on ADC analog-to-digital conversion to obtain real-time lens zoom ratio data. A preset zoom ratio-mask radius mapping function is used to match the real-time lens zoom ratio data in the zoom ratio-mask radius mapping function to obtain the target circular radius. The target circular radius increases or decreases as the lens is in a zoom-in or zoom-out state. Based on the original image data and the radius of the target circle, the initial binary image is assigned a circular region value to obtain an adaptive circular mask binary image.
5. The automatic exposure calculation method based on endoscope according to claim 4, characterized in that, Step S2 also includes: Using the center of the adaptive circular mask binary image as a reference, the overall image area of the adaptive circular mask binary image is divided into four independent scanning areas: upper left, upper right, lower left, and lower right, to obtain four test areas. The marked effective pixels in the test areas are counted to obtain the total number of effective pixels and the average brightness data of each area. Based on the total number of effective pixels and the average brightness data of each partition, the four partitions to be tested are prioritized to obtain a partition priority sequence.
6. The automatic exposure calculation method based on endoscope according to claim 5, characterized in that, Step S3 includes: Obtain the current frame image information and the current imaging environment lighting conditions. Based on the current frame image information, if the current frame is the initial frame, determine the current imaging environment lighting conditions as a medium brightness normal scene lighting range and output the lighting range determination category one. If the current frame is not the initial frame, then the average brightness value of the previous frame corresponding to the current frame is calculated. Based on the average brightness value of the previous frame image, the current imaging environment lighting conditions are divided into low-brightness dark scene lighting range, medium-brightness normal scene lighting range, and high-brightness strong light scene lighting range, and the lighting range determination category two is output. One of the results of the illumination interval determination category one and the illumination interval determination category two is named the preprocessed illumination interval category; A preset brightness connectivity difference threshold is used. Based on the preprocessed illumination interval category, the brightness connectivity difference threshold is matched and retrieved to obtain a dynamic brightness difference threshold that is adapted to the current imaging environment illumination conditions. A fixed scanning direction is preset for each partition. Based on the fixed scanning direction of each partition, the partition priority sequence and the dynamic brightness difference threshold, pixel connectivity is determined for the adaptive circular mask binary image to obtain the connected pixel determination result. Based on the connected pixel determination results, the adaptive circular mask binary image is partitioned and grown to obtain the target binary image.
7. The automatic exposure calculation method based on endoscope according to claim 6, characterized in that, Step S3 also includes: Filter all valid pixels with a value of 1 in the target binary image to obtain preprocessed valid pixels, and obtain the final total number of valid pixels based on the preprocessed valid pixels; Extract the brightness values of the corresponding pixels in the preprocessed brightness map to obtain the brightness values of the preprocessed effective pixels. Sum the brightness values of the preprocessed effective pixels and divide them by the average of the total number of final effective pixels to obtain the average brightness value of the preprocessed image. A target brightness value is preset, and the absolute value of the difference between the average brightness value of the preprocessed image and the target brightness value is calculated to obtain the absolute value to be measured. A preset exposure adjustment dead zone threshold is set. If the absolute value to be measured is less than or equal to the exposure adjustment dead zone threshold, it is determined that the current exposure state of the image meets the standard and no exposure adjustment is required. The result of the exposure adjustment not required is output. If the absolute value to be measured is greater than the exposure adjustment dead zone threshold, the gear adjustment amount is obtained by quantizing the gear conversion based on the gear boundary value and the absolute value to be measured, according to the linear deviation. A preset exposure parameter table, initial exposure level, and matching exposure parameters are used as the base exposure level. Based on the initial exposure level and matching exposure parameters, the base exposure level is adjusted by increasing or decreasing according to the level adjustment amount to obtain the exposure update level. Based on the exposure update level, the preset exposure parameter table is matched and retrieved, and the sensor drive configuration is processed to output the exposure adjustment result of the current frame.
