Laboratory animal identity recognition method and system based on image recognition

By combining frequency domain decomposition and a bi-branch diffusion network structure with attention mechanism and momentum update, the confusion problem of animal identification in laboratory environment is solved, and the fusion processing of high-frequency details and low-frequency contour features is realized, thereby improving the accuracy and consistency of identification.

CN120126172BActive Publication Date: 2026-06-09法洛思科技(深圳)有限公司

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
法洛思科技(深圳)有限公司
Filing Date
2025-02-19
Publication Date
2026-06-09

Smart Images

  • Figure CN120126172B_ABST
    Figure CN120126172B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of image recognition, and discloses a laboratory animal identity recognition method and system based on image recognition, which comprises the following steps: pre-processing animal motion image sequences collected by a high-speed camera in a laboratory to obtain target animal image data; performing two-dimensional discrete Fourier transform and inverse Fourier transform to obtain animal image high-frequency feature data and animal image low-frequency feature data; inputting the data into a double-branch diffusion network respectively for feature processing to obtain fused animal feature data; constructing a positive sample pair, constructing a negative sample pair through difficult sample mining, calculating a feature distance based on cosine similarity and performing momentum updating to obtain an animal identity feature template; and based on the double-branch diffusion network and the animal identity feature template, performing feature extraction and similarity calculation on real-time animal image sequences to obtain animal identity data; the application improves the distinguishing ability of identity features and enhances the time sequence consistency of identity recognition results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image recognition technology, and in particular to a method and system for identifying laboratory animals based on image recognition. Background Technology

[0002] In laboratory animal behavior analysis research, accurately identifying and tracking multiple animals is crucial for understanding their social behavior and movement patterns. Traditional animal behavior analysis methods mainly rely on manual observation and tagging, which is not only time-consuming and labor-intensive but also easily influenced by subjective factors, making it difficult to obtain accurate behavioral data. With the development of computer vision technology, image processing-based animal behavior analysis methods have gradually become a research hotspot, but they still face many challenges in practical applications.

[0003] Current image recognition-based animal identification methods suffer from two main problems: first, identification confusion easily occurs when animals are moving rapidly or occluding each other, leading to inaccurate tracking results; second, existing methods often only focus on the overall features of the image, ignoring the detailed information contained in different frequency components, making it difficult to effectively distinguish individuals with similar appearances. Especially in laboratory environments, due to factors such as high animal appearance similarity, fast movement speed, and large group size, traditional identification methods are insufficient to meet research needs. Summary of the Invention

[0004] This invention provides a laboratory animal identification method and system based on image recognition. This invention improves the ability to distinguish identity features and enhances the temporal consistency of identification results.

[0005] In a first aspect, the present invention provides a laboratory animal identification method based on image recognition, the laboratory animal identification method based on image recognition comprising:

[0006] Preprocessing is performed on animal motion image sequences captured by high-speed cameras in the laboratory to obtain target animal image data;

[0007] Perform two-dimensional discrete Fourier transform and inverse Fourier transform on the target animal image data to obtain high-frequency feature data and low-frequency feature data of the animal images;

[0008] The high-frequency feature data and low-frequency feature data of the animal images are respectively input into a dual-branch diffusion network for feature processing to obtain fused animal feature data.

[0009] Positive sample pairs are constructed based on the fused animal feature data, negative sample pairs are constructed through hard sample mining, feature distance is calculated based on cosine similarity and momentum is updated to obtain animal identity feature templates;

[0010] Based on the dual-branch diffusion network and the animal identity feature template, feature extraction and similarity calculation are performed on real-time animal image sequences to obtain animal identity data.

[0011] Secondly, the present invention provides a laboratory animal identification system based on image recognition, the laboratory animal identification system based on image recognition comprising:

[0012] The preprocessing module is used to preprocess the animal motion image sequences acquired by high-speed cameras in the laboratory to obtain target animal image data;

[0013] The transformation module is used to perform two-dimensional discrete Fourier transform and inverse Fourier transform on the target animal image data to obtain high-frequency feature data and low-frequency feature data of the animal image.

[0014] The feature processing module is used to input the high-frequency feature data and low-frequency feature data of the animal image into a dual-branch diffusion network for feature processing to obtain fused animal feature data.

[0015] The construction module is used to construct positive sample pairs based on the fused animal feature data, construct negative sample pairs through hard sample mining, calculate feature distance based on cosine similarity and perform momentum update to obtain animal identity feature templates;

[0016] The calculation module is used to extract features and calculate similarity from real-time animal image sequences based on the dual-branch diffusion network and the animal identity feature template to obtain animal identity data.

[0017] A third aspect of the present invention provides a computer device, comprising: a memory and at least one processor, wherein the memory stores instructions; the at least one processor invokes the instructions in the memory to cause the computer device to perform the above-described image recognition-based laboratory animal identification method.

[0018] A fourth aspect of the present invention provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the above-described image recognition-based laboratory animal identification method.

[0019] The technical solution provided by this invention introduces frequency domain decomposition and a dual-branch diffusion network structure to achieve separate extraction and fusion processing of high-frequency detail features and low-frequency contour features of animal images, thereby improving the distinguishability of identity features. Attention mechanisms and residual structures are used for feature interaction and enhancement, effectively capturing the correlation between features in different frequency domains and enhancing the robustness of feature representation. A feature learning strategy based on contrastive learning is designed, which improves the model's ability to distinguish similar individuals by constructing positive and negative sample pairs and mining hard samples. By introducing a momentum update mechanism, dynamic updates of feature templates are achieved, enabling the model to adapt to subtle changes in animal appearance. Combining Kalman filter prediction and Hungarian algorithm matching effectively solves the problem of trajectory breakage under conditions of rapid animal movement and occlusion. A multi-level feature fusion and spatiotemporal information association strategy is adopted to enhance the temporal consistency of identity recognition results. Attached Figure Description

[0020] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0021] Figure 1 This is a schematic diagram illustrating the steps of the laboratory animal identification method based on image recognition in an embodiment of the present invention;

[0022] Figure 2 This is a schematic diagram of the structure of a laboratory animal identification system based on image recognition in an embodiment of the present invention;

[0023] Figure 3 This is a schematic block diagram of the structure of the computer device in an embodiment of the present invention. Detailed Implementation

[0024] This invention provides a method and system for identifying laboratory animals based on image recognition. The terms "first," "second," "third," "fourth," etc. (if present) in the specification, claims, and accompanying drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" or "having" and any variations thereof are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0025] For ease of understanding, the specific process of the embodiments of the present invention is described below. Please refer to [link / reference]. Figure 1 One embodiment of the laboratory animal identification method based on image recognition in this invention includes:

[0026] Step S1: Preprocess the animal motion image sequence acquired by the high-speed camera in the laboratory to obtain the target animal image data;

[0027] It is understood that the executing entity of this invention can be a laboratory animal identification system based on image recognition, or it can be a terminal or a server; no specific limitation is made here. This embodiment of the invention will be described using a server as an example.

[0028] Specifically, RGB channels of animal motion image sequences captured by high-speed cameras in the laboratory are separated to extract independent information from each channel, shifting the image processing from a holistic approach to a more refined color dimension analysis. This separation helps reduce color interference caused by channel overlap. Simultaneously, pixel normalization mapping is performed on each separated channel. By readjusting pixel values ​​to the range of 0 to 1, the computability and consistency of the image are enhanced, eliminating amplitude differences introduced by different acquisition devices or lighting conditions, resulting in normalized animal image data. Pixel variance is calculated for local regions of the normalized animal image data to assess the degree of grayscale variation in local image areas. Pixel variance calculation reflects the detail complexity of the image; this statistical method can identify areas rich in detail and relatively flat areas in the image. Based on this variance information, adaptive smoothing intensity adjustment is implemented. This process effectively reduces noise interference in the image by preserving more detail in high-variance areas while smoothing low-variance areas, maintaining the clarity of key feature regions, generating denoised animal image data. A cumulative grayscale histogram is generated using the denoised animal image data. The cumulative gray-level histogram provides information on the distribution of gray-level values ​​in an image, reflecting its overall brightness and contrast characteristics. Based on this histogram, a piecewise linear transformation is used to adjust the gray-level distribution, thereby redistributing the image's contrast range. Contrast distribution adjustment aims to highlight key feature regions in the image, weaken redundant background information, and improve the image's visual effect and the effectiveness of feature extraction. This step generates contrast-enhanced animal image data. Multi-scale adaptive thresholding is then performed on the enhanced animal image data. Using image information at different scales, the animal's contour region is identified and segmented by dynamically adjusting the threshold, generating initial mask data. The initial mask data is then optimized. Through cascaded dilation and erosion operations, mask boundaries are corrected, isolated noise points are removed, and the contour of the target region is smoother. Dilation connects broken boundaries, while erosion helps eliminate small-area artifacts introduced during the expansion process, resulting in target mask data. Based on the target mask data, region localization is performed in the enhanced animal image data, effectively isolating the target region of the animal and eliminating interference from non-target regions, resulting in localized image data. Bilinear interpolation is performed on the localized image data to uniformly adjust the localized target region to a standardized size, generating normalized image data. The normalized image data is then combined with the target mask data using a pixel-cascaded structure. By integrating the mask and image information into a single data structure, subsequent processing utilizes both the pixel information of the target region and the spatial constraint information of the mask to generate the target animal image data.

[0029] Step S2: Perform two-dimensional discrete Fourier transform and inverse Fourier transform on the target animal image data to obtain high-frequency feature data and low-frequency feature data of the animal image.

[0030] Specifically, frequency domain transformation is performed on the target animal image data, using a two-dimensional discrete Fourier transform to convert the image from a time-domain representation to a frequency-domain representation. The spatial features of the original image pixel data are decomposed into a set of sinusoidal components with different frequencies and directions, revealing the frequency features contained in the image. A centering translation operation is performed on the initial frequency distribution. By shifting the frequency zero point from the upper left corner of the matrix to the center of the spectrum, the low-frequency components are more intuitively represented as being located in the central region, with high-frequency components surrounding them, resulting in centered spectrum data. Complex number operations are performed on the centered spectrum data to extract the real and imaginary parts of the frequency domain data, and the square root of the sum of their squares is calculated to generate a frequency domain amplitude matrix. Simultaneously, the phase angle of the frequency components is calculated using the arctangent function, resulting in a phase matrix. These two matrices describe the amplitude and phase information in the frequency domain, respectively. The frequency domain amplitude matrix reflects the intensity distribution of different frequency components in the image, while the phase matrix captures the spatial relationships of these frequency components. A frequency distribution histogram is established using the frequency domain amplitude matrix, thereby enabling statistical analysis of the energy distribution of the frequency components. A frequency distribution histogram, with frequency on the horizontal axis and frequency domain amplitude on the vertical axis, displays the spectral energy distribution characteristics of the target image. Based on this, frequency domain energy density distribution data is obtained through integration or weighted calculation, quantifying the ratio of high-frequency and low-frequency energy in the target image. Based on the frequency domain energy distribution data, the frequency domain amplitude matrix is ​​multiplied by a high-pass filter. The high-pass filter extracts detail information and edge features in the image by suppressing low-frequency components and preserving high-frequency components. The high-pass amplitude matrix is ​​then recombinated with the corresponding phase matrix to generate high-frequency sub-spectral data. Similarly, to extract low-frequency features, the frequency domain amplitude matrix is ​​multiplied by a low-pass filter. The low-pass filter preserves low-frequency components and suppresses high-frequency components, extracting the global contour and overall information of the image. The low-pass amplitude matrix is ​​then recombinated with the phase matrix to generate low-frequency sub-spectral data. A two-dimensional inverse discrete Fourier transform is performed on both the high-frequency and low-frequency sub-spectral data to transform them back from the frequency domain to the time domain. The inverse transform of the high-frequency sub-spectrum generates a high-frequency feature image that preserves detailed features of the target animal image, including fur texture, edges, and local contrast, making it suitable for high-resolution feature extraction. Conversely, the inverse transform of the low-frequency sub-spectrum generates a low-frequency feature image containing low-resolution features such as animal shape, outline, and overall structure.

[0031] Step S3: Input the high-frequency feature data and low-frequency feature data of animal images into a dual-branch diffusion network for feature processing to obtain fused animal feature data;

[0032] Specifically, high-frequency feature data from animal images is input into the high-frequency branch of a dual-branch diffusion network to capture rich details and local texture features. Through feature dimension mapping, the original feature dimensions of the high-frequency feature data are transformed into the latent space representation required by the network. This adjustment of feature dimensions allows the data to adapt to the subsequent hierarchical feature extraction module. During hierarchical feature extraction, the network extracts abstract representations of high-frequency features layer by layer, progressively summarizing edge textures and detailed structures into higher-order semantic information, generating high-frequency feature latent space data. Simultaneously, low-frequency feature data from animal images is input into the low-frequency branch of the dual-branch diffusion network. This branch is designed to extract global contour and overall structural information from low-frequency features. Similarly, through feature dimension mapping, the low-frequency feature data is normalized into a latent space representation suitable for network processing. In the hierarchical feature extraction module of the low-frequency branch, the network uses multi-layer feature transformation to progressively elevate the macroscopic shape information in the low-frequency data into latent space features with higher-level expressions, generating low-frequency feature latent space data. A first attention mapping matrix is ​​constructed based on the high-frequency and low-frequency feature latent space data. This attention mapping matrix captures cross-branch correlations between high-frequency and low-frequency features. The attention mechanism dynamically adjusts the importance of different features by calculating correlation weights between features, resulting in feature interaction data. This feature interaction data is then input into a group of residual convolutional layers in a dual-branch diffusion network. The residual convolutional layer group consists of multiple residual units, each including convolution operations and feature stacking operations. In each residual unit, features are processed by convolution kernels to extract local patterns, which are then stacked with the input features after skip connections, thus mitigating the gradient vanishing problem in deep networks while preserving information from shallow features. After processing by multiple residual units, residual feature data is generated. This residual feature data is then input into the self-attention module of the dual-branch diffusion network. The self-attention module recalibrates the features by reallocating the weights of the feature channels. During this process, the network dynamically adjusts the contribution weight of each channel according to task requirements, thereby highlighting the most discriminative features and obtaining channel attention feature data. Based on the channel attention feature data, spatial attention weights are allocated to capture the importance of different spatial locations in the image, generating spatial attention feature data. Cross-layer feature aggregation is performed on channel attention feature data and spatial attention feature data. By integrating and weighting features from different levels, the comprehensiveness and consistency of feature representation are ensured. Through global feature aggregation, all feature information is compressed and refined to generate the final fused animal feature data.

[0033] Step S4: Construct positive sample pairs based on fused animal feature data, construct negative sample pairs through hard sample mining, calculate feature distance based on cosine similarity and perform momentum update to obtain animal identity feature templates;

[0034] Specifically, based on fused animal feature data, data augmentation techniques are used to process the feature data of the same animal over consecutive time periods. This process includes random cropping, rotation, and flipping transformations. These operations can simulate image changes under different acquisition conditions, expand the diversity of positive samples, and increase the model's generalization ability, generating positive sample feature data. Euclidean distance is calculated for the features of different animal individuals in the fused animal feature data to quantify the similarity between different identity features, and the results are represented as feature distance ranking data. Through this ranking, the top N different identity feature pairs with the smallest distance are identified. These feature pairs are usually difficult to distinguish and are selected as hard samples. For these hard samples, feature alignment is performed. By uniformly processing the sample features in scale and direction, negative sample feature data is obtained, reflecting the similarity features between different identities, while improving the ability to distinguish hard samples. L2 norm normalization is applied to the positive and negative sample feature data to standardize the length of the feature vectors, and cosine similarity between sample pairs is calculated through inner product operations. Cosine similarity is an indicator that measures the directional similarity between two feature vectors. Cosine similarity data is weighted by a temperature coefficient, which controls the sensitivity of feature distribution and thus adjusts the dynamic range of similarity. Based on the weighted cosine similarity, the contrastive loss value between positive and negative sample pairs is calculated, yielding the contrastive learning loss data. The contrastive loss optimizes feature representation and improves the model's performance in distinguishing different identities by narrowing the distance between positive sample pairs and widening the distance between negative sample pairs. To enhance the dynamic adaptability of positive sample feature data, an exponential moving average is applied to the contrastive learning loss data. The exponential moving average method smooths fluctuations in positive sample feature data while preserving the trend of feature changes by weighting historical and current features. A momentum coefficient is set to control the update amplitude; the choice of momentum coefficient directly affects the flexibility and stability of feature updates, generating dynamic feature update data. Based on the dynamic feature update data, centroid calculation and feature aggregation operations are performed on the feature vector of each animal identity. Centroid calculation, through weighted averaging of all sample features, yields cluster center feature data that represents the overall characteristics of that identity. These cluster center features effectively eliminate noise and outlier interference through aggregation, thus more stably and accurately representing the feature vector of each animal identity. The feature index and cluster center feature vector corresponding to each animal identity are organized in the form of key-value pairs to generate an animal identity feature template.

[0035] Step S5: Based on the dual-branch diffusion network and animal identity feature template, perform feature extraction and similarity calculation on the real-time animal image sequence to obtain animal identity data.

[0036] Specifically, a two-dimensional discrete Fourier transform is performed on real-time animal image sequences to convert the images from the time domain to the frequency domain, allowing for the analysis of information contained in different frequency components. After the transform, the frequency domain data undergoes spectral separation, decomposing it into high-frequency and low-frequency components, from which real-time high-frequency and low-frequency feature data are extracted respectively. High-frequency data contains detailed information about the image, such as texture and edges, while low-frequency data reflects the overall structure and contours of the image. The real-time high-frequency feature data is input into the high-frequency branch of a dual-branch diffusion network, where feature dimension mapping converts the original features into a latent space representation for the adaptive network. In the hierarchical feature extraction module of the high-frequency branch, semantic information of the high-frequency features is extracted through layer-by-layer convolution and dimensionality reduction operations, gradually abstracting from details to the whole to generate real-time high-frequency latent space data. Similarly, real-time low-frequency feature data is input into the low-frequency branch of the dual-branch diffusion network, where feature dimension mapping and hierarchical feature extraction processes generate real-time low-frequency latent space data. The low-frequency branch is designed to capture the global structural information of the image to supplement the deficiencies of local features in the high-frequency branch, thereby ensuring the completeness and diversity of the overall feature extraction. A second attention mapping matrix is ​​constructed using real-time high-frequency and low-frequency latent space data. The correlation weights between latent space data are calculated through an attention mechanism to dynamically adjust the importance of features, fusing high-frequency and low-frequency features into real-time feature interaction data through cross-branch association calculations. This real-time feature interaction data is then input into the residual convolutional layers and self-attention module of a dual-branch diffusing network. The residual convolutional layers extract features through the stacking of multiple residual units, while retaining shallow information through a skip connection mechanism, generating a more robust feature representation. The self-attention module recalibrates the features, dynamically adjusting the importance of each feature dimension, enabling the network to adaptively optimize feature representation based on changes in real-time input, resulting in real-time fused feature data. Based on the feature index and feature vector in the animal identity feature template, the real-time fused feature data is L2-norm normalized to ensure a uniform scale for the feature vectors. The normalized real-time feature data is then used to calculate similarity with the feature vectors in the feature template through inner product operations, generating identity similarity data that reflects the degree of matching between the real-time input features and each identity feature in the template. After similarity calculation, a matching threshold is set for identity determination. By comparing the real-time features with a threshold, it is determined whether they match a certain identity feature in the template, generating identity determination result data. If the similarity exceeds the set threshold, it is considered a successful match; otherwise, it is considered an unmatched identity. To improve the system's usability, the identity determination result data is associated with the spatiotemporal information of the corresponding image frame. The recognition result of each image frame is associated with its capture time and spatial location, generating animal identity data containing spatiotemporal information.

[0037] Animal identification data is sampled temporally. By analyzing identification data in consecutive frames, the temporal motion characteristics of each target animal are extracted, including key parameters such as position, velocity, and acceleration, generating target motion state data. The target motion state data is initialized with a covariance matrix, which describes the correlation between system state variables and reflects the randomness of the motion process by setting process noise parameters. Simultaneously, a state transition matrix is ​​constructed to describe the evolution of the target animal from its current state to the next time step, and Kalman filter initialization data is generated based on these parameters. After Kalman filter initialization, the iterative prediction stage begins. Based on the Kalman filter initialization data, the target state is predicted, generating estimated values ​​for predicted position and motion state. Simultaneously, real-time observation data is used to correct the prediction results, adjusting for errors caused by process noise or inaccurate models. In each iteration, the estimated target state is continuously optimized by fusing prediction and observation data, generating target state prediction data. The iterative characteristics of the Kalman filter enable it to achieve smooth prediction of target motion in noisy environments and dynamically adapt to changes in target motion. The target state prediction data is matched with the detection results of the current frame. The Euclidean distance of each target is calculated using its position coordinates to quantify their spatial proximity. Simultaneously, the angle between the motion directions of the targets is calculated by combining motion direction information. These calculations are used to generate a target similarity matrix, where each element reflects the matching probability between different targets. Based on this, to determine trajectory allocation, a cost matrix for the Hungarian algorithm is constructed based on the target similarity matrix. The row and column elements of the cost matrix are normalized to ensure the numerical stability of the algorithm. The normalized cost matrix is ​​used to execute the Hungarian algorithm, which solves the target-trajectory allocation problem using the bipartite graph maximum matching method, generating trajectory matching index data. Trajectory break detection is performed on the trajectory matching index data to identify trajectory interruptions caused by brief occlusion, target loss, or detection failure. For broken trajectories, interpolation is performed using motion state prediction data to complete the trajectory. By analyzing the motion trends of the trajectory before and after the break, missing intermediate trajectory points are estimated and supplemented to generate a complete trajectory sequence. The complete trajectory sequence is mapped to the spatiotemporal correspondence with animal identification data. Each trajectory segment is combined with its corresponding animal identification tag to generate motion trajectory data with animal identification tags, which describes the movement pattern of the target animal in both spatial and temporal dimensions.

[0038] In this embodiment of the invention, by introducing frequency domain decomposition and a dual-branch diffusion network structure, the high-frequency detail features and low-frequency contour features of animal images are extracted and fused separately, improving the distinguishability of identity features. Attention mechanisms and residual structures are used for feature interaction and enhancement, effectively capturing the correlation between features in different frequency domains and enhancing the robustness of feature representation. A feature learning strategy based on contrastive learning is designed, improving the model's ability to distinguish similar individuals by constructing positive and negative sample pairs and mining hard samples. By introducing a momentum update mechanism, dynamic updates of feature templates are achieved, enabling the model to adapt to minor changes in animal appearance. Combining Kalman filter prediction and Hungarian algorithm matching effectively solves the problem of trajectory breakage under conditions of rapid animal movement and occlusion. A multi-level feature fusion and spatiotemporal information association strategy is employed to enhance the temporal consistency of identity recognition results.

[0039] In one specific embodiment, the process of performing step S1 may specifically include the following steps:

[0040] RGB channel separation and pixel normalization mapping were performed on animal motion image sequences captured by high-speed cameras in the laboratory to obtain normalized animal image data.

[0041] Local region pixel variance calculation and adaptive smoothing intensity adjustment are performed on normalized animal image data to obtain denoised animal image data;

[0042] An enhanced animal image data is obtained by generating a cumulative grayscale histogram based on denoised animal image data and adjusting the image contrast distribution through piecewise linear transformation.

[0043] Multi-scale adaptive threshold segmentation is performed on the enhanced animal image data to obtain initial mask data, and dilation and erosion cascade operations are performed on the initial mask data to obtain target mask data;

[0044] Based on the target mask data, region localization is performed in the enhanced animal image data to obtain localized image data. Then, bilinear interpolation is performed on the localized image data to obtain normalized size image data.

[0045] Normalized size image data and target mask data are combined in a pixel-cascaded structure to generate target animal image data.

[0046] Specifically, the acquired image sequence undergoes RGB channel separation, decomposing the three-channel color information of the image into a red channel R(i,j), a green channel G(i,j), and a blue channel B(i,j), where i,j represent the two-dimensional position index of the image pixel. The pixel values ​​of each channel are then normalized using the formula:

[0047]

[0048] Normalization is performed, where I(i,j) represents the pixel value, I min and I max These are the minimum and maximum values ​​of the channel, respectively, and I′(i,j) is the normalized pixel value. The purpose of normalization is to adjust the pixel values ​​to a uniform range of [0,1], thereby reducing image intensity differences caused by changes in lighting conditions and generating normalized animal image data. The local region pixel variance is calculated on the normalized data using the following formula:

[0049]

[0050] Where σ 2 (i,j) is the local variance centered at pixel (i,j), and μ(i,j) is the average value within the local window, defined as:

[0051]

[0052] The window size is (2k+1)×(2k+1). Local pixel variance reflects the distribution of details and noise in the image. The smoothing intensity is adaptively adjusted based on the variance magnitude, using bilateral filtering or Gaussian filtering to smooth areas with high noise while preserving details, generating denoised animal image data. A cumulative gray-level histogram is generated using the denoised data, defined as:

[0053]

[0054] Where H c (v) is the cumulative histogram of pixel grayscale values ​​v, and h(u) represents the frequency of pixel values ​​u. Image contrast distribution is adjusted through histogram equalization or piecewise linear transformation. For example, using piecewise linear transformation, the grayscale value range [v1, v2] is smoothly stretched to [w1, w2], and the mapping formula is:

[0055]

[0056] This enhances contrast, resulting in enhanced animal image data. Multi-scale adaptive thresholding is then applied to the enhanced image, with the threshold defined as:

[0057] T(i,j)=α·μ(i,j)+β·σ(i,j);

[0058] Where α and β are adjustment parameters, and μ(i,j) and σ(i,j) are the mean and standard deviation of the pixel neighborhood, respectively. For each pixel, if I″(i,j)>T(i,j), it is classified as foreground; otherwise, it is classified as background, thus obtaining the initial mask data. Morphological dilation and erosion operations are performed on the initial mask using the formula:

[0059]

[0060] Where E and D are the dilation and erosion results, respectively, B is the structuring element, and I is the input mask data. This step yields smoothed target mask data. After generating the target mask, the target region is located from the enhanced image based on the mask data. By extracting the region bounding box, pixels within the region are cropped, and bilinear interpolation is performed to generate fixed-size image data. The bilinear interpolation formula is:

[0061] I r (x,y)=(1-a)(1-b)I(x1,y1)+a(1-b)I(x2,y1)+(1-a)bI(x1,y2)+abI(x2,y2);

[0062] Where x1, x2, y1, y2 are the nearest neighbor integer coordinates, a, b are the fractional part weights, and I r (x,y) are the interpolated pixel values, generating normalized image data. The normalized image data and the target mask data are then concatenated pixel by pixel, and a multi-channel representation is constructed through a stitching operation to generate the target animal image data.

[0063] In one specific embodiment, the process of performing step S2 may specifically include the following steps:

[0064] Frequency domain transformation and frequency centering shift operations are performed on the target animal image data to obtain centered spectrum data;

[0065] Perform complex number operations on the centered spectrum data to calculate the sum of squares of the real and imaginary parts and the phase angle, and obtain the frequency domain amplitude matrix and phase matrix;

[0066] A frequency distribution histogram is established based on the frequency domain amplitude matrix, and energy density is calculated to obtain frequency domain energy distribution data;

[0067] Based on the frequency domain energy distribution data, the frequency domain amplitude matrix is ​​multiplied by the high-pass filter and combined with the phase matrix to obtain the high-frequency sub-spectrum data;

[0068] Based on the frequency domain energy distribution data, the frequency domain amplitude matrix is ​​multiplied by the low-pass filter and combined with the phase matrix to obtain the low-frequency sub-spectrum data;

[0069] Two-dimensional inverse discrete Fourier transform and time-domain restoration of high-frequency information are performed on the high-frequency sub-spectral data to obtain high-frequency feature data of animal images. Two-dimensional inverse discrete Fourier transform and time-domain restoration of low-frequency information are performed on the low-frequency sub-spectral data to obtain low-frequency feature data of animal images.

[0070] Specifically, for the input target animal image data I(x,y), a two-dimensional discrete Fourier transform is applied to convert the image from the spatial domain to the frequency domain. The formula for the two-dimensional discrete Fourier transform is:

[0071]

[0072] Where F(u,v) is the frequency domain representation, I(x,y) is the original image data, M and N are the width and height of the image, respectively, u,v are the frequency domain coordinates, and j represents the imaginary unit. Through Fourier transform, the frequency domain data F(u,v) captures the frequency components of the image. A frequency centering shift operation is performed on F(u,v) to move the low-frequency components to the center of the spectrum. The centering operation formula is:

[0073] F c (u,v)=F(u,v)·(-1) u+v ;

[0074] Where F c (u,v) represents the centered spectral data. This operation concentrates low-frequency information in the central region of the spectrum, while high-frequency information is distributed in the peripheral regions, thus more intuitively representing the frequency characteristics of the image. For the centered spectral data F... c Perform complex number operations on (u,v) to calculate the frequency domain amplitude and phase respectively. The formula for calculating the frequency domain amplitude matrix A(u,v) is:

[0075]

[0076] Where Re(F) c (u,v)) and Im(F) c (u,v) are respectively F c The real and imaginary parts of (u,v) are given. The frequency domain phase matrix Φ(u,v) is calculated using the following formula:

[0077]

[0078] The amplitude matrix A(u,v) describes the intensity distribution of the frequency components, while the phase matrix Φ(u,v) preserves the spatial location information of the frequency components. Based on the amplitude matrix A(u,v), a frequency distribution histogram H(f) is constructed, where... This represents the amplitude of the frequency. The formula for calculating a frequency histogram is:

[0079]

[0080] The energy density of the frequency distribution is obtained by summing the amplitudes at different frequencies. The amplitude matrix A(u,v) is then compared with the high-pass filter H. H (u,v) and low-pass filter H L(u, v) are multiplied separately to separate high-frequency and low-frequency information. A high-pass filter is defined as follows:

[0081]

[0082] Where f c This is the cutoff frequency of the high-pass filter. Similarly, the definition of a low-pass filter is:

[0083]

[0084] The formula for calculating high-frequency sub-spectral data is:

[0085] F H (u,v)=A(u,v)·H H (u,v)·e jΦ(u,v) ;

[0086] Where F H (u,v) represents the high-frequency sub-spectral data. The formula for calculating the low-frequency sub-spectral data is:

[0087] F L (u,v)=A(u,v)·H L (u,v)·e jΦ(u,v) ;

[0088] Where F L (u,v) represents the low-frequency sub-spectral data. For the high-frequency sub-spectral data F... H (u,v) and low-frequency sub-spectral data F L Two-dimensional discrete Fourier inverse transforms are performed on (u, v) respectively to recover the time-domain information. The inverse transform formula is:

[0089]

[0090]

[0091] Where I H (x,y) are high-frequency feature data, I L (x,y) represents low-frequency feature data. Through the above process, high-frequency feature I... H (x,y) contains edge and detail information of the image, such as the texture of animal fur; while low-frequency features I L (x,y) includes the overall outline and general shape, such as the morphological structure of an animal's body.

[0092] In one specific embodiment, the process of performing step S3 may specifically include the following steps:

[0093] High-frequency feature data of animal images are input into the high-frequency branch of a dual-branch diffusion network for feature dimension mapping and hierarchical feature extraction to obtain high-frequency feature latent space data.

[0094] Low-frequency feature data of animal images are input into the low-frequency branch of a dual-branch diffusion network for feature dimension mapping and hierarchical feature extraction to obtain low-frequency feature latent space data.

[0095] The first attention mapping matrix is ​​constructed based on high-frequency feature latent space data and low-frequency feature latent space data, and cross-branch association calculation is performed to obtain feature interaction data;

[0096] The feature interaction data is input into the residual convolutional layer group of the dual-branch diffusion network. Convolution operation and feature superposition are performed in each residual unit of the residual convolutional layer group to obtain residual feature data.

[0097] The residual feature data is input into the self-attention module of the dual-branch diffusion network for feature recalibration to obtain channel attention feature data, and spatial attention weights are assigned based on the channel attention feature data to obtain spatial attention feature data.

[0098] Cross-layer feature aggregation and global feature summarization are performed on channel attention feature data and spatial attention feature data to obtain fused animal feature data.

[0099] Specifically, high-frequency feature data from animal images are input into the high-frequency branch of a two-branch diffusion network. The feature dimension mapping module then maps this data from the original high-dimensional feature space to a more computationally suitable latent space representation. Assume the input high-frequency features are in matrix form. Where m and n represent spatial resolution, and c1 represents the number of channels, the feature dimension mapping is achieved through a linear transformation, and its formula is:

[0100] H′=H·W h +b h ;

[0101] in It is a weight matrix. It is a bias vector. This is the mapped high-frequency feature representation. This process compresses the original high-frequency features to a lower dimension c2 to reduce computational complexity while retaining key information. The mapped high-frequency features then enter a hierarchical feature extraction module, which consists of a series of convolutional and pooling layers, extracting more abstract semantic information layer by layer. Assume that the convolutional operation of each layer is represented as follows:

[0102] H″ l+1 =σ(W l *H″ l +b l );

[0103] Where H″ l W is the feature map of layer l. lIt is the convolution kernel, * indicates the convolution operation, b l σ is the bias term, and σ is the activation function (e.g., ReLU). Multiple layers of convolution can progressively extract edge information and detail patterns of high-frequency features, outputting high-frequency feature latent space data H″. L Simultaneously, low-frequency feature data from animal images are input into the low-frequency branch of a two-branch diffusion network for similar feature dimension mapping and hierarchical feature extraction. Assume the input low-frequency features are a matrix. Its dimension mapping and feature extraction process is similar to that of the high-frequency branch, resulting in low-frequency feature latent space data L″. L The low-frequency branch focuses on extracting overall shape and macroscopic contour information, complementing the detailed information captured by the high-frequency branch. A first attention mapping matrix is ​​constructed based on the latent space data of both high-frequency and low-frequency features. The attention mechanism dynamically adjusts the contribution value of each feature by calculating the correlation weights between the two sets of features. Assuming the high-frequency latent space data is... Low-frequency hidden space data is The formula for calculating its attention mapping matrix is:

[0104]

[0105] Where A(i,j) represents the attention weight between the i-th high-frequency feature and the j-th low-frequency feature. This attention matrix enables cross-branch association between high-frequency and low-frequency features, generating feature interaction data. This feature interaction data is then input into a group of residual convolutional layers in a dual-branch diffuse network. The residual convolutional layer group contains multiple residual units, each of which enhances and stabilizes the features through a skip connection mechanism. Assuming the input feature is X, the output of the residual unit is:

[0106] Y = σ(W1*X + b1) + X;

[0107] Where W1 is the convolution kernel, σ is the activation function, X is the input feature, and Y is the residual feature data. The introduction of the residual structure can alleviate the vanishing gradient problem in deep networks and maintain the effectiveness of shallow features. The residual feature data is input into the self-attention module of the dual-branch diffusing network. The self-attention module recalibrates the features by redistributing the importance of feature channels. The formula for calculating channel attention is:

[0108] S c =σ(FC2(ReLU(FC1(GAP(Y)))));

[0109] FC1 and FC2 are fully connected layers, GAP is a global average pooling operation, and S... cThis refers to channel attention weights. Based on these channel attention weights, spatial attention weights are assigned to features to generate spatial attention feature data. Cross-layer feature aggregation and global feature summarization are then performed on the channel attention feature data and spatial attention feature data. Through feature aggregation operations, such as weighted summation or concatenation, features from different levels are integrated to generate fused animal feature data F. final .

[0110] In one specific embodiment, the process of performing step S4 may specifically include the following steps:

[0111] Based on the fusion of animal feature data, the feature data of the same animal in a continuous time period are randomly cropped, rotated and flipped to obtain positive sample feature data.

[0112] Euclidean distance is calculated for the features of different animal individuals in the fused animal feature data to obtain feature distance ranking data;

[0113] Based on the feature distance sorting data, the top N different identity feature pairs with the smallest distance values ​​are selected as hard samples, and feature alignment is performed on the hard samples to obtain negative sample feature data.

[0114] L2 norm normalization and inner product operation are performed on positive and negative sample feature data to obtain cosine similarity data.

[0115] The cosine similarity data is weighted by a temperature coefficient, and the contrastive loss value between feature pairs is calculated to obtain the contrastive learning loss data.

[0116] Based on the contrastive learning loss data, an exponential moving average is calculated for the positive sample feature data, and a momentum coefficient is set to smooth the features, resulting in dynamic feature update data.

[0117] Based on the dynamically updated feature data, the centroid of each animal identity feature vector is calculated and features are aggregated to obtain cluster center feature data. Based on the cluster center feature data, the feature index and feature vector corresponding to each animal identity are organized into key-value pairs to obtain the animal identity feature template.

[0118] Specifically, data augmentation is performed on the feature data of the same animal over a continuous time period based on fused animal feature data. This is achieved by increasing feature diversity through random pruning, rotation, and flipping transformations to simulate feature changes under different environmental conditions. Assume the input feature data is a matrix F∈R. m×n×c Where m and n represent spatial dimensions, and c represents the number of channels, random cropping is achieved by setting a cropping ratio p, i.e.:

[0119] F′(x,y,:)=F(px:(1-p)m,py:(1-p)n,:);

[0120] Where p is the cropping ratio parameter, and x and y represent random starting points. Similarly, rotation transformation is achieved through an image rotation matrix, while flip transformation is accomplished through horizontal or vertical inversion operations. After these enhancement operations, positive sample feature data of the same animal at different time periods are generated. Euclidean distance is calculated for the features of different animal individuals in the fused animal feature data to quantify the differences between features. Let the two feature vectors be f1, f2 ∈ R. d The Euclidean distance calculation formula is:

[0121]

[0122] Where f 1,i and f 2,i These are the i-th elements of the feature vectors. By calculating and sorting the distances of all feature pairs, we obtain the feature distance ranking data. Based on the ranking results, the top N distinct identity feature pairs with the smallest distance values ​​are selected as hard samples. These hard samples have relatively close feature distances, making them difficult for the model to distinguish and are key samples in training. For the selected hard samples, feature alignment is performed to ensure that the features of all samples have a uniform scale and orientation. Feature alignment is achieved through mean alignment or standardization, using the following formula:

[0123]

[0124] Where μ and σ are the mean and standard deviation of the features, respectively, and f′ is the aligned feature vector. The aligned data obtained in this step is the negative sample feature data. The positive and negative sample feature data are then normalized using the L2 norm, with the normalization formula as follows:

[0125]

[0126] in It is the L2 norm of the eigenvector, f norm These are the normalized features. After normalization, the cosine similarity between positive and negative sample pairs is calculated using the inner product operation, with the following formula:

[0127]

[0128] The cosine similarity (sin) ranges from [-1, 1] and represents the directional similarity between two vectors. A temperature coefficient weighting is applied to the cosine similarity data to adjust the sensitivity of the feature distribution; the formula is:

[0129]

[0130] Where τ is a temperature coefficient, controlling the smoothness of the similarity distribution. The commonly used formula for calculating the contrast loss between positive and negative sample pairs based on weighted similarity is:

[0131]

[0132] in The similarity of positive sample pairs is represented by α, and the denominator is the weighted sum of the similarities of all sample pairs. This loss optimizes the model by increasing the similarity of positive sample pairs and decreasing the similarity of negative sample pairs. Based on the contrastive learning loss data, an exponential moving average is calculated on the positive sample feature data to achieve feature smoothing. Let the momentum coefficient be α, and the update formula for positive sample features is:

[0133] f updated =αf prev +(1-α)f new ;

[0134] Where f prev and f new These are historical features and new features, f updated These are the updated features. The momentum coefficient controls the smoothness, with a value range of [0,1]. Based on the updated feature data, centroid calculation and feature aggregation are performed on the feature vector for each animal identity, using the following formula:

[0135]

[0136] Where c is the centroid vector and N is the number of samples for that identity. The centroid vector of each identity is organized with its corresponding feature index into key-value pairs to obtain the animal identity feature template.

[0137] In one specific embodiment, the process of performing step S5 may specifically include the following steps:

[0138] Two-dimensional discrete Fourier transform and spectral separation are performed on real-time animal image sequences to obtain real-time high-frequency feature data and real-time low-frequency feature data, respectively.

[0139] Real-time high-frequency feature data is input into the high-frequency branch of the dual-branch diffusion network to perform feature dimension mapping and hierarchical feature extraction, thereby obtaining real-time high-frequency latent space data.

[0140] Real-time low-frequency feature data is input into the low-frequency branch of the dual-branch diffusion network to perform feature dimension mapping and hierarchical feature extraction, thereby obtaining real-time low-frequency latent space data.

[0141] A second attention mapping matrix is ​​constructed based on real-time high-frequency latent space data and real-time low-frequency latent space data, and cross-branch association calculation is performed to obtain real-time feature interaction data.

[0142] Real-time feature interaction data is input into the residual convolutional layer group and self-attention module of the dual-branch diffusion network, and feature fusion and recalibration are performed to obtain real-time fused feature data;

[0143] Based on the feature index and feature vector in the animal identity feature template, L2 norm normalization and inner product operation are performed on the real-time fused feature data to obtain identity similarity data.

[0144] A matching threshold is set for identity similarity data to determine identity, and the identity determination result data is obtained. The identity determination result data is then associated with the spatiotemporal information of the corresponding image frame to generate animal identity data.

[0145] Specifically, a two-dimensional discrete Fourier transform is performed on the real-time animal image sequence to convert the image from the spatial domain to the frequency domain and extract its frequency information. The formula for the two-dimensional discrete Fourier transform is:

[0146]

[0147] Where F(u,v) represents the frequency domain data, I(x,y) represents the pixel values ​​of the input image, M and N are the width and height of the image, respectively, and u,v are the frequency domain coordinates. The frequency domain data is subjected to spectral separation, decomposing it into high-frequency and low-frequency components. The high-frequency component F... H (u,v) mainly contains detailed information about the image, such as edges and textures, while the low-frequency component F L (u,v) reflects the global structure and contour of the image. High-frequency separation is achieved through a high-pass filter, which is defined as:

[0148]

[0149] Low-frequency separation is achieved through a low-pass filter, which is defined as follows:

[0150]

[0151] Where f c It is the cutoff frequency. This is determined by calculating F separately. H (u,v)=F(u,v)·H H (u,v) and F L (u,v)=F(u,v)·H L (u,v) is used to obtain real-time high-frequency and low-frequency feature data. The real-time high-frequency feature data is then input into the high-frequency branch of the dual-branch diffusion network for feature dimension mapping and hierarchical feature extraction. The formula for feature dimension mapping is:

[0152] H′(x,y,c)=σ(W H ·H(x,y,:)+b H );

[0153] Where H(x,y,c) is the input of high-frequency feature data, W H It is the mapping weight matrix, b HHere, σ is the bias vector, σ is the activation function (e.g., ReLU), and H′ is the mapped high-frequency latent space data. The mapped features are then used to extract hierarchical features through a series of convolution operations, as shown in the formula:

[0154] H″ l+1 =σ(W l *H″ l +b l );

[0155] Where H″ l It is the high-frequency feature map of the l-th layer, W l This refers to the convolution kernel, and * indicates a convolution operation. Similarly, real-time low-frequency feature data is input into the low-frequency branch of the dual-branch diffusing network, and similar dimensionality mapping and hierarchical feature extraction are performed to generate low-frequency latent space data L″. L High-frequency and low-frequency latent space data represent the detailed and global features of the image, respectively. Based on real-time high-frequency and low-frequency latent space data, a second attention mapping matrix is ​​constructed to capture the correlation between the features of the two branches. The formula for the attention mapping is:

[0156]

[0157] Where A(i,j) is the attention weight, representing the correlation between high-frequency and low-frequency features at a specific location. Through an attention mechanism, the two types of features are dynamically fused into real-time feature interaction data. This real-time feature interaction data is then input into the residual convolutional layers and self-attention module of the dual-branch diffusing network to extract and fuse features. The feature enhancement formula for the residual convolutional layers is:

[0158] Y = σ(W1*X + b1) + X;

[0159] Where X is the input feature, W1 is the convolution kernel, and b1 is the bias term. The self-attention module performs recalibration through channel attention and spatial attention. The channel attention is calculated as follows:

[0160] S c =σ(FC2(ReLU(FC1(GAP(Y)))));

[0161] Where GAP is global average pooling, FC1 and FC2 are fully connected layers, and S... c This refers to channel attention weights. Spatial attention redistributes weights based on positional relationships. After real-time fused feature data is generated, it is matched with feature vectors in the animal identity feature template. The fused feature data is then normalized using the L2 norm, as shown in the formula:

[0162]

[0163] After normalization, identity similarity is calculated using the inner product formula:

[0164]

[0165] Where T norm This is the template feature vector. A matching threshold τ is set for similarity; when sim ≥ τ, a successful match is determined. The identity determination result is associated with the temporal and spatial information of the image frame. By recording the frame number and coordinates, animal identity data with spatiotemporal information is generated.

[0166] In one specific embodiment, the method for identifying laboratory animals based on image recognition further includes the following steps:

[0167] Animal identification data is sampled over time and motion parameters are extracted to obtain target motion state data;

[0168] The covariance matrix of the target motion state data is initialized and the state transition matrix is ​​constructed. The process noise parameters are set to obtain the Kalman filter initialization data.

[0169] The target state prediction data is obtained by iteratively predicting the target state based on the Kalman filter initialization data and then combining the observation data for state correction.

[0170] The target state prediction data and the current frame detection result data are used to extract the position coordinates, and the Euclidean distance and the angle between the motion direction are calculated to obtain the target similarity matrix;

[0171] The cost matrix of the Hungarian algorithm is constructed based on the target similarity matrix, and the row and column elements of the cost matrix are normalized by minimizing the value to obtain the normalized cost matrix. The Hungarian algorithm is then executed on the normalized cost matrix, and trajectory allocation is calculated by the bipartite graph maximum matching method to obtain trajectory matching index data.

[0172] Trajectory breakage detection is performed on the trajectory matching index data, and the broken trajectory is interpolated and completed based on motion state prediction to obtain a complete trajectory sequence. The complete trajectory sequence is then mapped to the animal identification data to generate motion trajectory data with animal identification.

[0173] Specifically, animal identification data is temporally sampled to extract motion features across consecutive time frames. Assume the animal's trajectory data consists of identification data over T time steps, with each frame recording its position coordinates (x, y, y). t ,y t ) and velocity v t By sampling the time series data, motion parameters of the animal at key time points were extracted, including instantaneous velocity v. t and acceleration a t The formula for calculating speed is:

[0174]

[0175] Where (x) t ,y t ) and (x t-1 ,y t-1 ) represents the coordinates of the current frame and the previous frame, and Δt is the time interval. Similarly, acceleration is calculated using the rate of change of velocity.

[0176] a t =(v t -v t-1 ) / Δt;

[0177] The extracted motion parameters form the target motion state data, which serves as input for subsequent state estimation and prediction. Based on the target motion state data, the covariance matrix is ​​initialized and the state transition matrix is ​​constructed. The covariance matrix P represents the uncertainty of the state, and it is initialized as an extended form of the identity matrix:

[0178]

[0179] Where σ x ,σ y ,σ v ,σ a These represent the initial uncertainties in position, velocity, and acceleration, respectively. The state transition matrix F describes the dynamic evolution of the target state, and its form is:

[0180]

[0181] Where Δt is the time interval. This matrix represents the current state [x, y, v]. x ,v y Mapped to the state at the next time step. Furthermore, a process noise parameter Q is set to reflect random disturbances in the system:

[0182] Q = diag(q) x ,q y ,q v ,q a );

[0183] Where q x ,q y ,q v ,q a This is the covariance of the process noise. Based on these parameters, the Kalman filter is initialized. The Kalman filter iteration process is divided into two stages: prediction and correction. In the prediction stage, the state transition matrix is ​​used to predict the state at the next time step:

[0184]

[0185] in This represents the predicted state, and w represents the process noise. During the correction phase, the observed data Z is used as a reference. t Update prediction status:

[0186]

[0187] Where K = P·H T ·(H·P·H T +R) -1 Here, H is the Kalman gain matrix, H is the observation matrix, and R is the observation noise covariance matrix. Target state prediction data is generated through multiple iterations. This target state prediction data is then matched with the detection results of the current frame. By extracting the position coordinates (x, y), the Euclidean distance and the angle between the motion directions between targets are calculated. The formula for the Euclidean distance is:

[0188]

[0189] The formula for calculating the directional angle is:

[0190]

[0191] in and These are the velocity vectors of two targets. Based on this data, a target similarity matrix is ​​constructed. The cost matrix of the Hungarian algorithm is then constructed using the target similarity matrix, and the matrix is ​​normalized to its minimum value using the following formula:

[0192]

[0193] Where C is the original cost matrix, C ′ This is the normalized matrix. The trajectory allocation is calculated using the Hungarian algorithm and the bipartite graph maximum matching method to obtain trajectory matching index data. Trajectory break detection is performed on the matching index data to identify trajectory interruptions caused by occlusion or target loss. For broken trajectories, motion state prediction is used for interpolation completion. Assuming the states before and after the trajectory break are (x1, y1) and (x2, y2), the interpolation formula is:

[0194]

[0195] Where t1, t2, and t represent the times before, after, and at the interpolation point, respectively. A complete trajectory sequence is generated through completion. This complete trajectory sequence is then mapped to animal identification data to establish a spatiotemporal correspondence. By recording the time and location coordinates of each frame, an animal identification identifier is associated with each trajectory, generating motion trajectory data with animal identification identifiers.

[0196] The foregoing has described the image recognition-based laboratory animal identification method in the embodiments of the present invention. The following describes the image recognition-based laboratory animal identification system in the embodiments of the present invention. Please refer to [link / reference]. Figure 2 One embodiment of the laboratory animal identification system based on image recognition in this invention includes:

[0197] The preprocessing module is used to preprocess the animal motion image sequences acquired by high-speed cameras in the laboratory to obtain target animal image data;

[0198] The transformation module is used to perform two-dimensional discrete Fourier transform and inverse Fourier transform on the target animal image data to obtain high-frequency feature data and low-frequency feature data of the animal image.

[0199] The feature processing module is used to input high-frequency feature data and low-frequency feature data of animal images into a dual-branch diffusion network for feature processing to obtain fused animal feature data.

[0200] The module is used to construct positive sample pairs based on fused animal feature data, construct negative sample pairs through hard sample mining, calculate feature distance based on cosine similarity and perform momentum update to obtain animal identity feature templates.

[0201] The computation module is used to extract features and calculate similarity from real-time animal image sequences based on a dual-branch diffusion network and animal identity feature templates to obtain animal identity data.

[0202] Through the collaborative efforts of the aforementioned components, and by introducing frequency domain decomposition and a bi-branch diffusion network structure, the model achieves separate extraction and fusion processing of high-frequency detail features and low-frequency contour features in animal images, thereby enhancing the discriminative power of identity features. Attention mechanisms and residual structures are employed for feature interaction and enhancement, effectively capturing the correlation between features in different frequency domains and improving the robustness of feature representation. A feature learning strategy based on contrastive learning is designed, improving the model's ability to distinguish similar individuals by constructing positive and negative sample pairs and mining hard samples. The introduction of a momentum update mechanism enables dynamic updating of feature templates, allowing the model to adapt to subtle changes in animal appearance. Combining Kalman filter prediction and Hungarian algorithm matching effectively solves the trajectory breakage problem under conditions of rapid animal movement and occlusion. A multi-level feature fusion and spatiotemporal information association strategy enhances the temporal consistency of identity recognition results.

[0203] Reference Figure 3 This invention also provides a computer device, which may be a server, and its internal structure may be as follows: Figure 3As shown, the computer device includes a processor, memory, display screen, input device, network interface, and database connected via a system bus. The processor provides computing and control capabilities. The memory includes a non-volatile storage medium and internal memory. The non-volatile storage medium stores the operating system, computer programs, and database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The database stores the data corresponding to this embodiment. The network interface is used to communicate with external terminals via a network connection. When the computer program is executed by the processor, it implements the above-described method.

[0204] Those skilled in the art will understand that Figure 3 The structures shown are merely block diagrams of some structures related to the present invention and do not constitute a limitation on the computer devices on which the present invention is applied.

[0205] An embodiment of the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method. It is understood that the computer-readable storage medium in this embodiment can be a volatile readable storage medium or a non-volatile readable storage medium.

[0206] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the present invention and embodiments can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual-rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM, etc.

[0207] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0208] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0209] The above-described embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit it. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for identifying laboratory animals based on image recognition, characterized in that, The method includes: Preprocessing is performed on animal motion image sequences captured by high-speed cameras in the laboratory to obtain target animal image data; Performing two-dimensional discrete Fourier transform and inverse Fourier transform on the target animal image data yields high-frequency feature data and low-frequency feature data of the animal images; specifically including: performing frequency domain transformation and frequency centering shift operations on the target animal image data to obtain centered spectrum data; performing complex number operations on the centered spectrum data to calculate the sum of squares of the real and imaginary parts and the phase angle to obtain a frequency domain amplitude matrix and a phase matrix; establishing a frequency distribution histogram based on the frequency domain amplitude matrix and calculating the energy density to obtain frequency domain energy distribution data; based on the... The frequency domain energy distribution data is used to obtain high-frequency sub-spectrum data by multiplying the frequency domain amplitude matrix with a high-pass filter and combining it with the phase matrix. Based on the frequency domain energy distribution data, the frequency domain amplitude matrix is ​​multiplied with a low-pass filter and combined with the phase matrix to obtain low-frequency sub-spectrum data. Two-dimensional inverse discrete Fourier transform and time-domain restoration of high-frequency information are performed on the high-frequency sub-spectrum data to obtain high-frequency feature data of the animal image, and two-dimensional inverse discrete Fourier transform and time-domain restoration of low-frequency information are performed on the low-frequency sub-spectrum data to obtain low-frequency feature data of the animal image. The high-frequency feature data and low-frequency feature data of the animal images are respectively input into a dual-branch diffusion network for feature processing to obtain fused animal feature data. Positive sample pairs are constructed based on the fused animal feature data, negative sample pairs are constructed through hard sample mining, feature distance is calculated based on cosine similarity and momentum is updated to obtain animal identity feature templates; Based on the dual-branch diffusion network and the animal identity feature template, feature extraction and similarity calculation are performed on real-time animal image sequences to obtain animal identity data.

2. The laboratory animal identification method based on image recognition according to claim 1, characterized in that, The preprocessing of animal motion image sequences acquired by high-speed cameras in the laboratory to obtain target animal image data includes: RGB channel separation and pixel normalization mapping were performed on animal motion image sequences captured by high-speed cameras in the laboratory to obtain normalized animal image data. Local region pixel variance calculation and adaptive smoothing intensity adjustment are performed on the normalized animal image data to obtain denoised animal image data; A cumulative grayscale histogram is generated based on the denoised animal image data, and the image contrast distribution is adjusted through piecewise linear transformation to obtain enhanced animal image data. Multi-scale adaptive threshold segmentation is performed on the enhanced animal image data to obtain initial mask data, and dilation and erosion cascade operations are performed on the initial mask data to obtain target mask data; Based on the target mask data, region localization is performed in the enhanced animal image data to obtain localized image data, and bilinear interpolation is performed on the localized image data to obtain normalized size image data. The normalized size image data and the target mask data are combined in a pixel-cascaded structure to generate target animal image data.

3. The laboratory animal identification method based on image recognition according to claim 1, characterized in that, The process of inputting the high-frequency feature data and low-frequency feature data of the animal image into a dual-branch diffusion network for feature processing to obtain fused animal feature data includes: The high-frequency feature data of the animal image is input into the high-frequency branch of the dual-branch diffusion network for feature dimension mapping and hierarchical feature extraction to obtain high-frequency feature latent space data. The low-frequency feature data of the animal image is input into the low-frequency branch of the dual-branch diffusion network for feature dimension mapping and hierarchical feature extraction to obtain low-frequency feature latent space data. A first attention mapping matrix is ​​constructed based on the high-frequency feature latent space data and the low-frequency feature latent space data, and cross-branch association calculation is performed to obtain feature interaction data. The feature interaction data is input into the residual convolutional layer group of the dual-branch diffusion network. Convolution operation and feature superposition are performed in each residual unit of the residual convolutional layer group to obtain residual feature data. The residual feature data is input into the self-attention module of the dual-branch diffusion network for feature recalibration to obtain channel attention feature data, and spatial attention weights are allocated based on the channel attention feature data to obtain spatial attention feature data. Cross-layer feature aggregation and global feature summarization are performed on the channel attention feature data and the spatial attention feature data to obtain fused animal feature data.

4. The laboratory animal identification method based on image recognition according to claim 3, characterized in that, The process involves constructing positive sample pairs based on the fused animal feature data, constructing negative sample pairs through hard sample mining, calculating feature distance based on cosine similarity and performing momentum updates to obtain an animal identity feature template, including: Based on the fused animal feature data, the feature data of the same animal in a continuous time period are randomly cropped, rotated and flipped to obtain positive sample feature data. Euclidean distance is calculated for the features of different animal individuals in the fused animal feature data to obtain feature distance ranking data; Based on the feature distance sorting data, the top N different identity feature pairs with the smallest distance values ​​are selected as hard samples, and feature alignment is performed on the hard samples to obtain negative sample feature data. L2 norm normalization and inner product operation are performed on the positive sample feature data and the negative sample feature data to obtain cosine similarity data; The cosine similarity data is weighted by a temperature coefficient, and the contrast loss value between feature pairs is calculated to obtain the contrast learning loss data. Based on the contrastive learning loss data, an exponential moving average is calculated on the positive sample feature data, and a momentum coefficient is set for feature smoothing to obtain dynamic feature update data. Based on the dynamic feature update data, centroid calculation and feature aggregation are performed on the feature vector of each animal identity to obtain cluster center feature data. Based on the cluster center feature data, the feature index and feature vector corresponding to each animal identity are organized into key-value pairs to obtain the animal identity feature template.

5. The laboratory animal identification method based on image recognition according to claim 4, characterized in that, The process involves extracting features and calculating similarity from real-time animal image sequences based on the dual-branch diffusion network and the animal identity feature template to obtain animal identity data, including: Two-dimensional discrete Fourier transform and spectral separation are performed on real-time animal image sequences to obtain real-time high-frequency feature data and real-time low-frequency feature data, respectively. The real-time high-frequency feature data is input into the high-frequency branch of the dual-branch diffusion network to perform feature dimension mapping and hierarchical feature extraction, thereby obtaining real-time high-frequency latent space data. The real-time low-frequency feature data is input into the low-frequency branch of the dual-branch diffusion network to perform feature dimension mapping and hierarchical feature extraction, thereby obtaining real-time low-frequency latent space data. A second attention mapping matrix is ​​constructed based on the real-time high-frequency latent space data and the real-time low-frequency latent space data, and cross-branch association calculation is performed to obtain real-time feature interaction data. The real-time feature interaction data is input into the residual convolutional layer group and self-attention module of the dual-branch diffusion network, and feature fusion and recalibration are performed to obtain real-time fused feature data; Based on the feature index and feature vector in the animal identity feature template, L2 norm normalization and inner product operation are performed on the real-time fused feature data to obtain identity similarity data. A matching threshold is set on the identity similarity data to determine the identity, and the identity determination result data is obtained. The identity determination result data is then associated with the spatiotemporal information of the corresponding image frame to generate animal identity data.

6. The laboratory animal identification method based on image recognition according to claim 5, characterized in that, The image recognition-based laboratory animal identification method further includes: The animal identification data is subjected to time-series sampling and motion parameter extraction to obtain target motion state data; The target motion state data is initialized with a covariance matrix and a state transition matrix is ​​constructed. Process noise parameters are set to obtain Kalman filter initialization data. Based on the Kalman filter initialization data, iterative prediction calculations are performed on the target state, and state correction is performed in conjunction with the observation data to obtain the target state prediction data. The target state prediction data and the current frame detection result data are used to extract the position coordinates, and the Euclidean distance and the angle between the motion direction are calculated to obtain the target similarity matrix; Based on the target similarity matrix, a cost matrix for the Hungarian algorithm is constructed, and the row and column elements of the cost matrix are normalized to the minimum value to obtain a normalized cost matrix. The Hungarian algorithm is then executed on the normalized cost matrix, and trajectory allocation is calculated using the bipartite graph maximum matching method to obtain trajectory matching index data. Trajectory breakage detection is performed on the trajectory matching index data, and the broken trajectory is interpolated and completed based on motion state prediction to obtain a complete trajectory sequence. The complete trajectory sequence is then mapped to the animal identity data to generate motion trajectory data with animal identity identifiers.

7. A laboratory animal identification system based on image recognition, characterized in that, For performing the image recognition-based laboratory animal identification method as described in any one of claims 1-6, the image recognition-based laboratory animal identification system comprises: The preprocessing module is used to preprocess the animal motion image sequences acquired by high-speed cameras in the laboratory to obtain target animal image data; The transformation module is used to perform two-dimensional discrete Fourier transform and inverse Fourier transform on the target animal image data to obtain high-frequency feature data and low-frequency feature data of the animal image. The feature processing module is used to input the high-frequency feature data and low-frequency feature data of the animal image into a dual-branch diffusion network for feature processing to obtain fused animal feature data. The construction module is used to construct positive sample pairs based on the fused animal feature data, construct negative sample pairs through hard sample mining, calculate feature distance based on cosine similarity and perform momentum update to obtain animal identity feature templates; The calculation module is used to extract features and calculate similarity from real-time animal image sequences based on the dual-branch diffusion network and the animal identity feature template to obtain animal identity data.

8. A computer device, characterized in that, The invention includes a memory and a processor, the memory storing a computer program executable on the processor, characterized in that, when the processor executes the computer program, it implements the laboratory animal identification method based on image recognition as described in any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, the computer program causing a processor, when executed by a processor, to perform the image recognition-based laboratory animal identification method as described in any one of claims 1 to 6.