DoctorateOpen Access

A deep learning based approach for defect detection in x-ray hazelnut images

2025
0 views
0 downloads
Advisor: Dr. Öğr. Üyesi Serap Çakar Kaman ; Dr. Öğr. Üyesi Erkan Güler

Abstract (EN)

Hazelnut is a strategic agricultural product for both the Turkish economy and global agricultural production. Its annual production volume and position in the world market allow hazelnuts to play a critical role within the agricultural production chain. Agricultural hazelnut quality and the hazelnut kernel percentage directly affect numerous parameters, ranging from producer income to the industrial utilization potential of the product. Therefore, accurately and reliably assessing the quality level of hazelnuts is of great importance not only for securing producer income but also for determining the industrial usage potential of the product and ensuring the sustainability of the agricultural production chain. In the literature and current practices, the most common method used to determine agricultural hazelnut quality is the calculation of the hazelnut kernel percentage, also known as the sound hazelnut ratio. Türkiye is the leading country in global hazelnut production, with intensive cultivation in Giresun, Ordu, Samsun, and other regions of the Black Sea; this provides strategic importance in both the domestic market and international trade. Traditional methods for determining agricultural hazelnut quality and the hazelnut kernel percentage are typically carried out through manual inspections, visual assessments, and limited measuring instruments. These methods are time-consuming, labor-intensive, and prone to errors arising from human factors. Especially in large-scale production facilities, such traditional approaches limit the speed and accuracy of quality control and reduce industrial efficiency. In this context, this thesis proposes a non-destructive X-ray imaging and deep learning-based hazelnut quality determination system to improve quality control and hazelnut kernel percentage estimation processes in hazelnut production using modern, fast, reliable, and repeatable techniques. The proposed system provides data-driven decision support to the production chain by accurately identifying defective, slightly defective, and defect-free hazelnuts, thereby significantly enhancing the accuracy of quality control procedures. In doing so, it offers the ability to determine the hazelnut kernel percentage accurately and reliably, ensuring quality throughout the entire supply chain-from producer to consumer-and directly influencing economic valuation. In this thesis, a dedicated X-ray hazelnut dataset was constructed for the training and evaluation of the deep learning model developed for hazelnut defect detection. The dataset includes five different hazelnut varieties collected from the provinces of Samsun, Ordu, and Giresun in Türkiye, consisting of a total of 1320 labeled X-ray images. The images were meticulously annotated to accurately reflect the internal structure of the hazelnut kernel and possible defects, with each defective region marked in detail at the pixel level. This comprehensive annotation process ensured high accuracy in regional defect detection and enabled reliable assessment of the object detection and segmentation performance of the developed methods. During dataset construction, each hazelnut sample was scanned at high resolution using an X-ray device, and preprocessing steps were applied to preserve image quality and maximize the visibility of defects. In the preprocessing stage, hazelnut kernel regions were identified using the Otsu filtering method, while defect areas were enhanced using CLAHE, blur, and Anisotropic Diffusion filters, simultaneously reducing noise, improving contrast, and increasing object clarity. This process played a critical role in accurately detecting small, partial, or overlapping defects and provided the model with clean, optimized input data for training. For hazelnut defect detection, the YOLOv7 deep learning architecture, known for its high accuracy and fast inference capabilities, was selected. In particular, the DCIoU (Distance Centers Intersection over Union) loss function was proposed and integrated into the model to enhance bounding box regression performance. DCIoU overcomes the limitations of traditional IoU-based loss functions, which consider only the overlap area, by simultaneously optimizing the distance between box centers, width-height ratios, and aspect ratio consistency. Consequently, even in cases where there is minimal overlap between boxes or defects occupy very small pixel areas, the model can learn the correct regression direction at early stages and achieve rapid convergence. Since most defects encountered within the internal structure of hazelnuts-such as rot, voids, cracks, mold, and deformations-appear with low contrast, in fragmented forms, or partially, correct alignment of box centers plays a critical role in detection performance. DCIoU penalizes these center misalignments, enabling the model to localize defect regions with more precise boundaries; this provides a significant advantage over traditional IoU, GIoU, DIoU, and CIoU methods, particularly for defects that are closely positioned or overlapping. Moreover, including the geometric ratios of the boxes in the optimization contributes to more consistent modeling of defects with varying sizes and shapes. The low regression deviation produced by DCIoU enhances stability during the learning process and allows the model to establish a more balanced error distribution, particularly in the early epochs. Experimental results indicate that the YOLOv7 model utilizing DCIoU demonstrates significant improvements in detecting small and partial defects, marking them with high accuracy, and overall enhances object detection performance. Consequently, the requirements for high precision and low error tolerance, which are essential in hazelnut quality grading systems, are effectively met. To enhance the model's detection performance and generate segmentation outputs, a Neighborhood Relationship Algorithm was developed and integrated. This algorithm evaluates spatial continuity and pixel-level relationships among multiple bounding boxes produced by the model, selecting the most appropriate boxes and filtering out unnecessary duplicates. The output of the algorithm generates tensor structures that can be directly used in the segmentation process. This tensor-based structure comprehensively represents the cluster and neighborhood relationships of each pixel, eliminating the need for manual annotation. Consequently, the size, shape, and location information of defects on hazelnut kernels can be obtained with high accuracy and used directly in hazelnut kernel percentage calculations. The segmentation outputs not only identify the presence of objects but also determine the pixel-level distribution, area, and density of each defect, enabling hazelnuts to be classified as defective, slightly defective, or defect-free. In this way, the system produces more reliable and repeatable results in quality control processes throughout the production chain. Within the scope of this thesis, two separate simulation tests were conducted to compare the performance of DCIoU with existing IoU-based approaches. In these simulation environments, various synthetic data scenarios were created in which object sizes varied, overlap ratios between boxes changed, and center positions were systematically shifted. The findings indicate that the DCIoU loss function achieves significantly faster convergence during optimization compared to other commonly used approaches such as IoU, GIoU, DIoU, and CIoU. Furthermore, DCIoU was observed to maintain lower regression error levels and to perform more stable and accurate bounding box alignment, particularly in scenarios involving small or partial objects. This demonstrates that DCIoU's capacity to precisely optimize the distances between box centers substantially improves the overall performance of the model and provides supportive evidence for the results obtained on real data. In addition to these simulation tests, the system was evaluated on both the X-ray hazelnut dataset and the COCO-128 dataset, which is commonly used for general object detection. The YOLOv7 model trained with the integration of DCIoU and the Neighborhood Relationship Algorithm demonstrated high accuracy and stable performance on the X-ray hazelnut dataset as well. High values in precision, recall, F-1 score and mAP metrics indicate the model's reliability in both hazelnut defect detection and various object detection scenarios. In experiments on the X-ray dataset, the DCIoU-based model exhibited superior performance in terms of both accuracy and sensitivity compared to previous IoU-based approaches. In particular, the approach supported by segmentation outputs produced significantly better results in distinguishing small and overlapping defects than the standard YOLOv7 model. The experimental studies confirmed DCIoU's superior convergence behavior during optimization and its capacity to minimize regression deviation. Additionally, the Neighborhood Relationship Algorithm provided an alternative approach to classical NMS (Non-Maximum Suppression) processes, optimizing the selection of bounding boxes and demonstrating that segmentation processes can be directly derived from object detection outputs. By integrating X-ray imaging with deep learning–based analyses, the system offers a precise, fast, and reliable solution for hazelnut quality assessment and hazelnut kernel percentage calculations. It not only improves defect detection but also enhances automation, data-driven decision-making, and quality control efficiency in production processes. In conclusion, this thesis combines deep learning and non-destructive X-ray imaging methods to provide an innovative and practical solution that ensures high accuracy, reliability, and operational efficiency in hazelnut quality assessment and hazelnut kernel percentage calculation processes. The system offers a comprehensive and automated workflow, from detecting small and overlapping defects to segmentation, thereby securing quality throughout the hazelnut production chain and directly supporting economic valuation.

Author

Dr. Sultan Murat Yılmaz

Institution

How to Cite

Sultan Murat Yılmaz (Doctorate thesis). A deep learning based approach for defect detection in x-ray hazelnut images, 2025, Sakarya University.

License

Tüm Hakları Saklıdır

This work is shared under the specified license terms.

More theses from Sakarya University