A color region detection method and device for unreal engine
Patent Information
- Application Number
- CN202610836858.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-10
- Publication Date
- 2026-09-29
- Estimated Expiration
- 2046-06-10
AI Technical Summary
这种由于渲染噪声导致的像素特征不确定性使得算法在提取目标颜色区域时产生偏差,若为了消除该光照偏差而增加无光照通道或修改后处理渲染管线,又会破坏原有的全局光照氛围并增加额外的渲染负载,导致定位结果及执行效率无法支撑高精度的实时交互需求
[0015]根据本公开实施例的第三方面,提供了一种计算机设备,包括:
Smart Images

Figure CN122368213B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of image processing technology, and to a method and apparatus for color region detection in Unreal Engine. Background Technology
[0002] In interactive recognition and automated detection in Unreal Engine 5 (UE5), it is often necessary to determine the precise range of a specific color region. Since Unreal Engine 5 does not provide a mechanism for extracting region boundaries, related technologies usually use global pixel traversal to determine the target color region.
[0003] Furthermore, in UE5's real-time dynamic lighting rendering environment, the target color will exhibit complex nonlinear gradients and discrete bright spot noise at physical boundaries. This uncertainty in pixel features caused by rendering noise leads to deviations in the algorithm when extracting the target color region. If an unlit channel is added or the post-processing rendering pipeline is modified to eliminate this lighting deviation, it will disrupt the original global illumination atmosphere and increase the additional rendering load, resulting in positioning results and execution efficiency that cannot support the high-precision real-time interaction requirements. Summary of the Invention
[0004] This disclosure provides a method and apparatus for color region detection in Unreal Engine. Without modifying the underlying rendering pipeline or adding additional rendering load, it effectively eliminates the interference of dynamic lighting and rendering noise on color features. Compared with global pixel traversal, it reduces the computational cost of the algorithm, thus balancing execution efficiency and positioning accuracy, and achieving efficient and high-precision extraction of the boundary of the target color region.
[0005] Other features and advantages of this disclosure will become apparent from the following detailed description, or may be learned in part from practice of this disclosure.
[0006] According to a first aspect of the present disclosure, a method for color region detection in Unreal Engine is provided, the method comprising: Obtain the pixel data, preset target color, and preset tolerance range of the image to be rendered; A brightness compensation factor is calculated based on the perceived brightness of each pixel in the pixel data and the brightness deviation of the preset target color. The brightness compensation factor is used to perform a weighted correction between each pixel in the pixel data and the preset target color to obtain the matching value of each pixel. Using the pixels whose matching values are within the preset tolerance range as the starting nodes for evolution, spatial expansion processing is performed to obtain the target color region corresponding to the preset target color.
[0007] In some exemplary embodiments of this disclosure, based on the foregoing scheme, the step of calculating the brightness compensation factor according to the brightness deviation between the perceived brightness of each pixel in the pixel data and the preset target color includes: The red channel value, green channel value, and blue channel value of each pixel in the pixel data are weighted according to the preset perception weight to obtain the perceived brightness value of each pixel. Calculate the absolute difference between the perceived brightness value of each pixel and the brightness reference value of the preset target color; Calculate the product of the preset sensitivity coefficient and the absolute difference, and determine the sum of the product and the preset threshold as the brightness perception attenuation coefficient; The ratio of the preset constant to the brightness perception attenuation coefficient is determined as the brightness compensation factor.
[0008] In some example embodiments of this disclosure, based on the foregoing scheme, the step of using the brightness compensation factor to perform weighted correction on each pixel in the pixel data and the preset target color to obtain the matching value of each pixel includes: The original squared distance value of each pixel is obtained by performing a summation operation on the component differences between each pixel and the preset target color in the red channel, green channel, blue channel and alpha channel; The product of the original squared distance value and the brightness compensation factor is determined as the matching value for each pixel.
[0009] In some example embodiments of this disclosure, based on the foregoing scheme, the step of performing spatial expansion processing with pixels whose matching values are within the preset tolerance range as evolution starting nodes to obtain a target color region corresponding to the preset target color includes: The maximum position coordinate in the image to be detected is determined as the first position coordinate, and the minimum position coordinate in the image to be detected is determined as the second position coordinate. An anisotropic extension vector is constructed based on the rate of change of color components between the evolution start node and its corresponding adjacent pixels. The search path of the evolution starting node is spatially expanded using the anisotropic extension vector, and the first position coordinates and the second position coordinates are updated based on the coordinates of the effective pixels within the extended path that satisfy the preset tolerance range. The topological boundary range of the target color region is determined based on the updated first position coordinates and second position coordinates.
[0010] In some exemplary embodiments of this disclosure, based on the foregoing scheme, the Spatial expansion of the search path for the evolutionary starting node using the anisotropic extension vector includes: Calculate the rate of change of color components of the evolution starting node in multiple expansion directions, and determine the reciprocal of the rate of change corresponding to each expansion direction as the step size modulation weight of each dimension. Based on the step size modulation weight, determine the step size gain and step size attenuation in each of the expansion directions; The expansion distance of the search path is controlled by the step size gain and the step size decay.
[0011] In some exemplary embodiments of this disclosure, based on the foregoing scheme, the The method of controlling the expansion distance of the search path by means of the step size gain and the step size decay also includes: When the cumulative expansion step size of the search path reaches the preset step size threshold, the color deviation rate of the current edge node towards the evolution starting node is obtained. If the color deviation rate is within the preset coherence range, the current search path is determined to be valid, and the corresponding pixel is determined as a component pixel of the target color region.
[0012] In some example embodiments of this disclosure, based on the foregoing scheme, updating the first position coordinates and the second position coordinates based on the coordinates of valid pixels within the extended path that satisfy the preset tolerance range further includes: For each valid pixel within the extended path that satisfies the preset tolerance range, obtain the horizontal and vertical coordinate values of the valid pixel. The smaller value between the horizontal coordinate value of the effective pixel and the horizontal coordinate value of the first position coordinate is determined as the updated horizontal coordinate value of the first position coordinate. The smaller value between the vertical coordinate value of the effective pixel and the current vertical coordinate value of the first position coordinate is determined as the updated vertical coordinate value of the first position coordinate. The larger value between the horizontal coordinate value of the effective pixel and the current horizontal coordinate value of the second position is determined as the updated horizontal coordinate value of the second position. The larger value between the vertical coordinate value of the effective pixel and the current vertical coordinate value of the second position coordinate is determined as the updated vertical coordinate value of the second position coordinate.
[0013] In some exemplary embodiments of this disclosure, based on the foregoing scheme, the Based on the updated first and second position coordinates, the topological boundary range of the target color region is determined, including: If the horizontal coordinate value of the updated first position coordinate is less than the horizontal coordinate value of the updated second position coordinate, and the vertical coordinate value of the updated first position coordinate is less than the vertical coordinate value of the updated second position coordinate, then the target color region is determined based on the updated first position coordinate and the updated second position coordinate.
[0014] According to a second aspect of the present disclosure, a color region detection apparatus for Unreal Engine is provided, the apparatus comprising: The acquisition module is used to acquire the pixel data, preset target color, and preset tolerance range of the image to be detected and rendered; The calculation module is used to calculate a brightness compensation factor based on the perceived brightness of each pixel in the pixel data and the brightness deviation of the preset target color, and to use the brightness compensation factor to perform weighted correction on each pixel in the pixel data and the preset target color to obtain the matching value of each pixel. The processing module is used to perform spatial expansion processing on pixels whose matching values are within the preset tolerance range as evolution starting nodes to obtain a target color region corresponding to the preset target color.
[0015] According to a third aspect of the present disclosure, a computer device is provided, comprising: Processor; and A memory storing computer-readable instructions that, when executed by the processor, implement the method of the first aspect.
[0016] This application provides a color region detection method for Unreal Engine. It generates a brightness compensation factor by extracting the deviation between the perceived brightness of a pixel and the target color, and then uses this factor to perform weighted correction on the original pixels. Thus, the non-linear color shift in Unreal Engine is dynamically eliminated through the compensation factor, restoring pixel values distorted by lighting and shadow interference to a unified baseline range. This process is implemented entirely at the algorithm logic level, without modifying the Unreal Engine's post-processing rendering pipeline or adding additional rendering channels. Therefore, it avoids additional GPU rendering load without disrupting the original global illumination atmosphere of the scene, solving the problem of decreased detection accuracy under complex dynamic lighting and shadow conditions.
[0017] Furthermore, the modified matching values are used to filter the evolution start nodes and perform spatial expansion processing. This feature transforms the isolated pixel matching logic into a self-organizing evolution method based on spatial topological relationships, eliminating bright spot noise that cannot form a coherent topological structure during the growth process. This not only eliminates redundant traversal of all pixels in the image, reducing the computational power consumption of the CPU main thread and improving the real-time response speed of detection; but also suppresses boundary extreme value coordinate jitter caused by discrete noise interference, avoids abnormal stretching of the target color region, achieves precise locking of the target color region, and improves the reliability and accuracy of automated detection and interactive localization.
[0018] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0019] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure. It is obvious that the drawings described below are merely some embodiments of this disclosure, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.
[0020] Figure 1 The illustration schematically shows a flowchart of a color region detection method for Unreal Engine according to some embodiments of the present disclosure.
[0021] Figure 2 The illustration schematically shows a flowchart of a method for spatially expanding the search path for the evolution start node according to some embodiments of the present disclosure.
[0022] Figure 3 The schematic diagram illustrates the structure of a color region detection apparatus for Unreal Engine according to some embodiments of the present disclosure.
[0023] Figure 4 The illustration schematically shows a hardware structure diagram of a computer device according to some embodiments of the present disclosure.
[0024] Figure 5 A schematic diagram of a computer-readable storage medium according to some embodiments of the present disclosure is shown.
[0025] In the accompanying drawings, the same or corresponding reference numerals indicate the same or corresponding parts. Detailed Implementation
[0026] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this specification. Rather, they are merely examples of systems and methods consistent with some aspects of this specification as detailed in the appended claims.
[0027] The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of this specification. The singular forms “a,” “the,” and “the” as used in this specification and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.
[0028] It should be understood that although the terms first, second, third, etc., may be used in this specification to describe various information, this information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this specification, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."
[0029] Furthermore, the accompanying drawings are for illustrative purposes only and are not necessarily drawn to scale. The block diagrams shown in the drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor systems and / or microcontroller systems.
[0030] In this example embodiment, a color region detection method for Unreal Engine is first provided, such as... Figure 1 As shown, Figure 1 The schematic diagram illustrates a flow chart of a color region detection method for Unreal Engine according to some embodiments of the present disclosure. Reference Figure 1 As shown, the color region detection method for Unreal Engine may include the following steps: Step 110: Obtain the pixel data, preset target color, and preset tolerance range of the image to be rendered.
[0031] Step 120: Calculate the brightness compensation factor based on the brightness deviation between the perceived brightness of each pixel in the pixel data and the preset target color, and use the brightness compensation factor to perform weighted correction between each pixel in the pixel data and the preset target color to obtain the matching value of each pixel.
[0032] Step 130: Using pixels whose matching values are within the preset tolerance range as the starting nodes for evolution, perform spatial expansion processing to obtain the target color region corresponding to the preset target color.
[0033] The color region detection method provided in this application determines a brightness compensation factor by extracting the perceived brightness of a pixel and the brightness deviation of a preset target color, and then applies a weighted correction to the original pixels accordingly. Therefore, compared to matching methods that rely on a single fixed tolerance, this method can dynamically cancel out non-linear color shifts caused by high dynamic range lighting, self-illumination, and automatic exposure in Unreal Engine. By restoring pixel values distorted by lighting interference to a unified reference range, the problem of inaccurate matching accuracy under complex lighting conditions is solved. Furthermore, this compensation process is entirely algorithm-based, requiring no intervention or modification to the underlying post-processing rendering pipeline of Unreal Engine, nor requiring additional rendering channels. Thus, without disrupting the original global illumination atmosphere of the scene, it avoids the additional GPU rendering load caused by modifying the rendering architecture.
[0034] Furthermore, pixels with matching values within the tolerance range are used as the starting nodes for evolution to perform spatial expansion processing to determine the final target color region. This process transforms isolated pixel matching logic into a region evolution mechanism based on spatial topology. Utilizing the connectivity of the target region, isolated bright spots and noise points that cannot form a continuous structure are filtered out during the evolution process. This not only eliminates redundant traversal of all pixels in the image, reducing the computational burden on the CPU main thread and ensuring frame rate stability during real-time interaction, but also suppresses boundary extreme coordinate jitter caused by discrete noise interference, avoids abnormal stretching of the target color region, achieves accurate fitting of the target color region, and improves the reliability and accuracy of automated detection and interactive positioning.
[0035] The color region detection method for Unreal Engine in this example embodiment will be further described below.
[0036] In step 110, the pixel data, preset target color, and preset tolerance range of the image to be detected and rendered are obtained.
[0037] In one example embodiment of this disclosure, the rendered image to be detected refers to a real-time image resource generated by the Unreal Engine rendering pipeline. As an example, the rendered image to be detected is represented using the UE5 native UTextureRenderTarget2D class. Since the rendering data is stored on the GPU side, while the color region detection logic is executed on the host processor (such as the CPU), cross-hardware platform data synchronization is required.
[0038] To ensure thread safety during data reading and avoid system crashes or data inconsistencies caused by concurrent access to rendering resources, this disclosure does not directly access texture pointers. Instead, it obtains the target resource object of the image to be rendered by calling the GameThread_GetRenderTargetResource() interface. Subsequently, ensuring the target resource object is valid, the raw pixel stream from the GPU is read into a pixel array in memory. During the reading process, automatic mapping is performed according to the pixel format of the rendering target.
[0039] The preset target color refers to the color baseline value preset by the user through the UE5 editor interface or Blueprint interface. To counteract the interference of global illumination or post-processing on the value, a linear color space can be used.
[0040] Preset tolerance is a scalar parameter used to control the sensitivity of matching boundaries. In real-world scenarios, due to the anti-aliasing and compression algorithms in Unreal Engine causing slight deviations in color edges, preset tolerance can provide a reasonable matching bandwidth.
[0041] In one example embodiment of this disclosure, validity verification can be performed based on a multi-level error detection method during the acquisition of the aforementioned data. The first level of detection verifies whether the UTextureRenderTarget2D object is null to prevent invalid pointers from triggering exceptions. The second level of detection compares whether the length of the read pixel array is consistent with the product of the width and height of the rendering target. If the UTextureRenderTarget2D object is null or the length of the read pixel array is inconsistent with the product of the width and height of the rendering target, an error warning will be thrown and execution will be blocked through the UE_LOG system integrated inside the engine, thereby ensuring the integrity of the data throughout the entire chain.
[0042] In step 120, a brightness compensation factor is calculated based on the brightness deviation between the perceived brightness of each pixel in the pixel data and the preset target color. The brightness compensation factor is then used to perform weighted correction between each pixel in the pixel data and the preset target color to obtain the matching value of each pixel.
[0043] In one example embodiment of this disclosure, under the high dynamic range lighting rendering environment of Unreal Engine 5, target objects tend to appear whiter under strong light and darker in shadow areas. This phenomenon caused by complex scene lighting can lead to a severe non-linear shift in the color of the same target object within the RGB color space. If a fixed tolerance is used directly for color value comparison, it is very easy to cause misjudgment. Although in the conventional processing methods of related engines, color difference can be eliminated by globally modifying the automatic exposure parameters in the post-processing volume or forcibly flattening the shadow contrast, this will destroy the original overall lighting atmosphere and visual rendering effect of the scene. Therefore, this embodiment introduces a dynamic brightness dimension for supplementary calculation in the underlying pixel matching logic. This method can eliminate light and shadow interference through an algorithmic compensation mechanism without modifying the engine's post-processing rendering pipeline or affecting the original global lighting performance of the scene, and uniformly pull the pixel values distorted by light and shadow back to a comparable benchmark system.
[0044] For example, the red, green, and blue channel values of each pixel in the pixel data are weighted according to preset perceptual weights to obtain the perceptual brightness value of each pixel. Since the human visual system has significantly different sensitivities to different color channels, and the light radiation energy in the rendering engine is not uniformly distributed across the channels, weighted summation using preset perceptual weights (e.g., based on the Rec. 709 standard, setting the perceptual weights of the red, green, and blue channels to 0.2126, 0.7152, and 0.0722 respectively) can reduce the multidimensional color data to a single-dimensional perceptual brightness value, thus objectively representing the current physical brightness of the pixel. The same weighted calculation can be performed on a preset target color according to these preset perceptual weights to obtain the corresponding brightness baseline value.
[0045] Subsequently, the product of the preset sensitivity coefficient and the absolute difference is calculated, and the sum of this product and the preset threshold is determined as the brightness perception attenuation coefficient; the ratio of the preset constant to the brightness perception attenuation coefficient is determined as the brightness compensation factor. For example, the preset threshold and preset constant can be determined according to actual conditions and are not specifically limited. Based on this calculation method of the brightness compensation factor, the more severe the deviation of the pixel's brightness from the brightness reference value, the larger its perception attenuation base, and the smaller the calculated brightness compensation factor.
[0046] In one example embodiment of this disclosure, the process of using a brightness compensation factor to weight and correct each pixel in the pixel data with the preset target color to obtain the matching value of each pixel may include the following steps: First, the squared differences between each pixel and the preset target color in the red, green, blue, and alpha channels are summed to obtain the original squared distance value of each pixel. In the real-time operating environment of Unreal Engine, using conventional Euclidean distance for similarity determination would significantly increase the CPU's instruction execution cycle due to the floating-point square root operation across all pixels, leading to a computational bottleneck. This embodiment skips the square root step by using the summation of squares operation, preserving the monotonicity of color differences and improving the algorithm's execution efficiency.
[0047] Then, the product of the original squared distance value and the brightness compensation factor is used to determine the matching value for each pixel. In actual calculations, pixels of the same color that are strongly affected by lighting interference usually have original squared distance values that exceed the preset tolerance range. In this case, multiplicative scaling using the smaller brightness compensation factor obtained in the previous step can apply a decay penalty to the excessively large distance value, bringing it back to the preset tolerance range. For background noise pixels with different hues, their original squared distance values are large, and even after scaling with the brightness compensation factor, the final matching value will still be effectively blocked outside the tolerance range. Thus, without modifying the original data structure, adaptive dynamic correction of color detection in complex lighting scenarios is achieved, thereby avoiding frequent high-bandwidth data readbacks between the GPU and CPU and reducing data synchronization latency across hardware platforms.
[0048] In step 130, the pixels whose matching values are within the preset tolerance range are used as the starting nodes for evolution to perform spatial expansion processing, thereby obtaining the target color region corresponding to the preset target color.
[0049] In the exemplary implementation of this disclosure, the process of performing spatial expansion processing with pixels whose matching values are within a preset tolerance range as the starting nodes for evolution includes the following steps: Step 1301: Determine the maximum position coordinate in the image to be detected as the first position coordinate, and determine the minimum position coordinate in the image to be detected as the second position coordinate.
[0050] For example, during the initialization phase of spatial expansion, first and second position coordinates for representing the target color region can be initialized. Specifically, the maximum position coordinate in the image to be detected and rendered can be determined as the first position coordinate; that is, the maximum x-coordinate of the image to be detected and rendered is configured as the x-coordinate of the first position coordinate, and the maximum y-coordinate of the image to be detected and rendered is configured as the y-coordinate of the first position coordinate. The minimum position coordinate in the image to be detected and rendered is determined as the second position coordinate; that is, the minimum x-coordinate of the image to be detected and rendered is configured as the x-coordinate of the second position coordinate, and the minimum y-coordinate of the image to be detected and rendered is configured as the y-coordinate of the second position coordinate. Here, the x-coordinate is the X-axis coordinate, and the y-coordinate is the Y-axis coordinate.
[0051] Step 1302: Construct an anisotropic extension vector based on the rate of change of color components between the evolution start node and its corresponding neighboring pixels.
[0052] For example, after determining the evolution starting node, the adjacent pixels of the evolution starting node in each specific expansion direction within a preset spatial neighborhood (e.g., a four-neighborhood or an eight-neighborhood) can be obtained. Each adjacent pixel corresponds to an independent spatial expansion direction (e.g., the four independent directions of up, down, left, and right corresponding to a four-neighborhood). Further, the color components of the evolution starting node and the color components of the adjacent pixels in each expansion direction are obtained. These color components may include red channel components, green channel components, blue channel components, and alpha channel components.
[0053] After acquiring the color components, for each expansion direction, the component differences between the evolution starting node and its adjacent pixels in that direction are calculated in the corresponding color channel. The component differences across all color channels are then aggregated (e.g., by summing the absolute values of the differences or summing the squares of the differences). The result of this aggregation is determined as the color component change rate of the evolution starting node in that expansion direction. That is, this color component change rate, as a scalar value, accurately reflects the overall color gradient or abrupt change in the multi-channel image data along the corresponding expansion direction.
[0054] After obtaining the color component change rates in each expansion direction, an anisotropic expansion vector can be constructed based on these rates. This anisotropic expansion vector is a vector composed of the expansion step sizes of the evolutionary starting node in each expansion direction. For example, for any expansion direction, the magnitude of the color component change rate in that direction can be configured to have an inverse proportional relationship or a negative correlation with the expansion step size in that direction (e.g., using an inverse proportional decay function or a negative exponential function for mapping). That is, when the color component change rate in a certain expansion direction is small, it indicates that the change amplitude of each color channel in that direction is small, and the color distribution is relatively smooth; a larger expansion step size can be configured for that direction. Conversely, when the color component change rate in a certain expansion direction is large, it indicates that at least some color channels in that direction experience color abrupt changes, approaching the physical boundary of the object; a smaller expansion step size can be configured for that direction. With the above configuration, the underlying color gradient features of multiple channels can be accurately converted into adaptive growth parameters based on the spatial expansion direction. This allows the search path guided by the anisotropic expansion vector to quickly traverse the target region with a large step size, while automatically shrinking to a smaller step size for fine detection when approaching the boundary of the target region.
[0055] Step 1303: Spatial expansion of the search path of the evolution starting node is performed using anisotropic expansion vectors, and the first position coordinates and the second position coordinates are updated based on the coordinates of pixels within the expansion path that meet the preset tolerance range.
[0056] For example, after constructing the anisotropic extension vector, the extension step sizes in each extension direction contained in the vector can be used to control the expansion of the search path from the evolution starting node to the surrounding space. Here, spatial expansion in any extension direction refers to traversing a corresponding number of pixel positions according to the extension step size corresponding to that direction, in order to locate candidate pixels on the extension path.
[0057] Furthermore, after locating a candidate pixel, the color matching value of the candidate pixel is obtained, and it is determined whether the matching value is within a preset tolerance range. If the matching value of the candidate pixel is within the preset tolerance range, the candidate pixel is determined as a valid pixel within the target color region; if the matching value of the candidate pixel exceeds the preset tolerance range, it indicates that the expansion in that direction has reached a boundary or fault, and the search path is stopped from continuing to expand in that direction.
[0058] After obtaining valid pixels within the extended path that meet the preset tolerance range, the first and second position coordinates can be updated based on the coordinates of these valid pixels. For example, the position coordinates of the valid pixel can be obtained. These position coordinates include the horizontal and vertical coordinates of the valid pixel in the image space. Further, the obtained horizontal and vertical coordinates are compared numerically with the current first and second position coordinates, and a boundary update operation is performed based on the comparison results. Specifically, the horizontal coordinates of the valid pixel can be compared with the horizontal coordinates of the current first position coordinates, and the smaller of the two values is determined as the updated horizontal coordinates of the first position coordinates. Similarly, the vertical coordinates of the valid pixel can be compared with the vertical coordinates of the current first position coordinates, and the smaller of the two values is determined as the updated vertical coordinates of the first position coordinates. The horizontal coordinates of the valid pixel can also be compared with the horizontal coordinates of the current second position coordinates, and the larger of the two values is determined as the updated horizontal coordinates of the second position coordinates. Likewise, the vertical coordinates of the valid pixel can be compared with the vertical coordinates of the current second position coordinates, and the larger of the two values is determined as the updated vertical coordinates of the second position coordinates. Through this configuration, as the search path expands outward based on the evolutionary starting node, the first and second position coordinates can be dynamically updated in real time following the appearance of each valid pixel, thereby accurately extracting the extreme boundary coordinates that completely encompass the target color region.
[0059] Step 1304: Determine the topological boundary range of the target color region based on the updated first and second position coordinates.
[0060] For example, after the spatial expansion of all search paths at the evolution starting node has ended, such as after all expansion paths in all directions have reached the boundary of the preset target color, the first and second position coordinates of the final updated position can be obtained.
[0061] Furthermore, a validity verification can be performed on the updated first and second position coordinates to confirm whether valid pixels constituting the target color region have been successfully obtained during the expansion process.
[0062] The specific logic for performing validity verification is as follows: extract the horizontal and vertical coordinate values of the updated first position coordinates, as well as the horizontal and vertical coordinate values of the updated second position coordinates; determine whether the horizontal coordinate value of the updated first position coordinates is less than the horizontal coordinate value of the updated second position coordinates, and determine whether the vertical coordinate value of the updated first position coordinates is less than the vertical coordinate value of the updated second position coordinates.
[0063] Furthermore, if the horizontal coordinate value of the updated first position coordinate is less than the horizontal coordinate value of the updated second position coordinate, and the vertical coordinate value of the updated first position coordinate is less than the vertical coordinate value of the updated second position coordinate, then the validity verification is deemed successful. This successful verification result indicates that the inverse extremum coordinates configured during the spatial expansion initialization phase have been rewritten by the real spatial coordinates of the valid pixels.
[0064] After the validity verification is passed, the topological boundary range of the target color region can be determined based on the verified first and second position coordinates. Specifically, the first position coordinate is determined as the minimum extreme point of the topological boundary range, and the second position coordinate is determined as the maximum extreme point of the boundary where the target color region is located. These first and second position coordinates together construct a closed rectangular region, which is then defined as the final topological boundary range completely enclosing the target color region. This method not only accurately converts pixel evolution results into intuitive geometric boundary data but also automatically intercepts and filters invalid initial coordinates that do not match the target color region through a built-in boundary validity verification mechanism, ensuring the reliability and accuracy of the final output region positioning data.
[0065] In the exemplary embodiments of this disclosure, anisotropic extension vectors are used to spatially extend the search path of the evolutionary starting node, such as... Figure 2 As shown, steps 210-230 are included: Step 210: Calculate the color component change rate of the evolution start node in multiple expansion directions, and determine the reciprocal of the change rate corresponding to each expansion direction as the step size modulation weight of each dimension.
[0066] For example, after determining the evolution start node, the adjacent pixels of the evolution start node in multiple expansion directions can be obtained. Further, for each expansion direction, the color components of the evolution start node and the color components of the adjacent pixels in that expansion direction are obtained, and the component differences between the evolution start node and the adjacent pixels in the corresponding color channel are calculated. Further, the component differences in each color channel are aggregated (e.g., the sum of the absolute values of the component differences in each color channel, or the sum of the squares of the component differences in each color channel), and the result of this aggregated calculation is determined as the color component change rate of the evolution start node in the corresponding expansion direction.
[0067] After obtaining the color component change rate in each expansion direction, the reciprocal of the corresponding color component change rate is calculated for each expansion direction. For example, to avoid the abnormal crash of division by zero when calculating the reciprocal (i.e., when the color of adjacent pixels is exactly the same as the evolution start node, resulting in a zero color component change rate), a preset very small bias constant (e.g., 0.001) can be added to the color component change rate value. Then, the constant 1 is divided by the sum, and the resulting reciprocal value is determined as the step size modulation weight for the corresponding dimension. That is, by calculating the reciprocal of the color component change rate, an inverse proportional mapping logic is established between the color component change rate and the step size modulation weight. When the color component change rate in a certain expansion direction is small, the calculated step size modulation weight is large; when the color component change rate in a certain expansion direction is large, the calculated step size modulation weight is small. Through the above configuration, the local color gradient data at the bottom layer of the image can be precisely quantified mathematically into a weight benchmark for scaling the spatial detection span, thereby providing reliable parameter support for subsequent derivation of specific step size gain or attenuation.
[0068] Step 220: Determine the step gain and step attenuation in each expansion direction based on the step size modulation weight.
[0069] For example, after obtaining the step size modulation weights for each expansion direction, a pre-configured baseline expansion step size can be obtained. Further, for each expansion direction, using the corresponding step size modulation weights, forward gain mapping calculations and reverse attenuation mapping calculations are performed to obtain the step size gain and step size attenuation for that expansion direction. The step size gain represents the pixel span value that can be additionally amplified based on the baseline expansion step size when the search path is within the target color region; the step size attenuation represents the reduction value of the baseline expansion step size due to compression penalty when the search path approaches the boundary of the target color region.
[0070] Furthermore, in the specific calculation process, the reference expansion step size can be multiplied with the step size modulation weight corresponding to the expansion direction, or a preset gain ratio coefficient can be introduced to perform a series multiplication, and the result is determined as the step size gain in that expansion direction. Simultaneously, a preset attenuation reference constant can be divided with the step size modulation weight corresponding to the expansion direction, or the step size modulation weight can be substituted into a preset negative exponential attenuation function, and the resulting ratio or function output value is determined as the step size attenuation in that expansion direction. That is, through the above configuration, based on the same underlying step size modulation weight, a pair of opposite and dynamically changing step size control parameters are derived for each specific expansion direction. When the step size modulation weight in a certain expansion direction is large, the step size gain obtained based on the multiplication mapping increases, while the step size attenuation obtained based on the division ratio / negative exponential attenuation function approaches zero; conversely, when the step size modulation weight is small, the step size gain is strongly suppressed, while the step size attenuation increases significantly. This parametric model based on single-weight bidirectional deconstruction transforms local image gradient data into a control force that pulls the step size, providing accurate data support for subsequent calculations of the final search distance.
[0071] Step 230: Control the expansion distance of the search path by step gain and step decay.
[0072] For example, after determining the step gain and step decay in each expansion direction, the pre-configured baseline expansion step can be comprehensively numerically corrected based on these two dynamic parameters, thereby calculating the actual expansion distance of the search path in each corresponding expansion direction.
[0073] Furthermore, for any expansion direction, the step size gain corresponding to that expansion direction is subtracted from the step size attenuation to obtain the expansion distance used to guide actual space exploration.
[0074] To avoid excessive step size decay due to drastic color changes in local areas, which could lead to search stalls or reverse search coordinates, resulting in an invalid step size of less than or equal to zero, a minimum step size boundary value (e.g., 1 pixel) can be preset. Further, the initial subtraction result is compared with the minimum step size boundary value, and the larger value is determined as the expansion distance in that expansion direction. After determining this expansion distance, it is used to indicate the single position offset of the search path in the current expansion direction, thereby controlling the search pointer to directly cross a number of pixels equal to the expansion distance value to locate the next candidate pixel to be detected.
[0075] With the above configuration, the actual expansion distance of the search path in each direction is no longer a fixed static constant, but a dynamic variable affected by the combined effects of gain and attenuation. When the search path is located in a target color region with smooth color, the large gain and near-zero attenuation lengthen the expansion distance, driving the search path to perform a leapfrog expansion and significantly eliminating repeated traversal of pixels of the same color. Conversely, when the search path approaches the boundary of the target color region, the suppressed gain and the sudden increase in attenuation take effect simultaneously, forcing the expansion distance to shrink to the minimum step size boundary value, thus switching to a pixel-by-pixel detection mode. This approach balances the efficiency of large-scale image search with the accuracy of physical edge localization.
[0076] In the exemplary implementation of this disclosure, during the process of controlling the expansion distance of the search path based on the step gain and the step decay, the actual physical distance traversed by the search path since its evolution starting node can be simultaneously accumulated and recorded, i.e., the cumulative expansion step length. Further, this cumulative expansion step length is compared in real time with a preset step length threshold, for example, a preset continuous extension of 20 pixel units. When the cumulative expansion step length of the search path reaches the preset step length threshold, a global verification mechanism to prevent color drift is triggered, and the latest pixel endpoint reached by the search path is determined as the current edge node.
[0077] Because relying solely on minute local differences between adjacent pixels for verification during the target color evolution process of an image can easily lead to cumulative color drift over long distances, meaning the current node's color may have deviated significantly from the starting node, but a smooth local transition can cause missed detections. Therefore, after triggering a global verification mechanism, the color deviation rate of the current edge node towards the evolution starting node is obtained.
[0078] Specifically, the calculation process of the color deviation rate may include: extracting the color components of the current edge node and the color components of the evolution start node, and calculating the feature difference value between the two in each corresponding color channel; at the same time, obtaining the straight-line distance between the current edge node and the evolution start node in the two-dimensional space of the image; then, performing a ratio calculation between the feature difference value and the absolute straight-line distance to obtain the color deviation rate between the two points.
[0079] Furthermore, the calculated color deviation rate is numerically compared with the pre-configured preset coherence range for verification. If the color deviation rate is within the preset coherence range, it is determined that although the color of the current edge node has undergone long-distance spatial expansion, it still maintains a high degree of consistency with the color of the initial evolution starting node. At this time, the extension evolution direction of the current search path is determined to be valid, and the current edge node and the corresponding candidate pixels on the current search path are officially determined as the constituent pixels of the target color region, while allowing the search path to continue to expand outward based on this.
[0080] By employing the above method, a distance threshold-based verification mechanism is added on top of the dynamic step-size expansion logic. The algorithm does not need to perform global feature comparison at every pixel step; instead, it only performs a confirmation based on the color deviation rate when the cumulative expansion reaches a specific distance node. This approach ensures high execution efficiency in the evolutionary search of large-area connected regions while preventing the potential for overgrowth caused by local lighting variations, thus improving the accuracy and robustness of target color extremum extraction.
[0081] Furthermore, if the color deviation rate is not within the preset coherence range, the current search path is determined to be invalid, and the expansion of the search path in the current direction is stopped.
[0082] For example, after triggering the global verification mechanism and calculating the color deviation rate, if it is determined that the color deviation rate does not fall within the pre-configured preset coherence range, it indicates that the leading edge node has undergone substantial color shift relative to the evolution starting node (i.e., cumulative color drift has occurred). This shift typically indicates that the search path has deviated from the core feature range of the target color during the evolution process and entered the background area affected by external light and shadow gradients, diffuse reflection interference, or material transitions.
[0083] Furthermore, if the current search path is determined to be invalid, a path blocking operation will be performed. Specifically, the current edge node and the candidate pixels it crosses in the current verification cycle will no longer be identified as constituent pixels of the target color region; at the same time, further evolution and detection of the search path in the current expansion direction will be stopped, thereby decisively preventing erroneous overflow of the search range into non-target color regions.
[0084] Through the aforementioned exclusion and blocking logic targeting color deviation rate, an automatic correction and circuit breaker mechanism is established. When the underlying local detection logic blindly expands due to minor differences between adjacent pixels, comparison with the macroscopic features of the evolution starting node ensures that the effective pixels extracted by the algorithm and the final updated position coordinate boundaries always contain the true target color region, avoiding the problem of over-expansion of regions in complex lighting environments.
[0085] In the example implementation of this disclosure, the color region detection method for Unreal Engine can be encapsulated as a custom callable node in the Unreal Engine Blueprint system, forming a black-box operation. Only the input pins for receiving the rendering target instance and preset tolerance, and the output pins for returning the validity boolean value and the final target color region are exposed. This encapsulation configuration allows users to directly call the algorithm in the Blueprint diagram by dragging and dropping lines, lowering the technical threshold for engine-level image analysis and decoupling the underlying high-frequency computing power from the upper-level game business logic. In the example implementation of this disclosure, after verifying an anomaly or blocking the execution path, an anomaly capture mechanism is triggered. Pre-configured log macro instructions (e.g., UE_LOG) are used to extract the current anomaly status data, which is then formatted and injected into the engine-level log stream. Furthermore, the name of the rendering target that caused the anomaly, the specific reason for the failure (e.g., lack of CPU read permissions or missing pixel channels), and the code execution point information where the anomaly occurred are encapsulated into a formatted string with a specific tracking identifier (e.g., Warning or Error level), and this string is pushed to the Unreal Engine's global log system and developer output console in real time. By coupling with the underlying logging system of UE5, errors can be safely blocked, and clear and accurate diagnostic clues can be left in the packaged log files. This reduces the time cost for technicians to troubleshoot color rendering loss or detection failure bugs in complex rendering pipelines, making this technical solution valuable for engineering operation and maintenance and debugging.
[0086] like Figure 3 As shown, Figure 3 This is a block diagram illustrating a color region detection apparatus for Unreal Engine according to an exemplary embodiment of the present disclosure. The apparatus includes: an acquisition module 310, a calculation module 320, and a processing module 330. The acquisition module 310 is used to acquire the pixel data, preset target color, and preset tolerance range of the image to be detected and rendered.
[0087] The calculation module 320 is used to calculate a brightness compensation factor based on the perceived brightness of each pixel in the pixel data and the brightness deviation of the preset target color, and to use the brightness compensation factor to perform weighted correction on each pixel in the pixel data and the preset target color to obtain the matching value of each pixel.
[0088] The processing module 330 is used to perform spatial expansion processing with the pixels whose matching values are within the preset tolerance range as the evolution starting nodes to obtain the target color region corresponding to the preset target color.
[0089] It should be noted that the color region detection device for Unreal Engine in this embodiment is used to implement the corresponding color region detection method for Unreal Engine in the aforementioned method embodiment, and has the beneficial effects of the corresponding method embodiment, which will not be repeated here.
[0090] The embodiments of the color region detection device for Unreal Engine disclosed herein can be applied to computer devices, such as servers or terminal devices. The device embodiments can be implemented in software, hardware, or a combination of both. Taking software implementation as an example, as a logical device, it is formed by the processor reading the corresponding computer program instructions from non-volatile memory into memory for execution. From a hardware perspective, such as... Figure 4 The diagram shown is a hardware structure diagram of a computer device used for a color region detection device in Unreal Engine, according to an embodiment of this disclosure. Except for... Figure 4 In addition to the processor 410, memory 430, network interface 420, and non-volatile memory 440 shown, the server or electronic device used for the color region detection device of Unreal Engine in the embodiment may also include other hardware depending on the actual function of the computer device, which will not be described in detail here.
[0091] The specific implementation process of the functions and roles of each module in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0092] In one example embodiment of this disclosure, a computer-readable storage medium is also provided, on which a program product 500 capable of implementing the methods described above is stored. In some possible embodiments, various aspects of this disclosure may also be implemented as a program product including program code that, when the program product is run on a terminal device, causes the terminal device to perform the steps described in the "Exemplary Methods" section of this specification according to various exemplary embodiments of this disclosure.
[0093] In this disclosure, the terms "first" and "second" are used for description only and do not indicate relative importance or imply the number of technical features. Therefore, the features referred to as "first" or "second" may explicitly or implicitly include at least one of those features. "A plurality of" means at least two, unless otherwise expressly defined.
[0094] From the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this disclosure can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, external hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, touch terminal, or network device, etc.) to execute the methods according to the embodiments of this disclosure.
[0095] Finally, the above preferred embodiments are only used to illustrate the technical solutions of this disclosure and are not restrictive. Although this disclosure has been described in detail, those skilled in the art should understand that changes in form and detail can be made without departing from the scope defined by the claims of this disclosure. The dimensions in the drawings are not related to the specific physical object, and the physical object dimensions can be arbitrarily changed.
Claims
1. A method for color region detection in Unreal Engine, characterized in that, The method includes: Obtain the pixel data, preset target color, and preset tolerance range of the image to be rendered; A brightness compensation factor is calculated based on the perceived brightness of each pixel in the pixel data and the brightness deviation of the preset target color. The brightness compensation factor is then used to perform a weighted correction on each pixel in the pixel data and the preset target color to obtain the matching value of each pixel. Using the pixels whose matching values are within the preset tolerance range as the starting nodes for evolution, spatial expansion processing is performed to obtain the target color region corresponding to the preset target color. The step of calculating the brightness compensation factor based on the difference between the perceived brightness of each pixel in the pixel data and the brightness of the preset target color includes: The red, green, and blue channel values of each pixel in the pixel data are weighted according to a preset perception weight to obtain the perceived brightness value of each pixel; the absolute difference between the perceived brightness value of each pixel and the brightness reference value of the preset target color is calculated; the product of the preset sensitivity coefficient and the absolute difference is calculated, and the sum of the product and the preset threshold is determined as the brightness perception attenuation coefficient; the ratio of the preset constant to the brightness perception attenuation coefficient is determined as the brightness compensation factor. The step of performing spatial expansion processing using pixels whose matching values are within the preset tolerance range as the starting nodes to obtain the target color region corresponding to the preset target color includes: The maximum position coordinate in the image to be detected is determined as the first position coordinate, and the minimum position coordinate in the image to be detected is determined as the second position coordinate. An anisotropic extension vector is constructed based on the color component change rate between the evolution starting node and its corresponding adjacent pixels. The search path of the evolution starting node is spatially extended using the anisotropic extension vector, and the first position coordinate and the second position coordinate are updated based on the coordinates of the effective pixels within the extended path that satisfy the preset tolerance range. The topological boundary range of the target color region is determined based on the updated first position coordinate and second position coordinate. The spatial expansion of the search path for the evolutionary starting node using the anisotropic extension vector includes: Calculate the color component change rate of the evolution starting node in multiple expansion directions, and determine the reciprocal of the change rate corresponding to each expansion direction as the step size modulation weight for each dimension; determine the step size gain and step size decay in each expansion direction based on the step size modulation weight; control the expansion distance of the search path through the step size gain and the step size decay.
2. The method according to claim 1, characterized in that, The step of using the brightness compensation factor to weight and correct each pixel in the pixel data with the preset target color to obtain the matching value of each pixel includes: The original squared distance value of each pixel is obtained by performing a summation operation on the component differences between each pixel and the preset target color in the red channel, green channel, blue channel and transparency channel; The product of the original squared distance value and the brightness compensation factor is determined as the matching value for each pixel.
3. The method according to claim 1, characterized in that, The method of controlling the expansion distance of the search path through the step size gain and the step size decay also includes: When the cumulative expansion step size of the search path reaches the preset step size threshold, the color deviation rate of the current edge node towards the evolution starting node is obtained. If the color deviation rate is within the preset coherence range, the current search path is determined to be valid, and the corresponding pixel is determined as a component pixel of the target color region.
4. The method according to claim 1, characterized in that, The step of updating the first position coordinates and the second position coordinates based on the coordinates of valid pixels within the extended path that satisfy the preset tolerance range further includes: For each valid pixel within the extended path that satisfies the preset tolerance range, obtain the horizontal and vertical coordinate values of the valid pixel. The smaller value between the horizontal coordinate value of the effective pixel and the horizontal coordinate value of the first position coordinate is determined as the updated horizontal coordinate value of the first position coordinate. The smaller value between the vertical coordinate value of the effective pixel and the current vertical coordinate value of the first position coordinate is determined as the updated vertical coordinate value of the first position coordinate. The larger value between the horizontal coordinate value of the effective pixel and the current horizontal coordinate value of the second position is determined as the updated horizontal coordinate value of the second position. The larger value between the vertical coordinate value of the effective pixel and the current vertical coordinate value of the second position coordinate is determined as the updated vertical coordinate value of the second position coordinate.
5. The method according to claim 1, characterized in that, Determining the topological boundary range of the target color region based on the updated first and second position coordinates includes: If the horizontal coordinate value of the updated first position coordinate is less than the horizontal coordinate value of the updated second position coordinate, and the vertical coordinate value of the updated first position coordinate is less than the vertical coordinate value of the updated second position coordinate, then the target color region is determined based on the updated first position coordinate and the updated second position coordinate.
6. A color region detection device for Unreal Engine, used to implement the method as described in any one of claims 1 to 5, characterized in that, The device includes: The acquisition module is used to acquire the pixel data, preset target color, and preset tolerance range of the image to be detected and rendered; The calculation module is used to calculate a brightness compensation factor based on the perceived brightness of each pixel in the pixel data and the brightness deviation of the preset target color, and to use the brightness compensation factor to perform weighted correction on each pixel in the pixel data and the preset target color to obtain the matching value of each pixel. The processing module is used to perform spatial expansion processing on pixels whose matching values are within the preset tolerance range as evolution starting nodes to obtain a target color region corresponding to the preset target color.
7. A computer device, characterized in that, The method includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, implements the method as described in any one of claims 1-5.
Citation Information
Patent Citations
New energy battery coating thickness control method
CN120031789A
Mobile metering calibration method, device and equipment for mine remediation pollutants and medium
CN122109016A