Laboratory animal identity recognition method and system based on image recognition

By performing Fourier transform and double-branch diffusion network processing on the animal moving image sequences collected by high-speed cameras in the laboratory, fuse animal feature data, construct positive and negative sample pairs and perform momentum updates, the problems of animal identity identification obfuscation and timing consistency in the prior art are solved, and efficient animal identity identification is achieved.

CN120126172AActive Publication Date: 2025-06-10法洛思科技(深圳)有限公司

Patent Information

Application Number
CN202510185159.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-19
Publication Date
2025-06-10
Estimated Expiration
2045-02-19

AI Technical Summary

Technical Problem

Existing animal identity recognition methods based on image recognition are prone to identity confusion when animals move rapidly or block each other, and it is difficult to effectively distinguish individuals with similar appearances, especially in laboratory environments, which are difficult to meet research needs.

Method used

By preprocessing the sequence of animal moving images collected by high-speed cameras in the laboratory, performing two-dimensional discrete Fourier transform, extracting high-frequency feature data and low-frequency feature data of animal images, and inputting them into the double-branch diffusion network for feature processing, fusing animal feature data, constructing positive and negative sample pairs, and obtaining animal identity feature templates through momentum update to achieve real-time identity recognition.

Benefits of technology

It improves the ability to distinguish identity characteristics, enhances the timing consistency of identity recognition results, and can effectively solve the identity recognition problem in the case of rapid movement and occlusion of animals.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120126172A_ABST
    Figure CN120126172A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image recognition, and discloses a laboratory animal identity recognition method and system based on image recognition, and the method comprises the steps: carrying out the preprocessing of an animal motion image sequence collected by a high-speed camera in a laboratory, and obtaining the image data of a target animal; 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; respectively inputting into a double-branch diffusion network 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, feature extraction and similarity calculation are performed on the real-time animal image sequence to obtain animal identity data, so that the distinguishing capability of identity features is improved, and the time sequence consistency of an identity recognition result is enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of image recognition, and particularly to a method and system for identifying the identity of laboratory animals based on image recognition. Background Art

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

[0003] Currently, there are mainly two problems in the animal identity recognition method based on image recognition: one is that identity recognition confusion is likely to occur when animals move rapidly or block each other, resulting in inaccurate tracking results; the other is that existing methods often only focus on the overall features of images and ignore the detailed information contained in different frequency components, making it difficult to effectively distinguish individuals with similar appearances. Especially in the laboratory environment, due to factors such as high similarity in animal appearances, fast movement speeds, and large group sizes, traditional recognition methods are difficult to meet the research requirements. Summary of the Invention

[0004] The present invention provides a method and system for identifying the identity of laboratory animals based on image recognition, which improves the discrimination ability of identity features and enhances the temporal consistency of identity recognition results.

[0005] In a first aspect, the present invention provides a method for identifying the identity of laboratory animals based on image recognition, and the method for identifying the identity of laboratory animals based on image recognition includes:

[0006] Preprocess the animal motion image sequence collected by a high-speed camera 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 animal image high-frequency feature data and animal image low-frequency feature data;

[0008] Input the animal image high-frequency feature data and the animal image low-frequency feature data into a dual-branch diffusion network for feature processing respectively to obtain fused animal feature data;

[0009] Construct positive sample pairs based on the fused animal feature data, construct negative sample pairs through hard sample mining, calculate feature distances based on cosine similarity and perform momentum update to obtain an animal identity feature template;

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

[0011] In a second aspect, the present invention provides a laboratory animal identity recognition system based on image recognition. The laboratory animal identity recognition system based on image recognition includes:

[0012] A preprocessing module, configured to preprocess the animal motion image sequence collected by a high-speed camera in the laboratory to obtain target animal image data;

[0013] A transformation module, configured to perform two-dimensional discrete Fourier transform and inverse Fourier transform on the target animal image data to obtain animal image high-frequency feature data and animal image low-frequency feature data;

[0014] A feature processing module, configured to respectively input the animal image high-frequency feature data and the animal image low-frequency feature data into a double-branch diffusion network for feature processing to obtain fused animal feature data;

[0015] A construction module, configured to construct positive sample pairs based on the fused animal feature data, construct negative sample pairs through hard sample mining, calculate feature distances based on cosine similarity and perform momentum update to obtain an animal identity feature template;

[0016] A calculation module, configured to perform feature extraction and similarity calculation on the real-time animal image sequence based on the double-branch diffusion network and the animal identity feature template to obtain animal identity data.

[0017] In a third aspect of the present invention, a computer device is provided, including: a memory and at least one processor, wherein instructions are stored in the memory; the at least one processor calls the instructions in the memory to enable the computer device to execute the above-mentioned laboratory animal identity recognition method based on image recognition.

[0018] In a fourth aspect of the present invention, a computer-readable storage medium is provided, wherein instructions are stored in the computer-readable storage medium, and when the instructions are run on a computer, the computer is enabled to execute the above-mentioned laboratory animal identity recognition method based on image recognition.

[0019] In the technical solution provided by the present invention, by introducing frequency domain decomposition and a dual-branch diffusion network structure, the extraction and fusion processing of high-frequency detail features and low-frequency contour features of animal images are realized, and the discrimination ability of identity features is improved. The attention mechanism and residual structure 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, and by constructing positive and negative sample pairs and mining hard samples, the discrimination ability of the model for similar individuals is improved. By introducing a momentum update mechanism, the dynamic update of feature templates is realized, enabling the model to adapt to small changes in the appearance of animals. Combining Kalman filter prediction and Hungarian algorithm matching effectively solves the problem of trajectory breakage in the case of rapid movement and occlusion of animals. The multi-level feature fusion and spatio-temporal information association strategy are adopted to enhance the temporal consistency of the identity recognition results. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings in the following description are some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can be obtained based on these drawings.

[0021] Figure 1 It is a schematic diagram of the steps of the laboratory animal identity recognition method based on image recognition in the embodiments of the present invention;

[0022] Figure 2 It is a schematic diagram of the structure of the laboratory animal identity recognition system based on image recognition in the embodiments of the present invention;

[0023] Figure 3 It is a schematic block diagram of the structure of the computer device in the embodiments of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0024] The embodiments of the present invention provide a laboratory animal identity recognition method and system based on image recognition. The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present invention and the above accompanying drawings are used to distinguish similar objects and do not necessarily need to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments described here can be implemented in an order different from that shown or described here. In addition, the terms "comprising" or "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device comprising a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.

[0025] For ease of understanding, the specific process of the embodiments of the present invention will be described below. Please refer to Figure 1 One embodiment of the method for identifying the identity of laboratory animals based on image recognition in the embodiments of the present invention includes:

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

[0027] It can be understood that the execution subject of the present invention can be an image recognition-based laboratory animal identity recognition system, or a terminal or a server. Specifically, it is not limited here. The embodiments of the present invention will be described by taking the server as the execution subject as an example.

[0028] Specifically, the RGB channels of the animal motion image sequence collected by a high-speed camera in the laboratory are separated to extract the independent information of each channel, turning the overall image processing to a more refined color dimension analysis. This separation helps reduce the color interference problem caused by channel superposition. At the same time, pixel normalization mapping is performed on each separated channel. By readjusting the pixel values to the range of 0 to 1, the computability and consistency of the image are enhanced, the amplitude differences introduced by different acquisition devices or lighting conditions are eliminated, and the normalized animal image data is obtained. The pixel variance of the local area of the normalized animal image data is calculated to evaluate the degree of gray change in the local area of the image. The calculation of pixel variance reflects the detail complexity of the image. Through this statistical method, the regions with rich details and relatively flat regions in the image can be identified. Based on this variance information, adaptive smoothing intensity adjustment is implemented. In this process, more detail information is retained in the high-variance regions, while the low-variance regions are smoothed, effectively reducing the interference of noise on the image and maintaining the clarity of the key feature regions, generating the denoised animal image data. The cumulative gray histogram is generated using the denoised animal image data. The cumulative gray histogram provides the distribution information of the gray values in the image, which can reflect the overall brightness and contrast characteristics of the image. Based on this histogram, the gray distribution of the image is adjusted through piecewise linear transformation, thereby redistributing the contrast range of the image. The contrast distribution adjustment aims to highlight the key feature regions in the image, weaken the redundant background information, and improve the visual effect of the image and the effectiveness of feature extraction. Through this step, the contrast-enhanced animal image data is generated. Multiscale adaptive threshold segmentation is performed on the enhanced animal image data. Using the image information at different scales, the contour region of the animal is identified and segmented by dynamically adjusting the threshold, generating the initial mask data. The initial mask data is optimized. Through the cascaded operations of dilation and erosion, the mask boundary is corrected, isolated noise points are removed, and the contour of the target region is made smoother. The dilation operation is used to connect the broken boundaries, while the erosion operation helps eliminate the small-area artifacts introduced during the expansion process, obtaining the target mask data. Based on the target mask data, regional localization is performed in the enhanced animal image data, effectively isolating the target region of the animal and excluding the interference of non-target regions, obtaining the localized image data. Bilinear interpolation operation is performed on the localized image data to uniformly adjust the localized target region to a standardized size, generating the normalized size image data. The normalized size image data and the target mask data are combined in a pixel-level cascade structure. By integrating the mask and image information into a data structure, both the pixel information of the target region and the spatial constraint information of the mask are utilized in subsequent processing, generating 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 the high-frequency feature data of the animal image and the low-frequency feature data of the animal image;

[0030] Specifically, perform frequency domain conversion on the target animal image data, and use the two-dimensional discrete Fourier transform to convert the image from the time domain representation to the frequency domain representation. Decompose the spatial features of the original image pixel data into a set of sine components with different frequencies and directions, revealing the frequency features contained in the image. Perform a centering translation operation on the initial frequency distribution. By translating the frequency zero point from the upper left corner of the matrix to the center of the spectrum, it is more intuitive to represent that the low-frequency components are located in the central region and the high-frequency components surround it, obtaining the centered spectrum data. Perform complex number operations on the centered spectrum data, extract the real part and the imaginary part of the frequency domain data, and calculate the square root of the sum of the squares of the two to generate the frequency domain amplitude matrix. At the same time, calculate the phase angle of the frequency component through the arctangent function to obtain the phase matrix. These two matrices respectively describe the amplitude information and the phase information in the frequency domain, where the frequency domain amplitude matrix reflects the intensity distribution of different frequency components of the image, and the phase matrix captures the spatial relationship of these frequency components. Establish a frequency distribution histogram through the frequency domain amplitude matrix, thereby performing statistical analysis on the energy distribution of the frequency components. The frequency distribution histogram uses frequency as the horizontal axis and the frequency domain amplitude as the vertical axis to display the spectral energy distribution characteristics of the target image. On this basis, obtain the energy density distribution data in the frequency domain through integral or weighted calculation, quantifying the ratio of high-frequency and low-frequency energies in the target image. Based on the frequency domain energy distribution data, multiply the frequency domain amplitude matrix by a high-pass filter. The high-pass filter extracts the detail information and edge features in the image by suppressing the low-frequency components and retaining the high-frequency components. Recombine the high-pass amplitude matrix with the corresponding phase matrix to generate high-frequency sub-spectrum data. Similarly, in order to extract low-frequency features, multiply the frequency domain amplitude matrix by a low-pass filter. The role of the low-pass filter is to retain the low-frequency components and suppress the high-frequency components, extracting the global contour and overall information of the image. Recombine the low-pass amplitude matrix with the phase matrix to generate low-frequency sub-spectrum data. Perform the two-dimensional inverse discrete Fourier transform on the high-frequency sub-spectrum data and the low-frequency sub-spectrum data respectively, and convert 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, which retains the detail features of the target animal image, including information such as hair texture, edges, and local contrast, and is suitable for high-resolution feature extraction. The inverse transform of the low-frequency sub-spectrum generates a low-frequency feature image, which contains low-resolution features such as the shape, contour, and overall structure of the animal.

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

[0032] Specifically, the high-frequency feature data of the animal image is input into the high-frequency branch of the dual-branch diffusion network to capture the rich detail information and local texture features in the high-frequency feature data. Through the feature dimension mapping operation, the original feature dimension of the high-frequency feature data is transformed into the latent space representation required by the network. The adjustment of the feature dimension enables the data to adapt to the subsequent hierarchical feature extraction module. During the hierarchical feature extraction process, the network gradually extracts the abstract expressions of the high-frequency features, aggregating from edge textures and detailed structures into high-order semantic information to generate high-frequency feature latent space data. At the same time, the low-frequency feature data of the animal image is input into the low-frequency branch of the dual-branch diffusion network. The design of this branch focuses on extracting the global contour and overall structure information in the low-frequency features. Similarly, through the feature dimension mapping operation, 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 gradually elevates the macroscopic shape information in the low-frequency data to latent space features with high-level expressions through multiple feature transformations, generating 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. Through this attention mapping matrix, the cross-branch correlation relationship between the high-frequency and low-frequency features is captured. The attention mechanism dynamically adjusts the importance of different features by calculating the correlation weights between the features to obtain feature interaction data. The feature interaction data is input into the residual convolution layer group of the dual-branch diffusion network. The residual convolution layer group consists of multiple residual units, and each unit includes a convolution operation and a feature stacking operation. In each residual unit, the features extract local patterns through the convolution kernel and are stacked after a skip connection with the input features, thereby alleviating the vanishing gradient problem in the deep network while retaining the information of the shallow features. After being processed by multiple residual units, residual feature data is generated. The residual feature data is 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 weights of each channel according to the task requirements to highlight the most discriminative features, obtaining channel attention feature data. Based on the channel attention feature data, spatial attention weight allocation is performed to capture the importance of different spatial positions in the image, generating spatial attention feature data. The channel attention feature data and the spatial attention feature data are subjected to cross-layer feature aggregation. By integrating and weighting different-level features, the comprehensiveness and consistency of the feature representation are ensured. Through the global feature summarization operation, all feature information is compressed and refined to generate the final fused animal feature data.

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

[0034] Specifically, based on the fused animal feature data, the feature data of the same animal within a continuous time period is processed through data augmentation techniques. This process includes random cropping, rotation, and flipping transformations, which can simulate image changes under different acquisition conditions, expand the diversity of positive samples, and increase the generalization ability of the model to generate positive sample feature data. Calculate the Euclidean distance between the features of different animal individuals in the fused animal feature data, quantify the similarity degree between different identity features, and represent the results in the form of feature distance sorting data. Through this sorting, identify the top N different identity feature pairs with the smallest distance. These feature pairs are usually difficult to distinguish and are selected as hard samples. For these hard samples, perform feature alignment operations. By uniformly processing the sample features in terms of scale and direction, obtain negative sample feature data, which reflects the similarity features between different identities and improves the discrimination ability for hard samples. Normalize the positive sample feature data and negative sample feature data using the L2 norm to standardize the length of the feature vectors, and calculate the cosine similarity between sample pairs through inner product operations. Cosine similarity is an indicator for measuring the directional similarity of two feature vectors. Apply temperature coefficient weighting to the cosine similarity data. The temperature coefficient is used to control the sensitivity of the feature distribution, thereby adjusting the dynamic range of the similarity. Based on the weighted cosine similarity, calculate the contrast loss value between positive and negative sample pairs to obtain contrast learning loss data. The contrast loss optimizes the feature representation ability and improves the model's performance in distinguishing different identities by reducing the distance between positive sample pairs and increasing the distance between negative sample pairs. To enhance the dynamic adaptation ability of the positive sample feature data, perform exponential moving average calculation on the contrast learning loss data. The exponential moving average method can smooth the fluctuations in the positive sample feature data by weighting historical features and current features, while retaining the trend of feature changes. Set a momentum coefficient to control the update amplitude. The choice of the momentum coefficient directly affects the flexibility and stability of feature updates, generating dynamic feature update data. Based on the dynamic feature update data, perform centroid calculation and feature aggregation operations on the feature vectors of each animal identity. The centroid calculation obtains a clustering center feature data that can represent the overall features of this identity by weighted averaging all sample features. These clustering center features effectively eliminate the interference of noise and outliers through aggregation operations, thus more stably and accurately representing the feature vectors of each animal identity. Organize the feature index corresponding to each animal identity and the clustering center feature vector 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 the animal identity feature template, perform feature extraction and similarity calculation on the real-time animal image sequence to obtain animal identity data.

[0036] Specifically, perform a two-dimensional discrete Fourier transform on the real-time animal image sequence to convert the image from the time domain to the frequency domain representation, in order to analyze the information contained in different frequency components of the image. After the transformation is completed, perform a spectrum separation operation on the frequency domain data, decompose it into a high-frequency part and a low-frequency part, and extract real-time high-frequency feature data and real-time low-frequency feature data respectively. High-frequency data contains detailed information of the image, such as texture and edges, while low-frequency data reflects the overall structure and contour of the image. Input the real-time high-frequency feature data into the high-frequency branch of the dual-branch diffusion network, and convert the original features into a latent space representation adapted to network calculations through feature dimension mapping. In the hierarchical feature extraction module of the high-frequency branch, extract the semantic information of the high-frequency features 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, input the real-time low-frequency feature data into the low-frequency branch of the dual-branch diffusion network, and generate real-time low-frequency latent space data through the feature dimension mapping and hierarchical feature extraction process. The design goal of the low-frequency branch is to capture the global structural information of the image to supplement the deficiencies of local features in the high-frequency branch, thereby ensuring the integrity and diversity of overall feature extraction. Use the real-time high-frequency latent space data and real-time low-frequency latent space data to construct a second attention mapping matrix. Calculate the correlation weights between the latent space data through the attention mechanism, dynamically adjust the importance of features, and fuse the high-frequency and low-frequency features through cross-branch correlation calculations into real-time feature interaction data. Input the real-time feature interaction data into the residual convolution layer group and self-attention module of the dual-branch diffusion network. The residual convolution layer group refines features through the stacking of multiple residual units, and at the same time retains the shallow information through the skip connection mechanism to generate a more robust feature representation. The self-attention module recalibrates the features, dynamically adjusts the importance of each feature dimension, enabling the network to adaptively optimize the feature representation according to the changes in real-time input to obtain real-time fusion feature data. Based on the feature indices and feature vectors in the animal identity feature template, perform L2 norm normalization on the real-time fusion feature data to ensure that the feature vectors have a unified scale. The normalized real-time feature data calculates the similarity with the feature vectors in the feature template through inner product operations to generate identity similarity data, reflecting the matching degree between the real-time input features and each identity feature in the template. After the similarity calculation is completed, set a matching threshold for identity determination. By comparing with the threshold, determine whether the real-time features match a certain identity feature in the template to generate identity determination result data. If the similarity exceeds the set threshold, it is determined as a successful match; otherwise, it is regarded as an unmatched identity. To improve the practicality of the system, associate the identity determination result data with the spatio-temporal information of the corresponding image frame. The recognition result of each image frame is associated with its shooting time and spatial position to generate animal identity data containing spatio-temporal information.

[0037] Temporally sample the animal identity data. By analyzing the identity data in consecutive frames, extract the motion characteristics of each target animal over time, including key parameters such as position, velocity, and acceleration, to generate target motion state data. Initialize the covariance matrix for the target motion state data. This matrix describes the correlation between system state variables and reflects the randomness in the motion process by setting the process noise parameters. At the same time, construct a state transition matrix to describe the evolution relationship of the target animal from the current state to the next state, and generate Kalman filter initialization data based on these parameters. After the Kalman filter initialization is completed, enter the iterative prediction stage. Based on the Kalman filter initialization data, perform prediction operations on the target state to generate estimated values of the predicted position and motion state. At the same time, combine the real-time observation data to correct the state of the prediction results to adjust the errors caused by process noise or inaccurate models. In each iteration, continuously optimize the estimated results of the target state by fusing the prediction and observation data to generate target state prediction data. The iterative nature of the Kalman filter enables it to achieve smooth prediction of the target motion in a noisy environment and dynamically adapt to changes in the target motion. Match the target state prediction data with the current frame detection result data, and calculate the Euclidean distance of each target through position coordinate extraction to quantify their spatial proximity. At the same time, combine the motion direction information to calculate the included angle of the motion direction between the targets. These calculation results are used to generate a target similarity matrix, and each element in the matrix reflects the matching possibility between different targets. On this basis, to determine the trajectory assignment, construct the cost matrix of the Hungarian algorithm based on the target similarity matrix, and perform minimum value normalization processing on the row and column elements of the cost matrix to ensure the numerical stability of the algorithm calculation. The normalized cost matrix is used for the execution of the Hungarian algorithm. By the maximum matching method of the bipartite graph, solve the assignment problem between the targets and the trajectories to generate trajectory matching index data. Perform trajectory break detection on the trajectory matching index data to identify trajectory interruption phenomena caused by short-term occlusion, target loss, or detection failure. For the broken trajectories, use the motion state prediction data for interpolation and completion. By analyzing the motion trends of the trajectories before and after the break, estimate and supplement the missing intermediate trajectory points to generate a complete trajectory sequence. Map the spatio-temporal correspondence relationship between the complete trajectory sequence and the animal identity data, combine each segment of the trajectory with its corresponding animal identity identifier to generate motion trajectory data with animal identity identifiers, and describe the motion laws of the target animals in both the spatial and temporal dimensions.

[0038] In the embodiments of the present invention, by introducing frequency domain decomposition and a dual-branch diffusion network structure, the extraction and fusion processing of high-frequency detail features and low-frequency contour features of animal images are realized, and the discrimination ability of identity features is improved. The attention mechanism and residual structure 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 contrast learning is designed, and by constructing positive and negative sample pairs and mining hard samples, the discrimination ability of the model for similar individuals is improved. By introducing a momentum update mechanism, the dynamic update of feature templates is realized, enabling the model to adapt to small changes in the appearance of animals. Combining Kalman filter prediction and Hungarian algorithm matching effectively solves the problem of trajectory breakage in the case of rapid movement and occlusion of animals. A multi-level feature fusion and spatio-temporal information association strategy is adopted to enhance the temporal consistency of identity recognition results.

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

[0040] Separate the RGB channels and perform pixel normalization mapping on the animal motion image sequence collected by the high-speed camera in the laboratory to obtain normalized animal image data;

[0041] Calculate the local area pixel variance and perform adaptive smoothing intensity adjustment on the normalized animal image data to obtain denoised animal image data;

[0042] Generate a cumulative gray histogram based on the denoised animal image data, and adjust the image contrast distribution through piecewise linear transformation to obtain enhanced animal image data;

[0043] Perform multi-scale adaptive threshold segmentation on the enhanced animal image data to obtain initial mask data, and perform a cascade operation of dilation and erosion on the initial mask data to obtain target mask data;

[0044] Perform region localization on the enhanced animal image data based on the target mask data to obtain localized image data, and perform bilinear interpolation operation on the localized image data to obtain normalized size image data;

[0045] Combine the normalized size image data and the target mask data through a pixel-level cascade structure to generate target animal image data.

[0046] Specifically, separate the RGB channels of the collected image sequence, decompose the three-channel color information of the image into the red channel R(i,j), the green channel G(i,j), and the blue channel B(i,j), where i and j represent the two-dimensional position indices of the image pixels. Perform normalization mapping on the pixel values of each channel through the formula:

[0047]

[0048] Complete the normalization process, where I(i, j) represents the pixel value, and I min and I max are the minimum and maximum values of this channel respectively, and I′(i, j) is the normalized pixel value. The purpose of the normalization operation is to adjust the pixel values to a unified range of [0, 1], thereby reducing the image intensity differences caused by changes in lighting conditions and generating normalized animal image data. Calculate the local area pixel variance for the normalized data, and the calculation formula is:

[0049]

[0050] where σ 2 (i, j) is the local variance centered on the 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). The local pixel variance reflects the distribution of details and noise in the image. Adaptively adjust the smoothing intensity according to the variance size, use bilateral filtering or Gaussian filtering to smooth the high-noise areas while retaining the detail areas, and generate denoised animal image data. Generate a cumulative gray histogram using the denoised data, defined as:

[0053]

[0054] where H c (v) is the cumulative histogram of the pixel gray value v, and h(u) represents the frequency of the pixel value u. Adjust the image contrast distribution through histogram equalization or piecewise linear transformation. For example, use piecewise linear transformation, set the gray value range [v 1 , v 2 to be smoothly stretched to [w 1 , w 2 , and the mapping formula is:

[0055]

[0056] Thereby enhancing the contrast and obtaining enhanced animal image data. Perform multi-scale adaptive threshold segmentation on the enhanced image, and define the segmentation threshold 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 the foreground, otherwise it is classified as the background, obtaining the initial mask data. Perform morphological dilation and erosion operations on the initial mask. Through 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. Through this step, the smoothed target mask data is obtained. After generating the target mask, locate the target area from the enhanced image based on the mask data. By extracting the region bounding box, crop the pixels within the region and perform bilinear interpolation operations to generate image data of a fixed size. The bilinear interpolation formula is:

[0061] I r (x,y)=(1 - a)(1 - b)I(x 1 ,y 1 )+a(1 - b)I(x 2 ,y 1 )+(1 - a)bI(x 1 ,y 2 )+abI(x 2 ,y 2 );

[0062] Where x 1 ,x 2 ,y 1 ,y 2 are the nearest neighbor integer coordinates, a and b are the fractional part weights, and I r (x,y) is the interpolated pixel value, generating the normalized size image data. Combine the normalized size image data and the target mask data at the pixel level, and construct a multi-channel representation through a splicing operation to generate the target animal image data.

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

[0064] Perform frequency domain transformation and frequency centered translation operations on the target animal image data to obtain the centered spectrum data;

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

[0066] Based on the frequency domain amplitude matrix, establish a frequency distribution histogram and perform energy density calculation to obtain the frequency domain energy distribution data;

[0067] Based on the frequency-domain energy distribution data, multiply the frequency-domain amplitude matrix by a high-pass filter and combine it with the phase matrix to obtain high-frequency sub-spectrum data;

[0068] Based on the frequency-domain energy distribution data, multiply the frequency-domain amplitude matrix by a low-pass filter and combine it with the phase matrix to obtain low-frequency sub-spectrum data;

[0069] Perform two-dimensional inverse discrete Fourier transform and time-domain recovery of high-frequency information on the high-frequency sub-spectrum data to obtain high-frequency feature data of the animal image, and perform two-dimensional inverse discrete Fourier transform and time-domain recovery of low-frequency information on the low-frequency sub-spectrum data to obtain low-frequency feature data of the animal image.

[0070] Specifically, for the input target animal image data I(x,y), apply two-dimensional discrete Fourier transform to convert the image from the spatial domain to the frequency domain. The formula for 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. Perform a frequency-centering translation operation on F(u,v) to move the low-frequency components to the center position of the spectrum. The formula for the centering operation is:

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

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

[0075]

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

[0077]

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

[0079]

[0080] By accumulating the amplitudes at different frequencies, the energy density of the frequency distribution is obtained. Multiply the amplitude matrix A(u, v) with the high-pass filter H H (u, v) and the low-pass filter H L (u, v) respectively to separate the high-frequency and low-frequency information. The definition of the high-pass filter is:

[0081]

[0082] where f c is the cut-off frequency of the high-pass filter. Similarly, the definition of the low-pass filter is:

[0083]

[0084] The calculation formula for the high-frequency sub-spectrum data is:

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

[0086] where F H (u, v) is the high-frequency sub-spectrum data. The calculation formula for the low-frequency sub-spectrum data is:

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

[0088] where F L (u, v) is the low-frequency sub-spectrum data. Perform two-dimensional inverse discrete Fourier transform on the high-frequency sub-spectrum data F H (u, v) and the low-frequency sub-spectrum data F L (u, v) respectively to restore the time-domain information. The inverse transform formula is:

[0089]

[0090]

[0091] where I H (x, y) is the high-frequency feature data, IL (x, y) is low-frequency feature data. Through the above process, the high-frequency feature I H (x, y) contains the edge and detail information of the image, such as the texture of animal hair; while the low-frequency feature I L (x, y) contains the overall contour and general shape, such as the morphological structure of the animal body.

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

[0093] Input the high-frequency feature data of the animal image 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;

[0094] Input the low-frequency feature data of the animal image 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;

[0095] Construct a first attention mapping matrix based on the high-frequency feature latent space data and the low-frequency feature latent space data, and perform cross-branch correlation calculation to obtain feature interaction data;

[0096] Input the feature interaction data into the residual convolution layer group of the dual-branch diffusion network, and perform convolution operation and feature superposition in each residual unit of the residual convolution layer group to obtain residual feature data;

[0097] Input the residual feature data into the self-attention module of the dual-branch diffusion network for feature recalibration to obtain channel attention feature data, and perform spatial attention weight allocation based on the channel attention feature data to obtain spatial attention feature data;

[0098] Perform cross-layer feature aggregation and global feature summary on the channel attention feature data and the spatial attention feature data to obtain fused animal feature data.

[0099] Specifically, input the high-frequency feature data of the animal image into the high-frequency branch of the dual-branch diffusion network, and map it from the original high-dimensional feature space to a more suitable latent space representation for calculation through the feature dimension mapping module. Assume that the input high-frequency feature is in matrix form where m and n represent the spatial resolution, and c 1 represents the number of channels, then the feature dimension mapping is realized through a linear transformation, and its formula is:

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

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

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

[0103] where H″ l is the feature map of the l-th layer, W l is the convolutional kernel, * represents the convolutional operation, b l is the bias term, and σ is the activation function (such as ReLU). The stacking of multiple layers of convolutions can gradually extract the edge information and detailed patterns of the high-frequency features, and the output is the high-frequency feature latent space data H″ L . At the same time, the low-frequency feature data of the animal image is input into the low-frequency branch of the dual-branch diffusion network for similar feature dimension mapping and hierarchical feature extraction. Assume that the input low-frequency feature is a matrix Its dimension mapping and feature extraction process are similar to those of the high-frequency branch, and the low-frequency feature latent space data L″ L is obtained. The focus of the low-frequency branch is to extract the overall shape and macroscopic contour information, which complements the detailed information captured by the high-frequency branch. Based on the high-frequency and low-frequency feature latent space data, the first attention mapping matrix is constructed. The attention mechanism dynamically adjusts the contribution values of each feature by calculating the correlation weights between the two sets of features. Assume that the high-frequency latent space data is The low-frequency latent space data is The calculation formula for 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. Through this attention matrix, the cross-branch association of high-frequency and low-frequency features is realized, and the feature interaction data is generated. The feature interaction data is input into the residual convolutional layer group of the dual-branch diffusion network. The residual convolutional layer group contains multiple residual units, and each unit realizes the enhancement and stability of features through the skip connection mechanism. Assume that the input feature is X, and the output of the residual unit is:

[0106] Y=σ(W 1 *X+b 1 )+X;

[0107] where W 1is the convolutional kernel, σ is the activation function, X is the input feature, and the output 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 diffusion network, and the self-attention module performs feature recalibration by reallocating the importance of feature channels. The calculation formula for channel attention is:

[0108] S c = σ(FC 2 (ReLU(FC 1 (GAP(Y)))));

[0109] where FC 1 and FC 2 are fully connected layers, GAP is the global average pooling operation, and S c is the channel attention weight. Based on the channel attention weight, spatial attention weight allocation is performed on the features to generate 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. Through feature aggregation operations, such as weighted summation or concatenation, features at different levels are integrated to generate fused animal feature data F final .

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

[0111] Based on the fused animal feature data, random cropping, rotation, and flipping transformations are performed on the feature data of the same animal within a continuous time period to obtain positive sample feature data;

[0112] Euclidean distance calculations are performed on the features of different animal individuals in the fused animal feature data to obtain feature distance sorting 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 the hard samples are feature-aligned to obtain negative sample feature data;

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

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

[0116] Exponential moving average calculations are performed on the positive sample feature data based on the contrast learning loss data, and a momentum coefficient is set for feature smoothing to obtain dynamic feature update data;

[0117] Update data based on dynamic features, calculate the centroid and aggregate features of the feature vectors for each animal identity to obtain cluster center feature data, and organize the feature indices and feature vectors corresponding to each animal identity into key-value pairs based on the cluster center feature data to obtain the animal identity feature template.

[0118] Specifically, perform data augmentation on the feature data of the same animal within a continuous time period based on the fused animal feature data, increase the diversity of features through random cropping, rotation, and flipping transformations, and simulate the feature changes under different environmental conditions. Assume the input feature data is a matrix F ∈ R m×n×c , where m and n represent the spatial dimensions and c represents the number of channels. Then, random cropping is achieved by setting the 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, y represent the random starting points. Similarly, the rotation transformation is achieved through an image rotation matrix, and the flipping transformation is completed through horizontal or vertical flipping operations. After these augmentation operations, positive sample feature data of the same animal at different time periods is generated. Calculate the Euclidean distance between the features of different animal individuals in the fused animal feature data to quantify the differences between features. Let two feature vectors be f 1 , f 2 ∈R d , and the Euclidean distance calculation formula is:

[0121]

[0122] where f 1,i and f 2,i are the i-th elements of the feature vectors respectively. By calculating and sorting the distances of all feature pairs, the sorted feature distance data is obtained. Based on the sorting result, select the top N different identity feature pairs with the smallest distance values as hard samples. The feature distances of these hard samples are relatively close, and it is difficult for the model to distinguish them, which are the key samples in training. For the selected hard samples, perform feature alignment operations to make the features of all samples have a unified scale and direction. Feature alignment is achieved through mean alignment or normalization, and the formula is:

[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. Perform L2 norm normalization operations on the positive sample feature data and the negative sample feature data respectively, and the normalization formula is:

[0125]

[0126] where is the L2 norm of the feature vector, and f norm is the normalized feature. After normalization, the cosine similarity of positive and negative sample pairs is calculated through the inner product operation, and the formula is:

[0127]

[0128] The value range of the cosine similarity sin is [-1, 1], indicating the direction similarity of two vectors. The cosine similarity data is weighted by the temperature coefficient to adjust the sensitivity of the feature distribution, and the formula is:

[0129]

[0130] where τ is the temperature coefficient, controlling the smoothness of the similarity distribution. Based on the weighted similarity, the contrast loss value between positive and negative sample pairs is calculated, and the common formula is:

[0131]

[0132] where represents the similarity of the positive sample pair, 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 contrast learning loss data, exponential moving average calculation is performed on the positive sample feature data to achieve feature smoothing. Let the momentum coefficient be α, and the update formula for the positive sample feature is:

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

[0134] where f prev and f new are the historical feature and the new feature respectively, and f updated is the updated feature. The momentum coefficient controls the smoothness, and its value range is [0, 1]. Based on the updated feature data, the centroid calculation and feature aggregation are performed on the feature vectors of each animal identity, and the formula is:

[0135]

[0136] where c is the centroid vector and N is the number of samples of this identity. The centroid vector of each identity and the corresponding feature index are organized into key-value pairs to obtain the animal identity feature template.

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

[0138] Perform a two-dimensional discrete Fourier transform and spectral separation on the real-time animal image sequence to obtain real-time high-frequency feature data and real-time low-frequency feature data respectively;

[0139] Input the real-time high-frequency feature data into the high-frequency branch of the dual-branch diffusion network for feature dimension mapping and hierarchical feature extraction to obtain real-time high-frequency latent space data;

[0140] Input the real-time low-frequency feature data into the low-frequency branch of the dual-branch diffusion network for feature dimension mapping and hierarchical feature extraction to obtain real-time low-frequency latent space data;

[0141] Construct a second attention mapping matrix based on the real-time high-frequency latent space data and the real-time low-frequency latent space data, and perform cross-branch correlation calculation to obtain real-time feature interaction data;

[0142] Input the real-time feature interaction data into the residual convolution layer group and self-attention module of the dual-branch diffusion network for feature fusion and recalibration to obtain real-time fusion feature data;

[0143] Based on the feature indices and feature vectors in the animal identity feature template, perform L2 norm normalization and inner product operation on the real-time fusion feature data to obtain identity similarity data;

[0144] Set a matching threshold for the identity similarity data for identity determination to obtain identity determination result data, and associate the identity determination result data with the spatio-temporal information of the corresponding image frame to generate animal identity data.

[0145] Specifically, perform a two-dimensional discrete Fourier transform 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) is the frequency domain data, I(x,y) represents the pixel value of the input image, M and N are the width and height of the image respectively, and u,v are the frequency domain coordinates. Perform spectral separation on the frequency domain data to decompose it into high-frequency components and low-frequency components. The high-frequency component F H (u,v) mainly contains the detailed information of 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:

[0150]

[0151] where f c is the cut-off frequency. By separately calculating F H (u, v) = F(u, v) · H H (u, v) and F L (u, v) = F(u, v) · H L (u, v), real-time high-frequency feature data and real-time low-frequency feature data are obtained. The real-time high-frequency feature data is 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 the high-frequency feature data, W H is the mapping weight matrix, b H is the bias vector, σ is the activation function (such as ReLU), and H′ is the mapped high-frequency latent space data. The mapped features are used to extract hierarchical features through a series of convolutional operations, and the formula is:

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

[0155] where H″ l is the high-frequency feature map of the l-th layer, W l is the convolution kernel, and * represents the convolution operation. Similarly, the real-time low-frequency feature data is input into the low-frequency branch of the dual-branch diffusion network for similar dimension mapping and hierarchical feature extraction to generate the low-frequency latent space data L″ L . The high-frequency and low-frequency latent space data respectively represent the details and global features of the image. Based on the real-time high-frequency latent space data and real-time 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 attention mapping is:

[0156]

[0157] where A(i, j) is the attention weight, indicating the correlation between the high-frequency and low-frequency features at a specific position. Through the attention mechanism, the two types of features are dynamically fused into 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 to refine and fuse the features. The feature enhancement formula of the residual convolutional layer group is:

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

[0159] where X is the input feature, W 1 is the convolution kernel, and b 1 is the bias term. The self-attention module performs recalibration through channel attention and spatial attention. The calculation of channel attention is as follows:

[0160] S c = σ(FC 2 (ReLU(FC 1 (GAP(Y)))));

[0161] where GAP is global average pooling, FC 1 , FC 2 are fully connected layers, and S c is the channel attention weight. Spatial attention redistributes weights through positional relationships. After the real-time fusion feature data is generated, it is matched with the feature vectors in the animal identity feature template. The fusion feature data is normalized by L2 norm, and the formula is:

[0162]

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

[0164]

[0165] where T norm is the template feature vector. A matching threshold τ is set for the similarity. When sim ≥ τ, it is determined that the matching is successful. The identity determination result is associated with the time and space information of the image frame, and by recording the frame number and coordinates, animal identity data with spatio-temporal information is generated.

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

[0167] Perform temporal sampling and motion parameter extraction on the animal identity data to obtain target motion state data;

[0168] Initialize the covariance matrix and construct the state transition matrix for the target motion state data, and set the process noise parameter to obtain the Kalman filter initialization data;

[0169] Perform iterative prediction operations on the target state based on the Kalman filter initialization data, and at the same time perform state correction in combination with the observation data to obtain the target state prediction data;

[0170] Extract the position coordinates from the target state prediction data and the current frame detection result data, and calculate the Euclidean distance and the angle of the motion direction to obtain the target similarity matrix;

[0171] Construct a cost matrix for the Hungarian algorithm based on the target similarity matrix, perform minimum normalization on the row and column elements of the cost matrix to obtain a normalized cost matrix, execute the Hungarian algorithm on the normalized cost matrix, and perform trajectory assignment calculation through the maximum bipartite matching method to obtain trajectory matching index data;

[0172] Perform trajectory break detection on the trajectory matching index data, interpolate and complete the broken trajectories based on motion state prediction to obtain a complete trajectory sequence, and map the spatio-temporal correspondence relationship between the complete trajectory sequence and the animal identity data to generate motion trajectory data with animal identity tags.

[0173] Specifically, perform temporal sampling on the animal identity data to extract motion features in consecutive time frames. Assume that the motion trajectory data of the animal consists of identity data at T time steps, and each frame records its position coordinates (x t , y t ) and velocity v t . By sampling the time series, extract the motion parameters of the animal at key time points, including the instantaneous velocity v t and acceleration a t . The formula for velocity is:

[0174]

[0175] where (x t , y t ) and (x t-1 , y t-1 ) are the coordinates of the current frame and the previous frame, and Δt is the time interval. Similarly, acceleration is calculated through 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 is used as the input for subsequent state estimation and prediction. Based on the target motion state data, initialize the covariance matrix and construct the state transition matrix. 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 are the initial uncertainties of 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 maps the current state [x, y, v x , v y to the state at the next moment. Additionally, the process noise parameter Q is set to reflect the 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 are the covariances of the process noise. Based on these parameters, the Kalman filter is initialized. During the iterative process of the Kalman filter, it is divided into two stages: prediction and correction. In the prediction stage, the state at the next moment is predicted using the state transition matrix:

[0184]

[0185] where is the predicted state and w is the process noise. In the correction stage, the predicted state is updated by combining the observation data Z t :

[0186]

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

[0188]

[0189] And the formula for the direction angle is:

[0190]

[0191] where and are the velocity vectors of the two targets. Based on these data, a target similarity matrix is constructed. The cost matrix of the Hungarian algorithm is constructed using the target similarity matrix, and the matrix is normalized by the minimum value, with the formula:

[0192]

[0193] where C is the original cost matrix, and C ′ is the normalized matrix. By performing the Hungarian algorithm and using the maximum matching method of the bipartite graph for trajectory assignment calculation, trajectory matching index data is obtained. 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 and completion. Assume the states before and after the trajectory break are (x 1 , y 1 ) and (x 2 , y 2 ), and the interpolation formula is:

[0194]

[0195] where t 1 , t 2 , and t are the times before, after the break, and the interpolation point respectively. Through completion, a complete trajectory sequence is generated. The complete trajectory sequence is mapped to the spatio-temporal correspondence relationship with the animal identity data. By recording the time and position coordinates of each frame, an animal identity identifier is associated with each trajectory, and motion trajectory data with animal identity identifiers is generated.

[0196] The above describes the method for identifying the identity of laboratory animals based on image recognition in the embodiments of the present invention. Next, the system for identifying the identity of laboratory animals based on image recognition in the embodiments of the present invention will be described. Please refer to Figure 2 , an embodiment of the system for identifying the identity of laboratory animals based on image recognition in the embodiments of the present invention includes:

[0197] A preprocessing module for preprocessing the animal motion image sequence collected by a high-speed camera in the laboratory to obtain target animal image data;

[0198] A transformation module for performing two-dimensional discrete Fourier transform and inverse Fourier transform on the target animal image data to obtain animal image high-frequency feature data and animal image low-frequency feature data;

[0199] A feature processing module for respectively inputting the animal image high-frequency feature data and the animal image low-frequency feature data into a dual-branch diffusion network for feature processing to obtain fused animal feature data;

[0200] A construction module for constructing positive sample pairs based on the fused animal feature data, constructing negative sample pairs through hard sample mining, calculating feature distances based on cosine similarity and performing momentum update to obtain an animal identity feature template;

[0201] A calculation module, configured to perform feature extraction and similarity calculation on a real-time animal image sequence based on a dual-branch diffusion network and an animal identity feature template, so as to obtain animal identity data.

[0202] Through the collaborative cooperation of the above-mentioned various components, by introducing frequency-domain decomposition and a dual-branch diffusion network structure, the separate extraction and fusion processing of the high-frequency detail features and low-frequency contour features of animal images are realized, and the discrimination ability of identity features is improved. The attention mechanism and residual structure 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, and by constructing positive and negative sample pairs and mining hard samples, the discrimination ability of the model for similar individuals is improved. By introducing a momentum update mechanism, the dynamic update of the feature template is realized, enabling the model to adapt to the slight changes in the appearance of animals. Combining Kalman filter prediction and Hungarian algorithm matching effectively solves the problem of trajectory breakage in the case of rapid movement and occlusion of animals. The multi-level feature fusion and spatio-temporal information association strategy are adopted to enhance the temporal consistency of the identity recognition result.

[0203] Refer to Figure 3 , in an embodiment of the present invention, a computer device is further provided. The computer device may be a server, and its internal structure may be as Figure 3 shown. The computer device includes a processor, a memory, a display screen, an input device, a network interface, and a database connected through a system bus. Among them, the processor of the computer design is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store the corresponding data in this embodiment. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the above method is implemented.

[0204] Those skilled in the art can understand that Figure 3 the structure shown in

[0205] is only a block diagram of a part of the structure related to the solution of the present invention, and does not constitute a limitation on the computer device to which the solution of the present invention is applied.

[0206] Those of ordinary skill in the art can understand that all or part of the processes of implementing the methods in the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, storage, database, or other medium provided by the present invention and used in the embodiments can include non-volatile and / or volatile memories. 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), double data rate SDRAM (SSRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), Rambus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM, etc.

[0207] Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working processes of the above-described systems, systems, and units can refer to the corresponding processes in the foregoing method embodiments and will not be described herein again.

[0208] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an 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. The computer software product is stored in a storage medium and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The foregoing storage medium includes: USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs, etc., which can store program codes.

[0209] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, rather than limiting it; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A laboratory animal identification method based on image recognition, characterized in that: The method comprises: Preprocess the animal motion image sequence collected by the high-speed camera in the laboratory to obtain the target animal image data; Performing a two-dimensional discrete Fourier transform and an inverse Fourier transform on the target animal image data to obtain high-frequency feature data of the animal image and low-frequency feature data of the animal image; Inputting the high-frequency feature data of the animal image and the low-frequency feature data of the animal image into a double-branch diffusion network for feature processing respectively to obtain fused animal feature data; Constructing positive sample pairs based on the fused animal feature data, constructing negative sample pairs through difficult sample mining, calculating feature distance based on cosine similarity and performing momentum update, and obtaining an animal identity feature template; Based on the dual-branch diffusion network and the animal identity feature template, feature extraction and similarity calculation are performed on the real-time animal image sequence to obtain animal identity data.

2. The method for identifying laboratory animals based on image recognition according to claim 1, characterized in that: The method of preprocessing the animal motion image sequence collected by the high-speed camera in the laboratory to obtain the target animal image data includes: The animal motion image sequence collected by the high-speed camera in the laboratory is subjected to RGB channel separation and pixel normalization mapping to obtain normalized animal image data; Performing local area pixel variance calculation and adaptive smoothing intensity adjustment on the normalized animal image data to obtain denoised animal image data; Generating a cumulative grayscale histogram based on the denoised animal image data, and adjusting the image contrast distribution by piecewise linear transformation to obtain enhanced animal image data; Performing multi-scale adaptive threshold segmentation on the enhanced animal image data to obtain initial mask data, and performing dilation and erosion cascade operations on the initial mask data to obtain target mask data; Based on the target mask data, a region is located in the enhanced animal image data to obtain location image data, and a bilinear interpolation operation is performed on the location image data to obtain normalized size image data; The normalized size image data and the target mask data are combined in a pixel cascade structure to generate target animal image data.

3. The method for identifying laboratory animals based on image recognition according to claim 2, characterized in that: The performing of 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 includes: Performing frequency domain conversion and frequency centering translation operation on the target animal image data to obtain centralized spectrum data; Performing complex operations on the centralized spectrum data, calculating the square sum of the real part and the imaginary part and the phase angle, and obtaining a frequency domain amplitude matrix and a phase matrix; Establishing a frequency distribution histogram based on the frequency domain amplitude matrix, and performing energy density calculation to obtain frequency domain energy distribution data; Based on the frequency domain energy distribution data, multiplying the frequency domain amplitude matrix with a high pass filter and combining it with the phase matrix to obtain high frequency sub-spectrum data; Based on the frequency domain energy distribution data, multiplying the frequency domain amplitude matrix with a low-pass filter and combining it with the phase matrix to obtain low-frequency sub-spectrum data; The high-frequency sub-spectrum data is subjected to two-dimensional inverse discrete Fourier transform and high-frequency information time-domain restoration to obtain high-frequency feature data of the animal image, and the low-frequency sub-spectrum data is subjected to two-dimensional inverse discrete Fourier transform and low-frequency information time-domain restoration to obtain low-frequency feature data of the animal image.

4. The method for identifying laboratory animals based on image recognition according to claim 3, characterized in that: The step of inputting the high-frequency feature data of the animal image and the low-frequency feature data of the animal image into a double-branch diffusion network for feature processing to obtain fused animal feature data comprises: Inputting the high-frequency feature data of the animal image 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; Inputting the low-frequency feature data of the animal image 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; Constructing a first attention mapping matrix based on the high-frequency feature latent space data and the low-frequency feature latent space data, and performing cross-branch association calculation to obtain feature interaction data; Inputting the feature interaction data into a residual convolution layer group of a dual-branch diffusion network, performing convolution operation and feature superposition in each residual unit of the residual convolution layer group, and obtaining residual feature data; Inputting the residual feature data into the self-attention module of the dual-branch diffusion network for feature recalibration to obtain channel attention feature data, and performing spatial attention weight allocation based on the channel attention feature data to obtain spatial attention feature data; Cross-layer feature aggregation and global feature summary are performed on the channel attention feature data and the spatial attention feature data to obtain fused animal feature data.

5. The method for identifying laboratory animals based on image recognition according to claim 4, characterized in that: The method constructs positive sample pairs based on the fused animal feature data, constructs negative sample pairs by mining difficult samples, calculates feature distance based on cosine similarity and performs momentum update 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; Performing Euclidean distance calculation on 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 first N different identity feature pairs with the smallest distance values ​​are selected as difficult samples, and feature alignment is performed on the difficult samples to obtain negative sample feature data; Performing L2 norm normalization and inner product operation 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 a contrast loss value between feature pairs is calculated to obtain contrast learning loss data; Based on the contrastive learning loss data, an exponential sliding average calculation is performed on the positive sample feature data, and a momentum coefficient is set to perform feature smoothing to obtain dynamic feature update data; Based on the dynamic feature update data, the feature vector of each animal identity is subjected to centroid calculation and feature aggregation to obtain cluster center feature data, and based on the cluster center feature data, the feature index and feature vector corresponding to each animal identity are organized into a key-value pair form to obtain an animal identity feature template.

6. The method for identifying laboratory animals based on image recognition according to claim 5, characterized in that: The method of extracting features and calculating similarity of real-time animal image sequences based on the dual-branch diffusion network and the animal identity feature template to obtain animal identity data includes: Perform two-dimensional discrete Fourier transform and spectrum separation on real-time animal image sequences to obtain real-time high-frequency feature data and real-time low-frequency feature data respectively; Inputting the real-time high-frequency feature data into the high-frequency branch of the dual-branch diffusion network, performing feature dimension mapping and hierarchical feature extraction, and obtaining real-time high-frequency latent space data; Inputting the real-time low-frequency feature data into the low-frequency branch of the dual-branch diffusion network, performing feature dimension mapping and hierarchical feature extraction, and obtaining real-time low-frequency latent space data; Constructing a second attention mapping matrix based on the real-time high-frequency latent space data and the real-time low-frequency latent space data, and performing cross-branch association calculation to obtain real-time feature interaction data; The real-time feature interaction data is input into the residual convolution layer group and the self-attention module of the dual-branch diffusion network to perform feature fusion and recalibration to obtain real-time fused feature data; Based on the feature index and feature vector in the animal identity feature template, performing L2 norm normalization and inner product operation on the real-time fusion feature data to obtain identity similarity data; A matching threshold is set for the identity similarity data to perform identity determination to obtain identity determination result data, and the identity determination result data is associated with the spatiotemporal information of the corresponding image frame to generate animal identity data.

7. The method for identifying laboratory animals based on image recognition according to claim 6, characterized in that: The laboratory animal identification method based on image recognition also includes: Performing time series sampling and motion parameter extraction on the animal identity data to obtain target motion state data; Initializing the covariance matrix and constructing the state transfer matrix of the target motion state data, and setting process noise parameters to obtain Kalman filter initialization data; Performing an iterative prediction operation on the target state based on the Kalman filter initialization data, and performing state correction in combination with the observation data to obtain target state prediction data; Extracting the position coordinates of the target state prediction data and the current frame detection result data, and calculating the Euclidean distance and the motion direction angle to obtain a target similarity matrix; A 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 to the minimum value to obtain a normalized cost matrix, the Hungarian algorithm is executed on the normalized cost matrix, and trajectory allocation calculation is performed through a bipartite graph maximum matching method to obtain trajectory matching index data; The trajectory matching index data is subjected to trajectory breakage detection, and the broken trajectory is interpolated and completed based on the motion state prediction to obtain a complete trajectory sequence, and the complete trajectory sequence is mapped with the animal identity data in a time-space correspondence relationship to generate motion trajectory data with an animal identity identifier.

8. A laboratory animal identification system based on image recognition, characterized in that: Used to perform the laboratory animal identification method based on image recognition as described in any one of claims 1 to 7, the laboratory animal identification system based on image recognition comprises: A preprocessing module is used to preprocess the animal motion image sequence collected by a high-speed camera in the laboratory to obtain target animal image data; A transformation module, used for performing a two-dimensional discrete Fourier transform and an inverse Fourier transform on the target animal image data to obtain high-frequency feature data and low-frequency feature data of the animal image; A feature processing module, used for inputting the high-frequency feature data of the animal image and the low-frequency feature data of the animal image into a double-branch diffusion network for feature processing to obtain fused animal feature data; A construction module is used to construct positive sample pairs based on the fused animal feature data, construct negative sample pairs by mining difficult samples, calculate feature distances based on cosine similarity and perform momentum updates to obtain animal identity feature templates; The calculation module is used to extract features and calculate similarity of real-time animal image sequences based on the dual-branch diffusion network and the animal identity feature template to obtain animal identity data.

9. A computer device, characterized in that: It comprises a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and is characterized in that when the processor executes the computer program, the laboratory animal identification method based on image recognition described in any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the processor is enabled to execute the laboratory animal identification method based on image recognition according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Animal identity recognition method, device and system

    CN112785620A

  • Face image restoration method and device based on diffusion generation prior and readable medium

    CN117495714A

  • Double-branch unsupervised target re-identification method and system based on sample mining

    CN118351340A

  • Video analysis method and system of monitoring terminal

    CN118781526A

  • Method and system for automatically detecting defects of semiconductor chip based on hyperspectral imaging

    CN119417838A

Cited By

  • Face fusion method and device based on parallel denoising, equipment and medium

    CN120748026A

  • Face fusion method and device based on parallel denoising, equipment and medium

    CN120748026B

  • Identity recognition and authentication system based on machine vision three-dimensional features

    CN121838211A

  • Identity recognition and authentication system based on machine vision three-dimensional features

    CN121838211B