A method and system for real-time conversion of x-ray foreign object detection images into pseudo-color
By employing nonlinear segmented color mapping and lookup table acceleration techniques in X-ray foreign object detection, the problem of high computational complexity in pseudo-color conversion methods is solved, enabling efficient real-time pseudo-color image conversion and visual enhancement on embedded industrial control computers, thereby reducing the false negative rate.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- HANGZHOU GUANGGUANG EVOLUTION TECHNOLOGY CO LTD
- Filing Date
- 2026-02-28
- Publication Date
- 2026-06-02
AI Technical Summary
Existing pseudo-color conversion methods have high computational complexity in X-ray foreign object detection, making it difficult to meet the real-time requirements of high-speed production lines. Furthermore, they fail to optimize for the characteristics of foreign objects with different densities, leading to inspectors easily overlooking subtle density differences and resulting in a high rate of missed detections.
By employing nonlinear segmented color mapping rules and lookup table acceleration technology, a multi-mode color mapping library is constructed. Through lookup table caching and reuse and vectorized indexing operations, real-time conversion of pseudo-color images is achieved, enhancing the contrast of foreign object areas.
Efficient real-time pseudo-color image conversion was achieved on a resource-constrained embedded industrial computer, reducing hardware dependence, improving the detection frame rate and visual contrast, and reducing the risk of missed detections.
Smart Images

Figure CN122134847A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of X-ray nondestructive testing image processing technology, and is particularly applicable to the field of real-time image display and analysis in X-ray foreign object detection scenarios in food, pharmaceutical and industrial parts production lines. Specifically, it relates to a pseudo-color real-time conversion method and system for X-ray foreign object detection images. Background Technology
[0002] X-ray nondestructive testing (NDT) is an important inspection method in the industrial field, widely used in production lines for food, pharmaceuticals, and industrial parts. An X-ray NDT image is obtained by a detector after X-rays penetrate objects of different materials and densities; the original image is a grayscale image. The human eye has limited ability to distinguish grayscale levels, typically only about 30-50 levels. For example, in the food safety industry, in production lines for meat, seafood, baked goods, and pre-packaged foods, operators directly rely on grayscale images to determine the presence of foreign objects such as metal, glass, bones, and fish bones, easily leading to missed detections. Due to the physiological limitations of the human eye's grayscale resolution and visual fatigue from prolonged operation, subtle density differences are easily overlooked, resulting in missed detections. The industry practice is to convert grayscale images into pseudo-color images, assigning different colors based on grayscale values. This significantly improves the operator's ability to distinguish image details, thereby increasing the accuracy and efficiency of foreign object detection.
[0003] Currently, commonly used pseudo-color conversion methods mainly include direct color channel linear transformation, HSL / HSV color space mapping, and the applyColorMap function conversion method based on general image processing libraries such as OpenCV. Among them, the HSL color space mapping method has the richest color expression, but the calculation process involves a large number of floating-point operations and conditional branch judgments. Taking color mapping mode mapping as an example, for each pixel, the grayscale value needs to be mapped to the hue angle, and then the final color value is obtained through HSL to RGB conversion. This conversion involves multiple conditional judgments and floating-point multiplication and division operations, which is time-consuming overall. Furthermore, the applyColorMap function conversion method based on general image processing libraries such as OpenCV includes redundant memory copying, type checking, and other overheads to ensure cross-platform compatibility. There are also solutions that use GPU acceleration. Under the condition of limited industrial control computer resources, it is difficult to maintain a sufficient frame rate in interpreted language environments such as Python, and it also increases hardware costs. For example, in food safety industrial production lines, the conveyor belt speed is usually 60-120 meters per minute, and the X-ray inspection system requires an image display frame rate of no less than 30 frames per second. The aforementioned pseudo-color conversion method is unacceptable in terms of efficiency and cost.
[0004] Furthermore, most common pseudo-color mapping methods currently used employ uniform linear color space transformations and are not optimized for the specific needs of X-ray detection of foreign objects of varying densities. For example, in the food safety industry, the grayscale difference between low-density foreign objects such as fish bones and the surrounding fish meat may only be a dozen or so grayscale levels. If linear mapping is used, the color differences corresponding to these dozen or so grayscale levels are very weak and easily overlooked by inspectors after prolonged operation, leading to an increased rate of missed detections.
[0005] Therefore, it is necessary to propose a pseudo-color conversion scheme for X-ray images that can maintain rich color expression, meet the real-time requirements of high-speed production lines, and visually enhance the density characteristics of foreign objects. Summary of the Invention
[0006] The purpose of this invention is to provide a method and system for real-time pseudo-color conversion of X-ray foreign object detection images. This method is based on lookup table acceleration, which can reduce the dependence on hardware performance in X-ray foreign object detection, improve the real-time conversion efficiency of pseudo-color images, and enhance the contrast of pseudo-color images.
[0007] To achieve the above objectives, the present invention provides the following technical solution:
[0008] A method for real-time pseudo-color conversion of X-ray foreign object detection images, comprising the following steps:
[0009] S1. Establish non-linear segmented color mapping rules:
[0010] Based on the difference in X-ray absorption rate between the foreign object to be detected and the background material, a nonlinear segmented color mapping rule is established. The mapping rule sets a compressed color gradient range for the background material area with low X-ray absorption rate and sets a stretched color gradient range for the foreign object area with high X-ray absorption rate. This is to asymmetrically stretch and enhance the grayscale contrast of the high-density foreign object area in the pseudo-color space.
[0011] S2. Construct a multi-mode color mapping library:
[0012] At least two pseudo-color mapping modes are preset; each pseudo-color mapping mode is designed for foreign objects with different density characteristics, and each pseudo-color mapping mode adopts the non-linear segmented color mapping rule described in step S1.
[0013] S3. Lazy lookup table construction and cache reuse:
[0014] In response to the pseudo-color mode switching command, it checks whether the lookup table for the target mode already exists in the memory cache. If it does not exist, it calculates the complete mapping relationship from n-bit grayscale levels to RGB color values according to the non-linear segmented color mapping rule corresponding to the mode, generating a table containing 2... nThe lookup table for each entry is cached in an independent cache area corresponding to that mode for reuse in subsequent frames. If the lookup table already exists, the calculation is skipped and the cached lookup table is referenced directly. The memory cache of the lookup table adopts a contiguous memory allocation strategy, arranging the RGB triples corresponding to each gray level into a contiguous array in an interleaved order. This array is aligned with the CPU cache line to ensure that the CPU's prefetching mechanism can be used to reduce memory access latency when performing vectorized indexing, thus meeting the real-time display requirement of no less than 30 frames per second for X-ray detection images.
[0015] S4. Acquire the real-time grayscale image stream of the production line, and perform detection area extraction and vectorized lookup table rendering:
[0016] The real-time grayscale image stream of the production line is dynamically divided into each frame image. The grayscale matrix data of the detection area in each frame image is extracted according to the pre-set boundary parameters. The grayscale matrix data is used as an index array. The index array is used to perform vectorized parallel array indexing operation on the lookup table in step S3 to retrieve and generate the corresponding RGB color matrix in one go.
[0017] S5. Image synthesis and output;
[0018] The RGB color matrix is mapped to the detection area of each frame image, while keeping the grayscale data of non-detection areas unchanged. A pseudo-color image is synthesized and output, realizing real-time pseudo-color enhancement display only for the effective detection area.
[0019] Preferably, the boundary threshold between the compressed color gradient range and the stretched color gradient range is set based on the type of the foreign object to be detected and the background material and the difference in their X-ray absorption characteristics. When the gray value is lower than the threshold, the pseudo-color difference between adjacent gray levels is small. When the gray value is higher than the threshold, the pseudo-color difference between adjacent gray levels increases, thereby improving the visual saliency of the foreign object edge in the pseudo-color image.
[0020] Preferably, the at least two pseudo-color mapping modes include a rainbow enhancement mode and a heatmap alert mode.
[0021] Preferably, the rainbow enhancement mode maps grayscale values to a hue angle range of 0° to 240° via a nonlinear gamma mapping function, where the gamma coefficient ranges from 0.6 to 1.2, selected based on the density characteristics of the detected foreign object. The saturation S is set to a fixed value of 1.0, and the brightness L is set to a fixed value of 0.5. After HSL to RGB color space conversion, a corresponding lookup table is generated. This mode uses full-spectrum expansion of the hue space to visually create color jumps for foreign objects with low density differences. The heatmap warning mode applies different gain coefficients to the R, G, and B color channels, where the R channel gain coefficient ranges from 1.2 to 1.6, the G channel gain coefficient ranges from 0.4 to 0.8, and the B channel gain coefficient ranges from 0.15 to 0.35. The output values of each channel are truncated to the range of 0-255. This mode makes high-density foreign object areas appear as highly saturated warm colors, while low-density backgrounds appear as cool, dark tones, facilitating quick identification of metallic or glassy foreign objects by operators.
[0022] Preferably, the lookup table delayed construction and cache reuse in step S3 further includes, when the lookup table is constructed for the first time, arranging the RGB triples corresponding to each gray level into a continuous array in an interleaved order, so that the array is aligned with the CPU cache line, so as to ensure that the CPU's prefetching mechanism is used to reduce memory access latency when the vectorized index is executed in step S4.
[0023] Preferably, the n-bit grayscale level is 8 bits, corresponding to 256 grayscale levels, and the lookup table contains 256 entries, with a single lookup table occupying 768 bytes of memory.
[0024] Preferably, the preset boundary parameters in step S4 are obtained in any of the following ways:
[0025] Method 1: During the initialization phase, a pre-stored configuration file is read, which records the physical coordinate mapping values of the detected area in the detector's field of view.
[0026] Method 2: During the no-load operation of the production line, the grayscale gradient is calculated column by column along the longitudinal direction of the X-ray grayscale image stream to identify the grayscale jump position between the edge of the detected area and the background. When the jump position deviation of multiple consecutive frames is within the preset pixel threshold, the position is locked as the boundary coordinate. The locked boundary coordinate remains unchanged during continuous operation until the operator manually triggers recalibration or restart.
[0027] Preferably, before the lookup rendering in step S4, a grayscale enhancement step based on a preprocessing lookup table is performed on the detected area; the preprocessing lookup table records the mapping relationship between grayscale values and enhanced grayscale values, and is used to perform contrast stretching or density contrast enhancement; the preprocessing lookup table and the pseudocolor lookup table can be merged into a single composite lookup table, that is, the grayscale values are directly mapped to the enhanced RGB color values, and only one lookup operation is needed during runtime to complete both grayscale enhancement and pseudocolor conversion simultaneously.
[0028] Preferably, the mapping parameters in the nonlinear segmented color mapping rule are dynamically adjusted based on the grayscale histogram distribution characteristics of the current frame or historical frames to adapt to density differences between different product batches.
[0029] Another objective of this invention is to provide a pseudo-color real-time conversion system for X-ray foreign object detection images, suitable for embedded industrial control environments, without relying on a dedicated GPU acceleration unit. The system includes: a color mapping library management module for storing at least two nonlinear segmented color mapping rules designed for different density features, and employing a delayed initialization strategy to manage the lookup table cache corresponding to each rule, calculating and locking the lookup table upon first activation of the mode; and a detection region splitting module for receiving the real-time grayscale image stream output from the X-ray detector, dividing each frame of the image into a detection region and a background region in real time according to preset boundary parameters, and transmitting the grayscale matrix data of the detection region to the detection region. A vectorized rendering engine is used to perform parallel array indexing operations on the lookup table cache provided by the color mapping library management module, using the grayscale matrix of the detected area as an index, to generate an RGB color matrix; an image synthesis output module is used to receive the RGB color matrix and the grayscale data of the non-detected area, synthesize the two into a complete pseudo-color image frame and output it; a foreign object alarm interface module is used to receive the pseudo-color enhancement result output by the vectorized rendering engine and transmit it to the downstream detection alarm unit to assist in foreign object location and alarm determination; the system is configured to execute the pseudo-color real-time conversion method for X-ray foreign object detection images.
[0030] Compared with the prior art, the beneficial effects of the present invention are:
[0031] First, this method transforms pixel-by-pixel HSL to RGB floating-point operations into vectorized array indexing operations, fully utilizing the CPU's SIMD instruction set and cache prefetching mechanism. In actual testing, the single-frame processing time for rainbow mode was reduced from tens of milliseconds to microseconds. Especially on resource-constrained embedded industrial control computers, this method effectively avoids the overhead of high-level language interpreters in pixel-by-pixel loops and thread lock contention through low-level memory optimization and continuous block operations, enabling the system to stably achieve industrial-grade frame rates of over 30fps without the need for expensive GPU accelerator cards. Second, since all modes involve table lookup operations during runtime, the frame processing time for different modes is essentially the same, eliminating the frame rate fluctuation problem caused by differences in algorithm complexity in traditional methods. Furthermore, the memory footprint of each lookup table is very small (768 bytes for 8-bit grayscale), and the simultaneous resident lookup tables of multiple modes in memory do not put pressure on the limited resources of the industrial control computer. Furthermore, the pseudo-color mapping of this invention is not merely an image enhancement technique, but rather addresses the practical needs of X-ray foreign object detection. By employing a nonlinear piecewise mapping strategy to stretch the color gradient of the foreign object region and compress the color gradient of the background region, it improves the visual contrast of the foreign object in the pseudo-color image. Feedback from production lines indicates that this targeted color enhancement helps reduce the risk of missed detections during long-term operations. While the method of this invention can also run on GPU-equipped computing platforms, its technical value is particularly evident in embedded industrial control environments without GPUs. Attached Figure Description
[0032] Figure 1 This is a flowchart of the pseudo-color real-time conversion method for X-ray foreign object detection images according to the present invention;
[0033] Figure 2 This is a detailed flowchart of the lookup table pre-calculation step of the present invention;
[0034] Figure 3 This is a schematic diagram of the color mapping of the rainbow pattern lookup table of the present invention;
[0035] Figure 4 This is a color mapping diagram of the heatmap pattern lookup table of the present invention;
[0036] Figure 5 This is a schematic diagram of the extraction of the detection area in the production line of the present invention;
[0037] Figure 6 This is a module structure diagram of the pseudo-color real-time conversion system for X-ray foreign object detection images of the present invention;
[0038] Figure 7 The image shows a comparison of frame rates before and after using the existing traditional method and the method of this invention. Detailed Implementation
[0039] To enable those skilled in the art to better understand the present invention, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0040] It should be specifically noted that the specific parameters (such as image size, region coordinates, gain coefficient, gamma coefficient, etc.) appearing in the following embodiments are illustrative and not intended to limit the scope of protection of this invention. Those skilled in the art can adjust the above parameters according to actual equipment configuration and detection requirements. As long as the technical principles and method steps described in this invention are followed, they all fall within the scope of protection of this invention. The following embodiments are based on an actual operating X-ray foreign object detection system for a food production line. The industrial control computer used for testing is configured with an Intel Core i5 processor, 8GB of memory, and a Windows 10 operating system.
[0041] Example 1: Pre-calculation of the rainbow pattern lookup table:
[0042] Taking an 8-bit grayscale image (grayscale level N=256) as an example. When the detector output bit depth is 10 bits or 12 bits, the grayscale level of the lookup table increases accordingly to 1024 or 4096. The space occupied by the lookup table increases, but the execution method of the lookup table mapping remains unchanged.
[0043] The calculation process for the rainbow pattern lookup table is as follows:
[0044] First, create a 256×3 array LUT with unsigned 8-bit integer data type (uint8). Then, iterate through the grayscale values i from 0 to 255, and perform hue mapping for each grayscale value according to the following formula:
[0045] H = pow(i / 255.0, gamma) × 240
[0046] Wherein gamma is the density enhancement coefficient. In this embodiment, different gamma values are selected for different food types (see Table 1). 240 degrees is selected as the upper limit of hue to allow the color spectrum to transition from red to blue (or vice versa), avoiding confusion between the beginning and end colors caused by the closure of the hue ring.
[0047] The hue angle is then normalized: h = H / 360. Fixed parameters are set: S = 1.0 (full saturation) and L = 0.5 (standard brightness).
[0048] Since L=0.5 is exactly on the boundary of the piecewise function, the intermediate variables are calculated as follows: q=L×(1+S)=1.0, p=2L-q=0.
[0049] Then, the hue2rgb auxiliary function is used to calculate the three color channels respectively:
[0050] R = hue2rgb(0, 1, h + 1 / 3) × 255
[0051] G = hue2rgb(0,1,h) × 255
[0052] B = hue2rgb(0, 1, h-1 / 3) × 255
[0053] The logic of hue2rgb(p, q, t) is as follows: first, normalize t to the range [0,1] (t<0 then t+1, t>1 then t-1), and then return the corresponding value according to the four-segment linear interpolation rule in the HSL standard conversion formula.
[0054] After computation, the result is stored in LUT[i]=[R,G,B], and a contiguous memory arrangement function (such as NumPy's ascontiguousarray) is called on the entire LUT array to ensure that the storage space is a contiguous block of 768 bytes, aligned with the CPU cache line. Finally, the LUT is cached in the instance variable and marked as computed.
[0055] After the above pre-calculation, the grayscale value 0 is mapped to the color value near blue (0,0,255), and the grayscale value 255 is mapped to red (255,0,0). The intermediate grayscale values transition smoothly, forming a rainbow spectrum covering the entire hue. Foreign objects to be detected include, but are not limited to, metallic foreign objects (such as iron, stainless steel, aluminum, etc.), non-metallic hard foreign objects (such as bone, glass, ceramics, stones), and high-density plastics, as well as metals, bones, and glass.
[0056] Table 1. Recommended gamma parameters for different detection scenarios (examples)
[0057] Detection scenario Typical foreign bodies Recommended gamma Design basis Aquatic products (fish) Fish bones, small bones 0.7-0.8 Low-density foreign objects have little grayscale difference from muscle, so it is necessary to stretch the contrast of the low grayscale area. Poultry (chicken, duck) Bone fragments, cartilage 0.8-0.9 Bone density slightly higher than fishbone, moderate enhancement is needed in the low to medium range. Baked goods Metal fragments 1.0 The large density difference between metal and dough means that linear mapping is sufficient to meet the identification requirements. Prepackaged food Glass shards, pebbles 0.9-1.0 The foreign object has a medium to high density; slightly compressing the high-grayscale area can make the edges of the foreign object stand out. Nuts / Dried Fruits Shell fragments, pebbles 1.0-1.2 The background density is inherently high and uneven, requiring stretching of high grayscale areas. Pharmaceutical blister packaging Metal wire, glass shards 0.9-1.0 Aluminum-plastic composite materials have a uniform background, and a medium gamma is sufficient to meet the requirements.
[0058] Note: The above gamma values are only empirical recommendations and can be fine-tuned according to the X-ray absorption characteristic curve of the specific product in actual applications.
[0059] Example 2
[0060] Pre-calculation of heatmap pattern lookup table:
[0061] The calculation of the heatmap mode is relatively simple. The specific process is as follows: calculate the three channels for the grayscale value array gray=[0,1,...,255] respectively:
[0062] LUT_R = clip(gray×1.4, 0, 255)
[0063] LUT_G = gray × 0.6
[0064] LUT_B = gray × 0.25
[0065] The `clip` function truncates out-of-range values to [0, 255]. When the grayscale value exceeds approximately 182, the R channel reaches saturation at 255. The three channel arrays are converted to uint8 type and then cached.
[0066] The heatmap mode renders high-grayscale areas (corresponding to high-density materials) as orange-red to bright white, and low-grayscale areas (corresponding to low-density materials) as deep blue to dark purple. This distribution of warm and cool tones aligns with the operator's intuitive understanding, helping to shorten reaction time. Compared to the rainbow mode, this mode's lookup table calculations do not involve HSL color space conversion, requiring only simple multiplication and truncation operations, resulting in shorter pre-calculation time.
[0067] Example 3
[0068] Lookup table mapping in real-time frame processing:
[0069] During the operation of the X-ray inspection system, the processing of each frame of image is performed according to the following procedure:
[0070] First, the grayscale image data of the current frame is obtained from the X-ray image buffer. In the device configuration of this embodiment, the image format is BGRA32 (4 bytes per pixel), and the image size is 1400×520 pixels (this size is determined by the model of the linear array detector used; different models of detectors correspond to different image sizes).
[0071] Next, the production line detection area is extracted. In the device of this embodiment, the production line area is a rectangular area (460 rows × 1400 columns) in the image with vertical coordinates y=10 to y=470, i.e., belt_region=image[10:470,:,:]. The top 10 rows and the bottom 50 rows are the edge area of the detector's field of view, containing interference signals such as the conveyor belt support and air gaps of the production line, and are not involved in pseudo-color processing. The above coordinate values are configuration parameters of the device in this embodiment, and should be adjusted according to the device installation in actual applications.
[0072] Then extract the grayscale channel. Since the original image is stored in BGRA format with grayscale values (R=G=B=grayscale value), the third channel can be extracted: gray=belt_region[:,:,2].
[0073] Then, a table lookup mapping is performed—the entire gray array is used as an index to directly retrieve the lookup table:
[0074] belt_region[:,:,2]=LUT[gray,0] (R channel)
[0075] belt_region[:,:,1]=LUT[gray,1] (G channel)
[0076] belt_region[:,:,0] = LUT[gray,2] (Channel B)
[0077] The above operation utilizes NumPy's advanced indexing capabilities to perform color mapping of all pixels at once using the entire grayscale matrix (a 460×1400 two-dimensional array) as the index, without any Python-level loops.
[0078] Finally, the processed image data is written back to the display buffer and output to the screen.
[0079] Example 4
[0080] Lookup table cache management and mode switching:
[0081] The lookup table in this invention is managed using a lazy initialization strategy: no lookup table is pre-calculated at system startup, and all lookup tables for all modes are marked as uninitialized. When a user switches to a pseudo-color mode for the first time, the system checks the corresponding cache flag—if it is uninitialized, it performs pre-calculation and stores the cache; if it is initialized, it is used directly.
[0082] Each mode's lookup table is cached independently and does not overwrite others. For example, the lookup table for Rainbow mode is stored in an instance variable named _rainbow_lut, while the three channel lookup tables for Heatmap mode are stored in _hot_lut_r, _hot_lut_g, and _hot_lut_b, respectively. When a user switches between Rainbow mode and Heatmap mode, only the lookup table object referenced in the lookup step needs to be changed; recalculation is unnecessary.
[0083] When caching the lookup table, the NumPy `ascontiguousarray` function is called additionally to ensure that the array occupies a contiguous memory address space. This step aims to align the physical storage of the lookup table with the CPU's cache lines, improving the L1 / L2 cache hit rate during batch indexing. Since each lookup table is only 768 bytes, much smaller than the typical L1 cache size (usually 32KB-64KB), the lookup table will most likely remain in the L1 cache during actual operation, further reducing lookup latency.
[0084] Example 5
[0085] Performance comparison test:
[0086] With the above industrial control computer configuration, a performance comparison test was conducted using a 1400×460 pixel image of the production line area. The results are shown in Table 2.
[0087] Table 2 Performance Comparison Test Data
[0088] Processing mode Traditional method (Python loop) single frame time / ms The method of this invention (vectorized lookup table) has a single frame time of / ms. Frame rate stability Rainbow Mode 38.5 0.015 virtually no shaking Heatmap mode 5.2 0.012 virtually no shaking Grayscale mode (no processing) 0 0 - CPU utilization (single core) Near full load <5% -
[0089] Test data shows a significant difference between the 38.5ms execution time of the traditional rainbow mode implementation and the 5.2ms execution time of the heatmap mode. This is because the HSL to RGB conversion in rainbow mode involves multiple floating-point operations and conditional judgments, making its computational complexity far higher than the simple channel multiplication in heatmap mode. However, by adopting the lookup table method of this invention, the execution time of both modes is reduced to the microsecond level and the values are similar, because no matter how complex the lookup table generation logic is, the runtime processing is the same array indexing operation.
[0090] The CPU utilization rate dropped from near full load to less than 5%, meaning that most of the processor's computing power was freed up and could be allocated to other task modules such as foreign object detection algorithms, image storage, and network communication. Under the condition of a conveyor belt speed of 120 meters per minute on a production line, the system can maintain a display frame rate of 60 frames per second, meeting the real-time detection needs of the production line.
[0091] Regarding the visual enhancement effect: In rainbow mode, low-density foreign objects (such as fish bones in fish meat) with a grayscale difference of only a dozen gray levels originally exhibit a significantly increased pseudo-color span after nonlinear gamma mapping, forming more easily distinguishable color transitions in the color space. Production line operators have reported that using the pseudo-color enhancement display of this invention has reduced visual fatigue during long-term continuous inspection operations and improved the identification speed of suspicious areas.
[0092] Example 6
[0093] Construction and application of composite lookup tables:
[0094] In some applications, in addition to pseudo-color mapping, preprocessing operations such as contrast stretching or density enhancement are required. Traditionally, this involves first performing a preprocessing lookup to obtain the enhanced grayscale value, and then performing a pseudo-color lookup to obtain the RGB value, requiring two separate lookup operations. This embodiment provides a composite lookup table scheme that combines the two mapping steps into one, further improving processing efficiency.
[0095] The process of constructing a composite lookup table is as follows:
[0096] The first step is to construct a preprocessing mapping function f(g), where g is the original grayscale value and f(g) is the enhanced grayscale value. Common preprocessing methods include linear contrast stretching, histogram equalization, and S-curve enhancement. Taking linear contrast stretching as an example, if the original grayscale range is [g_min, g_max] and the target range is [0, 255], then f(g) = (g - g_min) × 255 / (g_max - g_min).
[0097] The second step is to construct a pseudo-color mapping function C(g), which is the grayscale to RGB mapping of the aforementioned rainbow mode or heatmap mode.
[0098] The third step is to combine the two mapping functions into a single mapping: CompositeLUT[g] = C(f(g)). Specifically, the original grayscale value g is iterated from 0 to 255. First, f(g) is calculated to obtain the enhanced grayscale value. Then, C(f(g)) is calculated using the enhanced grayscale value as input to obtain the final RGB value, which is then stored in the composite lookup table.
[0099] The memory footprint of a composite lookup table is the same as that of a regular pseudo-color lookup table (256×3 bytes), but only one lookup operation is needed at runtime to complete both grayscale enhancement and pseudo-color conversion simultaneously, avoiding the additional memory access overhead caused by two independent lookups.
[0100] In practical applications, multiple composite lookup tables can be pre-built and cached for different preprocessing needs, and a delayed initialization strategy is also used to manage the switching.
[0101] Example 7
[0102] Linkage with foreign object detection alarm:
[0103] The pseudo-color enhancement results of this invention can be linked with the downstream foreign object detection module. Specifically, the RGB color matrix output by the vectorized rendering engine is not only used for display but can also be passed to the foreign object detection algorithm module as auxiliary input. When the detection algorithm identifies a suspicious foreign object in a certain area, the alarm unit triggers an audible and visual alarm and can simultaneously send a mode switching command to the color mapping library management module, such as automatically switching from the conventional rainbow mode to a high-contrast heatmap warning mode, making the suspicious area more prominent in the display screen.
[0104] This closed-loop linkage mechanism between display enhancement and detection alarm helps operators quickly locate foreign objects after an alarm is triggered, improving re-inspection efficiency.
[0105] Further implementation methods
[0106] In a further embodiment, the gamma parameter can also be dynamically adjusted based on the grayscale histogram distribution characteristics of the current frame or historical frames to adapt to density differences between different product batches. For example, when the system detects that the overall grayscale distribution of the current batch of products is biased towards the high grayscale range, it can automatically reduce the gamma value to enhance the color resolution of the low grayscale range. This adaptive parameter adjustment mechanism can be considered an extension of the present invention.
[0107] While the invention has been described with reference to specific embodiments, it should be understood that these embodiments are merely examples of the principles and applications of the invention. Therefore, it should be understood that many modifications can be made to the exemplary embodiments, and other arrangements can be designed without departing from the spirit and scope of the invention as defined by the appended claims. It should be understood that different dependent claims and features described in the invention can be combined in ways different from those described in the original claims. It is also understood that features described in conjunction with individual embodiments can be used in other described embodiments.
Claims
1. A method for real-time pseudo-color conversion of X-ray foreign object detection images, characterized in that, Including the following steps: S1. Establish non-linear segmented color mapping rules: Features are constructed based on the difference in X-ray absorption rates between the foreign object to be detected and the background material, and a nonlinear segmented color mapping rule is established. The mapping rule sets a compressed color gradient range for the background material area with low X-ray absorption rate and sets a stretched color gradient range for the foreign object area with high X-ray absorption rate. S2. Construct a multi-mode color mapping library: The multi-mode color mapping library has at least two preset pseudo-color mapping modes; each pseudo-color mapping mode is designed for foreign objects with different density characteristics, and each pseudo-color mapping mode adopts the non-linear segmented color mapping rule described in step S1. S3. Lazy lookup table construction and cache reuse: In response to the pseudo-color mode switching command, check whether the lookup table for the target mode already exists in the memory cache space; If it does not exist, then according to the non-linear segmented color mapping rule corresponding to the mode, calculate the complete mapping relationship from n-bit grayscale levels to RGB color values, and generate a value containing 2... n The lookup table for each entry is calculated and cached in the independent cache area corresponding to the pattern for reuse in subsequent frames; if it already exists, the calculation is skipped and the cached lookup table is referenced directly. S4. Acquire the real-time grayscale image stream of the production line, and perform detection area extraction and vectorized lookup table rendering: The real-time grayscale image stream of the production line is dynamically divided into each frame image. The grayscale matrix data of the detection area in each frame image is extracted according to the pre-set boundary parameters. The grayscale matrix data is used as an index array. The index array is used to perform vectorized parallel array indexing operation on the lookup table in step S3 to retrieve and generate the corresponding RGB color matrix in one go. S5. Image synthesis and output; The RGB color matrix is mapped to the detection area of each frame image, while keeping the grayscale data of the non-detection areas unchanged, and a pseudo-color image is synthesized and output.
2. The method for real-time pseudo-color conversion of X-ray foreign object detection images according to claim 1, characterized in that, The boundary threshold between the compressed color gradient range and the stretched color gradient range is set based on the type of the foreign object to be detected and the background material and the difference in their X-ray absorption rates.
3. The method for real-time pseudo-color conversion of X-ray foreign object detection images according to claim 1, characterized in that, The at least two pseudo-color mapping modes include a rainbow enhancement mode and a heatmap alert mode.
4. The method for real-time pseudo-color conversion of X-ray foreign object detection images according to claim 3, characterized in that, The rainbow enhancement mode maps grayscale values to a hue angle range of 0° to 240° through a nonlinear gamma mapping function, where the gamma coefficient ranges from 0.6 to 1.2 and is selected based on the density characteristics of the detected foreign object; the saturation S is set to a fixed value of 1.0 and the brightness L is set to a fixed value of 0.5, and a corresponding lookup table is generated after HSL to RGB color space conversion; The heatmap alert mode applies different gain coefficients to the three color channels R, G, and B respectively. The gain coefficient of the R channel ranges from 1.2 to 1.6, the gain coefficient of the G channel ranges from 0.4 to 0.8, and the gain coefficient of the B channel ranges from 0.15 to 0.
35. The output value of each channel is truncated to the range of 0-255.
5. The method for real-time pseudo-color conversion of X-ray foreign object detection images according to claim 1, characterized in that, The lookup table delayed construction and cache reuse in step S3 further includes, when the lookup table is constructed for the first time, arranging the RGB triples corresponding to each gray level into a continuous array in an interleaved order, so that the array is aligned with the CPU cache line, so as to ensure that the CPU's prefetching mechanism is used to reduce memory access latency when the vectorized index is executed in step S4.
6. The method for real-time pseudo-color conversion of X-ray foreign object detection images according to claim 1, characterized in that, The n-bit grayscale level is 8 bits, corresponding to 256 grayscale levels. The lookup table contains 256 entries, and the memory usage of a single lookup table is 768 bytes.
7. The method according to claim 1, characterized in that, The preset boundary parameters mentioned in step S4 are obtained through any of the following methods: Method 1: During the initialization phase, a pre-stored configuration file is read, which records the physical coordinate mapping values of the detected area in the detector's field of view. Method 2: During the no-load operation of the production line, the grayscale gradient is calculated column by column along the longitudinal direction of the X-ray grayscale image stream to identify the grayscale jump position between the edge of the detected area and the background. When the jump position deviation of multiple consecutive frames is within the preset pixel threshold, the position is locked as the boundary coordinate. The locked boundary coordinate remains unchanged during continuous operation until the operator manually triggers recalibration or restart.
8. The method according to claim 1, characterized in that, Before the lookup rendering in step S4, a grayscale enhancement step based on a preprocessing lookup table is performed on the detected region; the preprocessing lookup table records the mapping relationship between grayscale values and enhanced grayscale values, and is used to perform contrast stretching or density contrast enhancement. The preprocessing lookup table and the pseudo-color lookup table can be merged into a single composite lookup table, which directly maps grayscale values to enhanced RGB color values. During runtime, only one table lookup operation is needed to simultaneously complete grayscale enhancement and pseudo-color conversion.
9. The method according to claim 1, characterized in that, The mapping parameters in the nonlinear segmented color mapping rule are dynamically adjusted based on the grayscale histogram distribution characteristics of the current frame or historical frames to adapt to density differences between different product batches.
10. A pseudo-color real-time conversion system for X-ray foreign object detection images, characterized in that, include The color mapping library management module is used to store at least two non-linear segmented color mapping rules designed for different density features, and adopts a delayed initialization strategy to manage the lookup table cache corresponding to each rule. The lookup table is calculated and locked when the mode is first activated. The detection area splitting module is used to receive the real-time grayscale image stream output by the X-ray detector, divide each frame of the image into the detection area and the background area in real time according to the preset boundary parameters, and transmit the grayscale matrix data of the detection area to the vectorized rendering engine. The vectorized rendering engine is used to perform parallel array indexing operations on the lookup table cache provided by the color mapping library management module, using the grayscale matrix of the detected region as an index, to generate an RGB color matrix. The image synthesis output module is used to receive the RGB color matrix and the grayscale data of the non-detection area, synthesize the two into a complete pseudo-color image frame and output it. The foreign object alarm interface module is used to receive the pseudo-color enhancement results output by the vectorized rendering engine and transmit them to the downstream detection alarm unit to assist in foreign object location and alarm determination. The system is configured to perform a pseudo-color real-time conversion method for X-ray foreign object detection images as described in any one of claims 1-9.