Abstract
Accurate identification of the big and small ends of poultry eggs is a crucial step in automatic packaging of poultry eggs in trays. In the actual packaging process, some factors, such as uneven surface brightness, different eggshell colors, and differences in ends and shape, have a negative impact on recognition accuracy. In this study, three kinds of eggs with red-shell, white-shell, and green-shell were used as the research object. After image acquisition, the contrast stretching method was utilized to correct the brightness of the collected egg images, and the U-Net network was utilized to achieve egg body region segmentation and complex background removal. The A2C2f_RCSOSA, EUCB, and CSFCN modules were introduced for improvement in YOLOv12. The results showed that the RCCS12 model had the best overall performance. Its precision, recall, and mAP@0.5 reached 99.5%, 99.4%, and 99.5%, respectively. Compared to RepVitASF12 (i.e., a superior model for egg recognition in our previous research), RCCS12 maintains high precision while having lower FLOPs, model size, and inference time. The overall results indicated that the integration of reasonable brightness correction and recognition detection algorithms can effectively solve the problem of big and small ends recognition, providing a reference for the automatic egg packaging process.
1. Introduction
Poultry eggs are an important animal-derived food in the daily dietary structure of residents, with high nutritional value, stable consumer demand, and wide coverage of the industrial chain. Among them, as a typical representative of poultry egg products with significant production and consumption volumes, eggs are not only important raw materials for fresh consumption and food processing, but also the main focus of research on automated packaging of poultry eggs. During the automated packaging process of eggs, precisely adjusting the big and small ends of eggs is the key to ensuring the quality and freshness of the eggs [1,2]. Previous studies have shown that identifying the big and small ends of eggs using machine vision and deep learning methods is feasible. By collecting appearance images of eggs, combined with target detection, image classification, and feature extraction models, it is possible to effectively obtain the difference information between the big and small ends of eggs and achieve automatic discrimination of the big and small ends of eggs, achieving high recognition precision. However, during the actual image acquisition process, due to the influence of the light source arrangement, the color of the eggshell, and the spherical surface characteristics of the egg, the surface of the egg often shows uneven brightness distribution or shadow areas, leading to interference with the edge contours and detailed features of the big and small ends of eggs. Especially for egg images with small differences in the big and small ends and shape, uneven brightness will further increase the difficulty of feature extraction in the model, reducing the stability and robustness of the big and small ends recognition. Therefore, based on existing visual recognition research, further studies on correcting uneven surface brightness of eggs and optimizing the precision of big and small ends recognition have strong theoretical significance and practical application value.
Regarding the issue of uneven brightness in images, existing studies have mainly focused on image enhancement and brightness correction methods, improving the brightness uniformity and detail feature expression ability of images through brightness adjustment, gamma correction, multi-scale fusion, filtering enhancement, and adaptive lighting compensation. This has enhanced the ability of object detection and recognition. Wang et al. [3] proposed a method that combines the alternating minimization scheme and the augmented Lagrangian method to correct images with uneven brightness, and achieved good results. Li et al. [4] proposed an image enhancement technique based on multi-scale fusion to solve the problem of dark images caused by uneven brightness during crop processing in enclosed spaces. This technique has achieved good results in improving the visual quality, brightness uniformity, and color accuracy of images. Severoglu et al. [5] proposed an image correction scheme based on Y-I-Q transformation and least squares bilateral filtering, which can present dark images with better visual quality and color. Li [6] used dual-scale adaptive gamma correction to solve the problems of low-brightness images with dim brightness and uneven local lighting. Chen et al. [7] proposed an adaptive brightness adjustment image enhancement method, which restored more color and detail information for low-brightness images. Lv et al. [8] used an adaptive correction method based on regional brightness to solve the sensitivity of image automatic detection methods to illumination changes, which can provide a reference for crop picking operations under natural lighting conditions. Wang et al. [9] proposed an adaptive brightness correction algorithm based on the improved two-dimensional gamma function, which increases the brightness value of images in areas with dark lighting and reduces the brightness value of images in areas with strong lighting, ultimately obtaining an enhanced image. The results indicate that the algorithm can effectively reduce the impact of uneven lighting and improve image quality.
With the development of deep learning technology, image enhancement and brightness correction methods based on convolutional neural networks, generative networks, and attention mechanisms are gradually receiving attention. Deep learning methods can automatically perform image brightness correction through data-driven methods, exhibiting stronger feature expression ability and scene adaptability under complex lighting conditions. Jia et al. [10] proposed a robust Retinex model based on reflectance map reweighting, which can effectively balance image brightness. Tian et al. [11] proposed a fusion method based on variational adaptive enhancement of non-uniform illumination images, which achieves color balance between globally enhanced images and locally enhanced images. Wang et al. [12] proposed an effective fully convolutional network for directly correcting uneven lighting images; this network not only achieves brightness correction but also retains more image details. Wang et al. [13] proposed a Convolutional Neural Network (CNN) guided by dynamic gamma correction for crop image detection under uneven lighting, significantly improving the quality and recognition detection precision of uneven brightness images. Jiang et al. [14] proposed an efficient unsupervised generative adversarial network, EnlightenGAN, which achieved significant success in balancing low-brightness photos and normal light photos. Fan et al. [15] proposed a multi-scale dynamic fusion method to correct images with uneven illumination. This method can balance the overall illumination of images with uneven illumination while maintaining the original brightness contrast and enhancing the image details. Lin et al. [16] proposed two CNN-based methods for image enhancement under uneven brightness illumination; the proposed methods significantly outperformed the comparison methods in improving image quality. Serdar [17] proposed an adaptive multi-branch feature fusion method that achieves brightness unevenness correction while maintaining structural integrity and color. Zhang et al. [18] introduced a simple and effective Retinex decomposition strategy to solve the problem of brightness adjustment in images. Chao et al. [19] proposed a Correcting Uneven Illumination Network (CUI Net) that effectively extracts features from low-light areas by constraining highlight features. Qiu et al. [20] proposed a joint prior-based non-uniform illumination enhancement (JPUIE) method, which accurately and effectively eliminates non-uniform illumination and avoids information loss in enhanced images. Lei et al. [21] proposed a network model based on deep learning and Retinex theory. Experimental results show that the proposed algorithm effectively improves the contrast of images with uneven brightness while solving the problems of detail loss and color distortion. Huang et al. [22] designed a three-branch asymmetric exposure fusion network (TAFNet) to solve the problems of uneven image brightness, noise amplification, and color distortion.
The big and small ends of egg recognition not only require improving the impact of uneven image brightness on visual information extraction, but also accurately identifying key visual features such as the overall contour, end shape, and subtle differences in the egg body. At the same time, it should achieve the effective extraction of egg targets under complex background conditions. Deep learning methods can adaptively extract deep morphological and detailed information related to the big and small ends of the egg, providing technical support for improving recognition accuracy [23]. At present, many studies have applied deep learning techniques to characterize differences in target object contours and extract subtle visual features, and achieved good results. Fang et al. [24] proposed a new local contrast loss method for learning object contour features, and the edge detection network trained using local contrast loss achieved high accuracy. Zhou et al. [25] proposed an extended branch cascade structure and created a new architecture from the perspective of deep edge detection to adapt to edge contour detection tasks. Wang et al. [26] proposed a novel dual-branch attention fusion detection model (DAF-C) based on Canny-assisted supervision, which effectively improves the ability to recognize complex edge structures. Cai et al. [27] proposed an adaptive sensitivity-based adjustment model (ASR) that enhances the adaptability of color image edge contours. Wang et al. [28] proposed a new attention network (MPSA) for classification recognition, and the proposed MPSA achieved good results in the identification of subtle features. Liu et al. [29] proposed a dual attention-guided multi-scale CNN for image classification, achieving key localization of images and detail capture of local regions. Lu et al. [30] proposed a new LSI learning module to add to the backbone network in order to enhance the ability of the network to discover subtle features and obtained good results. Liu et al. [31] proposed a cross-layer mutual attention learning network (CMAL Net). This solves the problem of neglecting deep detail information in the target area. Yu et al. [32] proposed the PHI module and the CFL module to help the network obtain more detailed local feature information.
The above research indicates that traditional image enhancement and brightness correction methods can, to some extent, solve the problem of uneven brightness distribution, providing a foundation for improving image quality and target recognizability; the brightness correction method based on deep learning can balance brightness and restore details, demonstrating stronger adaptability in lighting scenes. Meanwhile, studies related to target contour features and edge detection have shown that deep learning networks can effectively extract local features, morphological changes, and subtle differences in the target, providing support for the precise identification of similar categories. However, most of the existing studies focus on low-light image enhancement, crop detection, or fine-grained classification tasks. There is still a relative lack of collaborative research addressing issues such as uneven brightness on the egg surface, background interference, and subtle differences in the shape of the big and small ends of the egg. Based on this, this study applies deep learning techniques to the tasks of correcting uneven brightness on the surface of eggs and big and small ends recognition, in order to improve the accuracy and robustness of the big and small ends recognition under different lighting conditions.
This study focuses on the problem of correcting uneven surface brightness of eggs and optimizing the precision of big and small ends recognition. A multi-module fusion-improved model, RCCS12, was designed and implemented, and the technical roadmap was shown in Figure 1. This study mainly includes image preprocessing, model optimization, and performance evaluation. Based on this framework, the main objectives of this study were as follows: (1) Correction of uneven surface brightness of eggs. By combining the contrast stretching method with the U-Net segmentation network, the interference from complex backgrounds was eliminated, and the clarity of the egg edge contour was improved, providing a high-quality dataset for subsequent model training; (2) Implement a multi-module cross-fusion strategy. The A2C2f_RCSOSA, EUCB, and CSFCN modules were introduced to solve the problem of difficult recognition of subtle features and color discrimination at the big and small ends; (3) Comparative analysis through ablation experiments. The impact of the A2C2f_RCSOSA, EUCB, and CSFCN modules on recognition performance was evaluated to obtain a good detection model.
Figure 1.
The technology roadmap.
2. Materials and Methods
2.1. Data Acquisition System and Samples
The system and data collection work built for this study were completed during the period from March to May 2026. The image acquisition system in this study consists of a computer, conveyor rollers (Xianghe Jinbi Sheng Metal Products Co., Ltd., Langfang, China), two cameras (MV-CS060-10GC, Hangzhou Hikvision Digital Technology Co., Ltd., Hangzhou, China), a light source controller (KM-DCS 2.0-2 C 030 W-24 PS, Dongguan KOMA Visual Technology Co., Ltd., Dongguan, China) and a light source (WTX-LLR2-400X20W, Zhejiang Wang Student Technology Co., Ltd., Taizhou, China). As shown in Figure 2a,b, two cameras are arranged above the conveyor roller. The vertical distance between the cameras and the conveyor roller is about 25 cm, and the angle with the plane of the conveyor roller is about 50°. To ensure the stability of lighting conditions during image acquisition, an adjustable linear light source is installed on the bracket below the camera, vertically arranged about 22 cm above the conveyor roller, with an angle of about 40° between the light source and the plane of the conveyor roller. During the experiment, the eggs were placed horizontally on the conveyor roller and moved at a constant speed of 0.3 m/s along with the conveyor roller; the image acquisition was completed through the Hikvision MVS client.
Figure 2.
Image data collection platform. (a) Side-view structure and device position parameters. (b) Front-view structure and physical device.
The eggs used in the experiment were purchased from two supermarkets in Beijing; the sample types included red-shell eggs, white-shell eggs, and green-shell eggs. Due to the differences in appearance features and edge contours of eggs with different shell colors, and to improve the model’s ability to identify the big and small ends of eggs, this study further divided the samples based on the color and size of the eggshell, and set a total of 6 recognition categories: the big ends of red-shelled eggs, the small ends of red-shelled eggs, the big ends of white-shelled eggs, the small ends of white-shelled eggs, the big ends of green-shelled eggs, and the small ends of green-shelled eggs. In the following text, the experimental results for these categories are denoted by BRE, SRE, BWE, SWE, BGE, and SGE, respectively. During the data collection stage, full consideration was given to the changes in egg image features under different lighting conditions. The experiment included three lighting environments with different intensities, as shown in Figure 3. For red-shell, white-shell, and green-shell eggs, 200 images were collected for each color of egg, resulting in a total of 600 original egg images. By introducing multi-intensity lighting conditions, the coverage range of the dataset for actual lighting changes has been enhanced, and the diversity and representativeness of the samples have been improved.
Figure 3.
Image samples. Original images and the images after contrast stretching.
2.2. Egg Surface Uneven Brightness Correction
Due to the elliptical shape of eggs, there are significant differences in the degree of reflection in different areas of the egg under the same lighting intensity conditions, which can lead to uneven brightness distribution on the surface of the egg in the image. In addition, with differences in the emission angle of the light source, this uneven brightness phenomenon will become even more severe. These unfavorable factors may cause problems such as blurred target boundaries and missing local contours, thereby affecting the precision of subsequent egg external contour feature extraction and big and small ends recognition. In order to obtain more stable and reliable image data and reduce the impact of lighting changes and complex background interference on recognition results, this study first performs brightness unevenness correction on the collected images in the image preprocessing stage to improve the consistency of the grayscale distribution on the egg surface, enhance the discrimination between the target area and the background, and improve the clarity of the edge contour.
2.2.1. Contrast Stretching and Image Annotation
This study used the contrast stretching method to enhance color images in the image preprocessing stage, as shown in Figure 3. Firstly, component extraction is performed on the collected egg color images to obtain grayscale images for subsequent processing. The parameter settings of the imadjust function are adjusted to some extent, thereby enhancing the distinction between the egg target area and the background area, and improving the visual brightness and detail presentation of the dimly lit images. In order to obtain a high-quality egg target segmentation dataset, this study used manual annotation to accurately label the egg target area in the collected images. Firstly, the preprocessed egg image is imported into Labelme annotation software (Labelme 3.16.7). Based on the external contour of the egg, the target area is delineated point by point, and the annotation boundary is kept as consistent as possible with the true edge of the egg to reduce the interference of background, shadow, and reflective areas on the segmentation results. After the annotation is completed, the software automatically generates a JSON-format annotation file corresponding to the original image, which includes information such as the target category, contour coordinates, and image size, as shown in Figure 4a,b. Because training deep learning segmentation models usually requires pixel-level label maps as input, it is necessary to further convert the .json annotation files generated by Labelme [33] into .png-format segmentation label maps, as shown in Figure 4a. During the conversion process, the egg target area is assigned a fixed pixel value, and the background area is set to another pixel value, thus forming a label image that distinguishes the target from the background. Through this method, segmentation label data corresponding one-to-one with the original image can be obtained, providing standardized data for subsequent training of U-Net image segmentation models.
Figure 4.
Image data processing and network structure.(a) Annotation of egg image segmentation data. (b) An example of the JSON file. (c) The U-net network structure.
2.2.2. U-Net
The U-Net network is a typical encoder–decoder structure semantic segmentation model, featuring a clear structure, strong feature extraction capability, and excellent pixel-level segmentation performance. This network extracts deep semantic features of the image layer by layer through an encoder, and gradually restores the spatial resolution of the image using a decoder, thereby achieving precise localization and segmentation of the target area. Meanwhile, the U-Net network introduces a skip connection structure between the encoder and decoder, fusing shallow edge detail features with deep semantic features, effectively compensating for the problem of spatial information loss during downsampling, and improving the integrity and accuracy of target boundary segmentation. In this study, the U-Net network mainly uses manually annotated segmentation labels as input information for training. The model can learn the different features between the egg region and the background region, and finally generate a PTH weight file, as shown in Figure 4c.
2.2.3. Mask with the Original Image Fusion
To ensure consistency between the segmentation results and the original image size, and to improve the stability of subsequent image processing, this study scales the preprocessed image size while maintaining the original aspect ratio, reducing the computational load in the segmentation inference process; subsequently, the scaled image is sequentially padded to ensure that its height and width meet the size requirements of network inference and post-processing, avoiding boundary mismatch problems. In response to the problem that the surface of the conveyor roller is relatively smooth and prone to local high-brightness reflective areas under strong light or different incident angles, this study used the brightness characteristics of each component of the RGB image to threshold screen high pixel value areas. The areas that meet the high brightness conditions are identified as potential reflective areas and suppressed to reduce the interference of background reflection on the segmentation results. In the post-processing stage of the segmentation mask, the Gaussian smoothing method is used to improve the aliasing phenomenon of the target edge, and the optimized mask is restored to the original image size. Merge and segment the single-channel mask with the original image. In this process, the egg target area retains a higher mask response while the background area is suppressed. Eventually, an egg target image with consistent size, complete edges, and background removal is obtained.
2.2.4. Dataset Expansion
To improve the generalization ability and robustness of the model, data augmentation was performed on the egg images after removing the background. After expansion, the number of images for each type of egg increased to 2000, resulting in a total of 6000 egg images. Subsequently, the LabelImg tool was used to manually label the dataset, locate the egg targets in the images using rectangular boxes, and assign corresponding category labels. Finally, the dataset was divided into training set, validation set, and testing set in a ratio of 8:1:1.
2.3. Optimization of Big and Small Ends of the Egg Recognition Precision
To improve the model under the condition of uneven brightness of the big and small ends of the egg, subtle morphological characteristics and color information extraction and recognition, this study is based on YOLOv12n and introduces the RCS-OSA, EUCB, and CSFCN modules to synergistically optimize the network from feature extraction, upsampling detail recovery, and context and spatial feature calibration, thereby enhancing the model’s ability to discriminate the big and small ends of egg features under different brightness conditions. The improved model structure is shown in Figure 5a–f. The RCS-OSA module enhances the ability to extract subtle end features through structural reparameterization, channel shuffling, and one-time feature aggregation. The EUCB module uses efficient upsampling and multi-scale convolution fusion to restore the spatial resolution of deep semantic features, effectively preserving end-contour information and alleviating feature attenuation caused by uneven brightness and differences in eggshell color. The CSFCN module enhances the semantic expression and spatial positioning ability of the end region through the context feature calibration and spatial feature calibration mechanisms and improves the discrimination effect of the model for subtle targets. The synergistic effect of the three enables the network to fully integrate the end contour and eggshell color information, reduce the impact of light interference on recognition precision, and provide reliable feature support for high-precision recognition of the big and small ends.
Figure 5.
The improved model. Backbone (a), detecting internal structures (b,c), head (d,e), neck (f), RCS-OSA structure (g,h), EUCB structure (i), CSFCN structure (j), CFC structure (k) and SFC structure (l).
2.3.1. RCS-OSA Module
In response to the issues of subtle differences in the contour of the big and small ends recognition task and the weakening of features caused by uneven lighting, this study introduces RCS-OSA (Reparameterized Convolution based on Channel Shuffle and One-Shot Aggregation) modules, as shown in Figure 5g,h. Through structural reparameterization, channel shuffling, and a one-shot feature aggregation mechanism, it can enhance the ability of the network to extract fine-grained discriminative features while maintaining the lightweight nature of the model. Specifically, the structural reparameterization mechanism uses the multi-branch structure to enhance the learning ability of the model for edge changes, curvature changes, and local morphological differences in the big and small ends of the egg in the training stage, and the multi-branch structure can be equivalently fused into a more concise convolution form in the inference stage, thereby reducing the computational complexity and improving the detection efficiency. The Channel Shuffle operation promotes the interaction and recombination of feature information between different channels, which helps alleviate the problem of insufficient feature expression in a single channel and enables the network to more fully integrate edge contours and local response information under lighting changes. The One-Shot Aggregation mechanism enhances the retention and transmission ability of key end features by concentrating and aggregating multi-level features, reducing the attenuation of subtle information.
2.3.2. EUCB Module
In order to improve the recovery ability of the model to the details of the big and small ends in the feature fusion stage, this study introduces the Efficient Upsampling Module EUCB (efficient up-convolution block) into the YOLOv12n network structure, as shown in Figure 5i. Under conditions of uneven brightness and differences in eggshell color, these weak discriminative features are prone to decay during feature downsampling and transmission. The EUCB module restores the spatial resolution of the deep semantic features through the efficient upper convolutional structure, which helps to enhance the reconstruction ability of the egg edge information under uneven brightness. The multi-scale deep convolution structure can extract the contour information of the egg end region from different receptive fields and improve the perception ability of the model for weak difference features. Meanwhile, the dynamic weight allocation mechanism can adaptively adjust the fusion weights based on the importance of features at different scales, reducing the impact of ineffective backgrounds and lighting interference on recognition results.
2.3.3. CSFCN Module
This study introduces the CSFCN (context and spatial feature calibration network) structure in the YOLOv12n network to jointly calibrate contextual information and spatial features, as shown in Figure 5j. The egg recognition of the big and small ends belongs to the task of fine feature visual discrimination, and the target differences are mainly concentrated in the edge area of the end. However, in the actual image acquisition process, local features at the end are easily weakened by background interference or lighting changes, resulting in insufficient spatial localization and semantic expression of key areas in the model. The CSFCN structure optimizes feature representation through the context feature calibration (CFC) and spatial feature calibration (SFC) modules, as shown in Figure 5k,l. Among them, the CFC module utilizes a cascaded pyramid pooling method to obtain contextual information at different scales, and adaptively aggregates it based on the correlation between pixel features and contextual information, enabling the network to more fully model the relationship between the overall shape of the egg and the local regions at the ends, thereby alleviating the problem of local features caused by uneven brightness. The SFC module calibrates the feature responses of different spatial positions through channel grouping, which helps to enhance the spatial expression ability of the end edges. By introducing the CSFCN structure, the model can achieve the collaborative enhancement of context semantic information and spatial detail features at a lower computational complexity, reduce the influence of illumination interference on the recognition of large and small ends, and improve the feature discrimination ability of the network for differential targets.
2.4. Model Parameters and Evaluation Metrics
2.4.1. Model Parameters
The environment for these experiments was a laptop equipped with an AMD Ryzen R9 5900HX CPU, 32 GB of memory, and an RTX 3080 GPU. The operating system is Windows 11, the CUDA version is 11.6, and the programming language is Python (3.8). The batch size is set to 4, the epochs to 200, the optimizer to SGD, and the learning rate to 0.01.
2.4.2. Evaluation Indicators
In this study, IoU can be understood as the degree of coincidence between the frame predicted by the system and the marked frame in the original picture. If the IoU calculated is greater than the preset threshold, it is considered that the target has been correctly detected; otherwise, it is considered that the target has not been correctly detected. The test results can be divided into four categories: True Positive (TP), False Positive (FP), False Negative (FN), and True Negative (TN).
In order to verify the impact of the improved YOLOv12 model on the experimental results, precision (P), recall (R), mAP, FLOPs, model size, and inference time were introduced to evaluate the performance of object detection. Precision is the percentage of correct positive predictions of the identified objects, with a higher precision indicating a lower false positive rate of the model; The recall rate is the ratio of correctly identified objects to the total number of objects, and a higher recall indicates a lower model miss rate; mAP represents the average value of average precision (AP) for all categories, AP represents the detection performance results for each category, C represents the total number of categories, and i represents the category number. The higher the mAP value, the more stable the model’s detection performance for each category. The formulas were defined as follows:
FLOPs represent floating-point operations used to measure the complexity of a model. The model size represents the size of the model weight file after training is completed. The inference time represents the time when the network model to recognize the target. The smaller the values of FLOPs, model size, and inference time are, the lower the computational overhead of the model, the lower the storage occupation, and the better the real-time performance; the overall performance of the model is better.
3. Results and Discussion
3.1. The Advantages and Effects of Image Brightness Correction
After stretching the contrast of the original egg image, the brightness of the darker areas in the image was improved, and the overall contour and end shape information of the egg were clearer, as shown in Figure 3. On this basis, the trained U-Net model is used to segment the main area of the egg, and the saved psh weight file is called to generate the target mask. As shown in Figure 6a, by suppressing the high-brightness areas, interference from local high-brightness reflections on the conveyor roller surface is significantly reduced in the mask results, and the separation of the background area is more accurate. The discrimination effect between the egg target and the background is improved. As shown in Figure 6b, the mask edges optimized using the Gaussian smoothing method are smoother, and the edge sawtooth phenomenon is effectively reduced. The contour continuity and integrity of the egg target area are further improved. As shown in Figure 6c, the optimized mask is merged and fused with the original color image to preserve the color, texture, and edge information of the egg area in the original image, while effectively removing the background area and presenting it as black. The results show that this method has good adaptability to eggs with different eggshell colors and can provide clearer and less interfering input images for subsequent big- and small-end feature extraction and recognition, meeting the preprocessing requirements of big- and small-end recognition experiments for eggs with different colors.
Figure 6.
Post-processing of Segmented Egg Images. (a) Reflective area Suppression. (b) Gaussian Smoothing. (c) Segmentation result.
3.2. Analysis of Model Recognition Performance and Category Detection Results
To objectively evaluate the detection performance of each model in the recognition task, the precision, recall rate, and mAP value are selected as the evaluation indicators. As shown in Table 1 and Figure 7, the YOLOv12 model achieves recognition precision, recall rate, mAP@.5/% and mAP@.5 95/% are 94.7%, 89.8%, 98.0%, and 65.9%, respectively. As shown in Table 2, the recall rates of the SGE, SWE, and BWE categories are 81.1%, 83.0%, and 76.4%, respectively, which are significantly lower than those of other categories; meanwhile, the recognition accuracy of the SRE and BRE categories was 87.1% and 85.4%, respectively, indicating that the model still has some misjudgments in the process of discriminating the red egg size end category. This phenomenon indicates that although the original YOLOv12 has good overall detection ability, its feature extraction ability and category discrimination ability are still insufficient in the face of color differences and egg size recognition. Green- and white-shell eggs have a lighter overall color in the image, and under uneven lighting conditions, the target boundaries and end features are easily weakened, resulting in lower recall rates for the SGE, SWE, and BWE categories. The surface color of red-shell eggs is darker, and the differences between the big and small ends are easily affected by shadows and lighting. Therefore, the model is more prone to category confusion in the SRE and BRE categories, resulting in lower recognition accuracy. It can be seen from this that the recognition of the big and small ends of eggs not only relies on the overall contour information of the target, but also requires the model to have a strong ability to express spatial features and distinguish fine categories.
Table 1.
Comparison of overall recognition performance among different models.
Figure 7.
Radar chart comparing precision, recall, and mAP across different models.
Table 2.
Comparison of class-wise recognition performance among different models.
Given the shortcomings of the YOLOv12 model in terms of precision and recall, this study conducted targeted optimization design based on it. Specifically, in the backbone, replace A2C2f with A2C2f_RCSOSA, introduce the EUCB module in the neck section, and introduce the CSFCN module in the head section. After introducing different improvement modules, the overall performance of the model in the BRE and SRE categories has been improved. In order to improve the conciseness of model name expression and the readability of ablation experiment result analysis, this study uniformly named the improved models. YOLOv12 + A2C2f_RCSOSA, YOLOv12 + EUCB, YOLOv12 + CSFCN, YOLOv12 + A2C2f_RCSOSA + EUCB, YOLOv12 + A2C2f_RCSOSA + CSFCN, YOLOv12 + EUCB + CSFCN, YOLOv12 + A2C2f_RCSOSA + EUCB + CSFCN are, respectively, named RCSOSA12, EUCB12, CSFCN12, RCEU12, RCCS12, EUCS12 and RCEUCS12. In the following text, the above abbreviations are used to represent the corresponding models. To more intuitively illustrate the relationship between precision and recall rate of the model, a precission–recall rate curve graph has been introduced. The closer the curve is to the upper right corner, the better the model’s performance. As shown in Table 1 and Figure 8, for the single module improvement results, the CSFCN12 model has the best overall performance, with precision, recall rates, mAP@0.5, and mAP@0.5 0.95 achieving 98.9%, 99.0%, 99.4%, and 72.2%, respectively, indicating that the CSFCN module has good performance in enhancing contextual information modeling and spatial feature calibration. As shown in Table 2, the recognition precision of the SGE and BGE categories in the CSFCN12 model reached 99.6%, the BWE category recall rate increased to 100.0%, and the recognition precision of the SRE and BRE categories increased to 96.4% and 97.8%, respectively. This indicates that the CSFCN module can enhance the attention ability of the model to the key target regions through context information fusion and spatial feature calibration, so that the network can still extract relatively stable discriminative features under the condition of weak boundary contours. For the dual module improvement results, the combination of A2C2f_RCSOSA and CSFCN showed a more balanced performance in various category detection results. The RCCS12 model achieved the best overall performance, with its precision, recall rate, and mAP@0.5 reaching 99.5%, 99.4%, and 99.5%, respectively, significantly better than the original YOLOv12 model, indicating that A2C2f_RCSOSA and CSFCN have good synergistic effects in feature extraction and calibration, which can further improve the ability to recognize subtle features of the big and small ends of eggs. In the RCCS12 model, the recall rates for the SGE, BGE, SWE, and BWE categories all reached 100.0%, effectively addressing the missed detection issue of the original YOLOv12 in these categories. Meanwhile, the precision of the SRE and BRE categories has increased to 98.8% and 99.0%, respectively, which are 11.7% and 13.6% higher than the original model. This indicates that the A2C2f_RCSOSA module and CSFCN module have a good complementary effect in feature extraction and feature calibration.
Figure 8.
The precision–recall rate curves chart of nine models.
3.3. Analysis of Performance Changes in the Three-Module Combined Model
It is worth noting that the introduction of the EUCB module on the basis of A2C2f_RCSOSA and CSFCN did not further improve the model performance. The precision of the RCEUCS12 model is 99.1%, and the mAP@0.5@0.95 is 70.9%, which is lower than the 99.5% and 71.7% of the RCCS12 model. However, the model still maintains high detection performance in some categories. For instance, the recall rates of SGE, BGE, and BWE reach 100.0%, and the precision of SRE and BRE is 97.3% and 98.4%, respectively. However, compared with the RCCS12 model, the three-module combination did not continue to improve in all categories, and the recognition accuracy of the SRE and BRE categories declined slightly. This indicates that network modules are not simply stacked to achieve sustained performance gains. A possible reason is that although the EUCB module can enhance detail recovery during the upsampling process, when used together with A2C2f_RCSOSA and CSFCN, it may increase the complexity of the network structure and the difficulty of feature fusion, causing some local information to be repeatedly reinforced or introducing redundant features, thereby interfering with the recognition of subtle features. In addition, after the three modules are stacked, the feature transmission path increases, and the model may exhibit an uneven distribution of information weights during feature fusion at different scales, resulting in less clear discrimination boundaries for some difficult-to-classify areas than those obtained with the combination of two modules. Therefore, the superposition of more modules does not necessarily lead to better performance. When improving the network structure, it is necessary to comprehensively consider the complementarity between modules, feature expression ability, and model complexity.
Compared with the original YOLOv12, RepVitASF12 [34] significantly solves the missed detection problem of some categories. The recall rate of SGE categories is increased from 81.1% to 100.0%, and the recall rate of BWE categories is increased from 76.4% to 98.0%. This shows that the RepViTASF structural feature fusion strategy can enhance the perception ability of the model for weak feature targets. However, from the perspective of precision distribution, the improvement of RepViTASF12 compared to the original YOLOv12 is not significant, while the RCCS12 model has improved the recognition precision of the SRE and BRE categories by 12.6 and 12.3 percentage points, respectively, compared to RepViTASF12. In addition, the RCCS12 model performs well on six types of targets: SGE, BGE, SRE, BRE, SWE, and BWE, with mAP@0.5 all remaining above 99.4%, indicating that it can not only improve the detection results of a single category but also has good adaptability between different colors and end categories.
3.4. Analysis of Model Complexity and Reasoning Efficiency
In order to further evaluate the practical application performance of the model, a comprehensive evaluation analysis was conducted on each model based on FLOPs, model size, and inference time. As shown in Figure 9, the FLOPs of the original YOLOv12 model are 6.3 G, the model weight size is 5.5 M, and the inference time is about 6.0 ms. It belongs to a lightweight model, but there are shortcomings in precision and recall in some category recognition. Although RepVitASF12 performed well in previous experiments and improved the recognition ability of weak feature categories, its FLOPs reached 18.2 G, the model weight was 13.2 M, and the inference time was 9.6 ms, significantly increasing the computational burden and storage requirements compared to YOLOv12. After introducing the A2C2f_RCSOSA and CSFCN modules, the FLOPs of the RCCS12 model are 9.4 G, the model weight is 8.3 M, and the inference time is 6.9 ms. Compared with RepVitASF12, this new model maintains high accuracy and high recall while controlling the computation and inference time at a lower level, thereby achieving a good balance between performance and efficiency. This indicates that module collaboration can significantly improve the performance of difficult-to-detect categories while still maintaining low resource consumption. The FLOPs of the RCEUCS12 model are 9.3 G, the model weight size is 8.2 M, and the inference time is 5.3 ms. The difference in FLOPs and weight size between the two models is small, indicating that further introducing the EUCB module on the basis of A2C2f_RCSOSA and CSFCN does not significantly increase the model’s computational and storage overhead. Meanwhile, the reasoning time of the three-module superposition model is lower than that of the two-module combination, indicating that it has certain advantages in reasoning speed, which may be related to the structural optimization of the EUCB module for the feature sampling process and the change in the calculation path in the reasoning process. However, based on the various recognition results, it can be concluded that the RCCS12 model has better overall detection performance.
Figure 9.
Comparison of FLOPs, model size, and inference time among different models.
Overall, the original YOLOv12 mainly had issues with missed detection of white- and green-shelled egg categories and misjudgment of red egg categories. After introducing the improved module, the model’s ability to detect weak feature targets and distinguish subtle feature categories has been improved. Among them, the combination of A2C2f_RCSOSA and CSFCN performs the best in reducing missed detections, minimizing false positives, and maintaining balanced detection performance across categories. The RCCS12 model has moderate computational complexity and inference speed while maintaining high precision and recall, and is more effective in improving weak category performance compared to the single-module model. Therefore, this study ultimately chose the RCCS12 model as the optimal improved model structure.
4. Conclusions
This study focused on the high-precision identification of the big and small ends of eggs. By combining image brightness correction with deep learning detection methods, an improved model (ie.e RCCS12) was proposed. In this model, RCSOSA enhances the extraction and aggregation of subtle egg-end features, such as local contours and shape differences, while CSFCN further calibrates contextual and spatial information to emphasize discriminative regions and reduce interference caused by uneven illumination and eggshell color variations. This model has solved the problem of high-precision identification of the big and small ends of eggs under uneven brightness conditions. This study indicates that the original YOLOv12n model has significant shortcomings in the recall rate of green- and white-shell eggs, as well as the recognition precision of the big and small ends of the red-shell eggs. The precision, recall rate, mAP@0.5, and mAP@0.5: 0.95 were 94.7%, 89.8%, 98.0%, and 65.9%, respectively, indicating that the model lacks the ability to extract subtle features and distinguish colors. In contrast, the improved model introduces the A2C2f_RCSOSA module in the backbone to enhance the ability to extract subtle local features, adds the EUCB module in the neck to optimize upsampling details, and adds the CSFCN module in the head for context information fusion and spatial feature calibration, thereby improving the recognition performance of the model. The ablation experiment showed that the improvement of the CSFCN12 model can significantly increase the recall and precision of weak categories. The dual-module combined RCCS12 model achieved a precision of 99.5%, a recall rate of 99.4%, and an mAP@0.5 of 99.5%. The mAP@0.5 values for the six sample types (BRE, SRE, BWE, SWE, BGE, and SGE) all exceeded 99.4%, effectively reducing false negatives and false positives. Compared to the previous RepVitASF12 model, the big and small ends of the red-shell eggs category have improved by 12.6% and 12.3%, respectively. In terms of model efficiency, the RCCS12 model has a FLOPs of 9.4 G, a weight size of 8.3 M, and an inference time of 6.9 ms. It has been significantly optimized. Overall, the improved RCCS12 model can effectively alleviate the recognition difficulties caused by uneven brightness and significantly improve the recognition precision of the big and small ends of the egg. In future work, the proposed method will be further extended and validated from both algorithmic and practical application perspectives. At the algorithmic level, more challenging egg conditions, including occlusion, damage, contamination, cracks, and motion blur, will be considered to further improve recognition robustness, while its applicability to other agricultural and food inspection tasks will also be explored. To meet the real-time requirements of automatic packaging production lines, the proposed method will be further integrated with the robotic egg-packaging system, and practical performance, including processing FPS, end-to-end latency, conveyor throughput, robot synchronization, and embedded deployment, will be systematically evaluated.
Author Contributions
Conceptualization, X.L. and J.L.; Methodology, X.L. and J.L.; Software, X.S. and Y.Z.; Validation, Y.Z. and S.N.; Formal analysis, X.L., L.C. and J.L.; Investigation, W.Y., S.T., and J.L.; Resources, L.C. and J.L.; Data curation, X.L., L.C. and J.L.; Writing—original draft, X.L., L.C., and J.L.; Writing—review and editing, L.C. and J.L. All authors have read and agreed to the published version of the manuscript.
Funding
This work was supported by the National Key R&D Plan (2024YFD2000903).
Data Availability Statement
All sample data in this study were obtained from our experiments and are currently not publicly available. If necessary, we are willing to share the dataset through applications from other researchers.
Conflicts of Interest
The authors declare no conflicts of interest.
Abbreviations
The following abbreviations are used in this manuscript:
| CSFCN12 | YOLOv12 + CSFCN |
| EUCB12 | YOLOv12 + EUCB |
| EUCS12 | YOLOv12 + EUCB + CSFCN |
| RCCS12 | YOLOv12 + A2C2f_RCSOSA + CSFCN |
| RCEU12 | YOLOv12 + A2C2f_RCSOSA + EUCB |
| RCEUCS12 | YOLOv12 + A2C2f_RCSOSA + EUCB + CSFCN |
| RCSOSA12 | YOLOv12 + A2C2f_RCSOSA |
| RepVitASF12 | YOLOv12 + RepVit + ASF |
References
- Huang, Y.; Yang, P.; Li, S.; Fan, J.; Liu, J. Effects of laying methods on physical properties of eggs during storage. Heilongjiang Anim. Sci. Vet. Med. 2018, 6, 62–64. [Google Scholar] [CrossRef]
- Vitezslav, O.; Frantisek, M. The Influence of the Position of the Eggs Upon Their Interior Quality. Poult. Sci. 1956, 35, 1381–1384. [Google Scholar] [CrossRef] [Scilit]
- Wang, W.; He, C.; Tang, L.; Ren, Z. Total variation based variational model for the uneven illumination correction. Neurocomputing 2018, 281, 106–120. [Google Scholar] [CrossRef] [Scilit]
- Li, J.; Wei, Z.; Song, Y.; Chen, S.; Yu, M.; Wang, W.; Chen, Y. A Multi-Scale Fusion-Based Method for Ultra-Low-Light Agricultural Image Enhancement. Teh. Vjesn. 2025, 32, 2407–2419. [Google Scholar] [CrossRef] [Scilit]
- Severoglu, N.; Demir, Y.; Kaplan, N.; Kucuk, S. ACGC: Adaptive chrominance gamma correction for low-light image enhancement. J. Vis. Commun. Image Represent. 2025, 107, 104402. [Google Scholar] [CrossRef] [Scilit]
- Li, H. Low-light color image equalization based on adaptive brightness adjustment. Sci. Rep. 2025, 16, 1644. [Google Scholar] [CrossRef] [Scilit]
- Chen, G.; Liu, Y.; Yang, H.; Sun, B.; Yu, C. Adaptive brightness correction of dim-lightening color images. Opt. Precis. Eng. 2021, 29, 1999–2007. [Google Scholar] [CrossRef] [Scilit]
- Lv, J.; Fang, M.; Yao, Q.; Wu, C.; He, Y.; Bian, L.; Zhong, X. Detection model for tea buds based on region brightness adaptive correction. Trans. Chin. Soc. Agric. Eng. 2021, 37, 278–285. [Google Scholar]
- Wang, D.; Wang, J.; Xu, Z.; Liu, Y. Adaptive correction algorithm for non-uniform illumination images. Syst. Eng. Electron. 2017, 39, 1383–1390. [Google Scholar]
- Jia, F.; Wong, H.; Wang, T.; Zeng, T. A reflectance re-weighted Retinex model for non-uniform and low-light image enhancement. Pattern Recognit. 2023, 144, 109823. [Google Scholar] [CrossRef] [Scilit]
- Tian, Q.; Cohen, L. A variational-based fusion model for non-uniform illumination image enhancement via contrast optimization and color correction. Signal Process. 2018, 153, 210–220. [Google Scholar] [CrossRef] [Scilit]
- Wang, J.; Wang, X.; Zhang, P.; Xie, S.; Fu, S.; Li, Y.; Han, H. Correction of uneven illumination in color microscopic image based on fully convolutional network. Opt. Express 2021, 29, 28503–28520. [Google Scholar] [CrossRef] [Scilit]
- Wang, Q.; Liu, Y.; Hu, S.; Yan, Y.; Li, B.; Mao, H. Dynamic gamma correction-guided CNN for low-light corn tassel enhancement in intelligent detasselling systems. Comput. Electron. Agric. 2026, 244, 111436. [Google Scholar] [CrossRef] [Scilit]
- Jiang, Y.; Gong, X.; Liu, D.; Cheng, Y.; Fang, C.; Shen, X.; Wang, Z. EnlightenGAN: Deep Light Enhancement Without Paired Supervision. IEEE Trans. Image Process. 2021, 30, 2340–2349. [Google Scholar] [CrossRef] [Scilit]
- Fan, J.; Li, J.; Ren, L.; Chen, Z. Multi-scale dynamic fusion for correcting uneven illumination images. J. Vis. Commun. Image Represent. 2023, 97, 103978. [Google Scholar] [CrossRef] [Scilit]
- Lin, F.; Zhang, H.; Wang, J.; Wang, J. Unsupervised image enhancement under non-uniform illumination based on paired CNNs. Neural Netw. 2023, 170, 202–214. [Google Scholar] [CrossRef] [Scilit]
- Serdar, Ç. Adaptive Multi-Branch Feature Fusion for Low-Light Image Enhancement. Appl. Sci. 2026, 16, 2712. [Google Scholar] [CrossRef] [Scilit]
- Zhang, F.; Liu, X.; Gao, C.; Sang, N. Color and Luminance Separated Enhancement for Low-Light Images with Brightness Guidance. Sensors 2024, 24, 2711. [Google Scholar] [CrossRef] [Scilit]
- Chao, K.; Song, W.; Shao, S.; Liu, D.; Liu, X.; Zhao, X. CUI-Net: A correcting uneven illumination net for low-light image enhancement. Sci. Rep. 2023, 13, 12894. [Google Scholar] [CrossRef] [Scilit]
- Qiu, Y.; Niu, S.; Niu, T.; Li, W.; Li, B. Joint-Prior-Based Uneven Illumination Image Enhancement for Surface Defect Detection. Symmetry 2022, 14, 1473. [Google Scholar] [CrossRef] [Scilit]
- Lei, C.; Tian, Q. Low-Light Image Enhancement Algorithm Based on Deep Learning and Retinex Theory. Appl. Sci. 2023, 13, 10336. [Google Scholar] [CrossRef] [Scilit]
- Huang, W.; Li, K.; Xu, M.; Huang, R. Self-Supervised Non-Uniform Low-Light Image Enhancement Combining Image Inversion and Exposure Fusion. Electronics 2023, 12, 4445. [Google Scholar] [CrossRef] [Scilit]
- Jing, J.; Liu, S.; Wang, G.; Zhang, W.; Sun, C. Recent advances on image edge detection: A comprehensive review. Neurocomputing 2022, 503, 259–271. [Google Scholar] [CrossRef] [Scilit]
- Fang, X.; Zhang, S. Learning Local Contrast for Crisp Edge Detection. J. Comput. Sci. Technol. 2023, 38, 554–566. [Google Scholar] [CrossRef] [Scilit]
- Zhou, J.; Zhao, H.; Sun, M. SEHSNet: Stage Enhancement and Hierarchical Supervision Network for edge detection. Vis. Comput. 2024, 40, 7439–7456. [Google Scholar] [CrossRef] [Scilit]
- Wang, H.; Liu, P.; Dou, Q.; Song, Y.; Luo, M.; Han, R.; Zhang, B. Enhanced edge detection via Dual-branch attention fusion with Canny-assisted supervision. Vis. Comput. 2025, 41, 9765–9780. [Google Scholar] [CrossRef] [Scilit]
- Cai, P.; Cai, Z.; Fan, Y.; Wu, W. Image Contour Detection Based on Visual Pathway Information Transfer Mechanism. Neural Process. Lett. 2024, 56, 11063. [Google Scholar] [CrossRef] [Scilit]
- Wang, J.; Xu, Q.; Jiang, B.; Luo, B.; Tang, J. Multi-Granularity Part Sampling Attention for Fine-Grained Visual Classification. IEEE Trans. Image Process. 2024, 33, 4529–4542. [Google Scholar] [CrossRef] [Scilit]
- Liu, X.; Zhang, L.; Li, T.; Wang, D.; Wang, Z. Dual attention guided multi-scale CNN for fine-grained image classification. Inf. Sci. 2021, 573, 37–45. [Google Scholar] [CrossRef] [Scilit]
- Lu, J.; Zhang, W.; Zhao, Y.; Sun, C. Image local structure information learning for fine-grained visual classification. Sci. Rep. 2022, 12, 19205. [Google Scholar] [CrossRef] [Scilit]
- Liu, D.; Zhao, L.; Wang, Y.; Kato, J. Learn from each other to Classify better: Cross-layer mutual attention learning for fine-grained visual classification. Pattern Recognit. 2023, 140, 109550. [Google Scholar] [CrossRef] [Scilit]
- Yu, Y.; Wang, J. Hybrid Granularities Transformer for Fine-Grained Image Recognition. Entropy 2023, 25, 601. [Google Scholar] [CrossRef] [Scilit]
- Russell, B.; Torralba, A.; Murphy, K.P.; Freeman, W.T. LabelMe: A database and web-based tool for image annotation. Int. J. Comput. Vis. 2008, 77, 157–173. [Google Scholar] [CrossRef] [Scilit]
- Tian, Y.; Ye, Q.; Doermann, D. YOLOv12: Attention-centric real-time object detectors. arXiv 2025, 2502:12524. [Google Scholar]
- Li, X.; Chen, L.; Zhou, S.; Zhang, Y.; Li, J. RepVitASF12: A network of ViT and attention scale sequence modules to identify the big and small ends of eggs. Inf. Process. Agric. 2026, in press. [Google Scholar] [CrossRef] [Scilit]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license.








