Abstract

One of the most critical aspects of quality assurance is inspecting products for defects before they are sold or shipped. A good product is more vital than having more of the same item for a customer’s enjoyment. The client has a significant role in determining the quality of a product. Another way to think about quality is as the total of all the characteristics that contribute to the creation of items that the client enjoys. Recently, the application of machine vision and image processing technology to improve the surface quality of fruits and other foods has increased significantly. This is primarily because these technologies make significant advancements in areas where the human eye falls short. This means that, by utilizing computer vision and image processing techniques, time-consuming and subjective industrial quality control processes can be eliminated. This article discusses how to check and assess food using picture segmentation and machine learning. It is capable of classifying fruits and determining whether a piece of fruit is rotten. To begin, Gaussian elimination is used to remove noise from images. Then, photos are subjected to histogram equalization in order to improve their quality. Segmentation of the image is carried out using the K-means clustering technique. Then, fruit photos are classified using machine learning methods such as KNN, SVM, and C4.5. These algorithms determine if a fruit is damaged or not.

1. Introduction

Quality is more crucial to the customer’s delight than supplying more items of the same kind [1]. The client is an important factor in determining product quality. A further way to define quality is to look at it as the totality of all the traits that go into creating goods that satisfy the client [2]. The quality of certain imported goods has recently improved in importing nations. In addition to preserving the native seafood industry, it also protects the quality of food imported from other nations. The direct sensory quality of agricultural goods is mostly indicated by their exterior quality. Exterior characteristics such as color, texture, size, form, and flaws are often used to assess product’s quality [3]. While output and revenues are important, food manufacturing company administrators also take into account the product’s prominence, the social context, and the problems faced by farmers in completing their agricultural chores [4].

One of the most important aspects of quality assurance is the detection of flaws prior to the sale or export of products [5]. Mango quality has always been assessed by human operators using visual cues. This is no longer the case. They are time-consuming, tiresome, and inconsistent [6]. This technique has been used in agricultural engineering studies [7, 8].

In recent years, there has been a significant surge in the use of machine vision and image processing technologies to improve fruit surface quality. This is primarily because these technologies deliver enormous gains in areas where the human eye is not sensitive [9]. As a result, the use of computer vision and image processing algorithms streamlines the arduous and subjective industrial quality control methods.

Some issues and anomalies exist in the automated inspection of agricultural goods, compared to other industries, because of the biological nature of the items inspected. Similar to the great diversity of flavors and textures found in nature, fruits and vegetables exhibit a wide range of exterior qualities. The color, size, and form of fruits might vary even if they were harvested from the same tree on the same day [10]. Depending on their ripeness and storage circumstances, food goods naturally change color or texture after harvest (humidity and temperature, fungal infections, presence of volatile substances, storage duration, etc.). In addition, the color of a healthy fruit’s skin might match the color of another fruit of the same kind in a specific section of the skin. Furthermore, it is critical to identify any foreign material on quality control lines, such as stems, leaves, dirt, or blemishes on the skin, and not mistake them for the real thing [11, 12].

After harvest, these traits are determined by the fruit’s ripeness and the storage circumstances under which it was kept (humidity and temperature, fungal infections, presence of volatile substances, storage duration, etc.). It is also possible to match the color of a section of the skin of one fruit to the color of another fruit of the same type. Furthermore, it is critical to identify any foreign material on quality control lines, such as stems, leaves, dirt, or blemishes on the skin, and not mistake them for the real thing [13, 14].

This article provides a method based on image segmentation and machine learning for food inspection and grading. It is capable of grading fruit into different categories and also identifying defective fruits.

2. Literature Survey

Computer vision and inductive characterization with a limited number of characteristics have been provided [3] with three examples of how this framework has been effectively implemented to enhance the quality inspection process. The Hass avocado, the Manila mango, and the maize tortilla were all examined. The enormous volume of these items’ manufacture and marketing made them very valuable economically. Although each product has unique qualities that need distinct approaches to the quality inspection process, the framework offered may cover the most common aspects that can be used to automate the process.

A food traceability system developed by Wang et al. [15] not only enables forward tracking and diverse tracing, but also evaluates food quality along the supply chain and provides consumers with the evaluation information, to primarily enhance the consumer experience and help firms gain consumers’ trust in the food supply chain. It was found that fuzzy classification was used to assess food quality at each level of the supply chain, and an ANN algorithm used to determine a final food quality grade for each stage was employed.

The present growth and function of image research and computer vision systems in the evaluation of agricultural and food product quality have been proposed by Iqbal et al. [12]. In order to do image analysis, computerized classification, and rank-based ranking, this device’s basic perception and equipment linked to computer vision are both required. In order to improve agricultural productivity, it is essential that the efficacy and suitable evaluation progression be taken into consideration. In terms of fruit ranking, the agricultural business has grown significantly. Because high-quality fruits may be exported and bring in a lot of money, it is important to have a system in place for evaluating the fruit [16].

It has been shown that an image processing-based illness classification method for apple fruit may be used. There were a total of four phases in the strategy that was given. First, the area of interest was extracted using the K-means clustering-based defect segmentation approach. The segmented apple illnesses were used as a source for the most current color, texture, and form attributes in the second stage. In the third phase, several sorts of characteristics were blended to create a more distinguishing feature. Using a multiclass support vector machine, training and classification were completed in the final stage.

In order to increase the prominence of food items, Al-Marakeby [17] devised a classification system based on eyesight. The development of classification is based on the retention and examination of the picture of the fruit or product to eliminate the defective items. To arrange the classification gates, signals are sent to computer-interfacing cards [18]. Different food items, such as apples, tomato sauces, eggs, and lemons, are improved in four different food processing methods.

Commercialization and grade categorization of fruit necessitates the use of automated fruit quality detecting systems. Methods that may be utilized efficiently to evaluate fruit quality are now more important than ever in the food industry. As a result of this, research has been performed to create automated and semiautomatic ways for inspecting fruit quality and ensuring public safety [19].

Apples are graded and sorted using a machine vision algorithm that was designed and implemented [20]. A horizontal and vertical grading system with the same structure and orientation of fruit was presented. A fruit-picking robot was assisted by a machine vision system. Authors [21] employed unsupervised clustering techniques to separate the locations where fruit faults were found. The photos’ color characteristics were retrieved, and the simulation yielded excellent results.

Using an iterative clustering-based noise detection technique and a switching median filter, researchers [22] were able to successfully repair pictures that had been damaged by impulsive noise. Using a noise-detection technique for picture restoration, this filter used three pixel clusters to identify noisy pixels. It is secret if the pixel in question falls below the center cluster in the previous iteration; else, it is considered corrupted and removed from consideration. Uncorrupted pixels remain unaffected while corrupted pixels utilize median filtering to transform themselves to uncorrupted form.

Smart farming is a term that refers to a well-known and better way to run a farm that has become more common in modern farming. Agricultural and information technologies are used to keep an eye on the health and production of crops. This includes keeping an eye on field crop conditions and other indicators. Finally, the goal of smart farming is to cut the cost of agricultural inputs while still keeping the quality of the end product the same [23, 24].

3. Methodology and Results

3.1. Methodology

The proposed methodology consists of five main stages. It is shown in Figure 1. These stages are as follows:Step 1: input dataset of various images related to foodsStep 2: using Gaussian elimination to preprocess images. Gaussian elimination is used to remove noise from images in this step. This preprocessing helps to improve the quality of the image. Improved image quality makes it easier to classify things better.Step 3: image enhancement by equalizing the histogram. In image enhancement, the quality of an already existing set of images is made better by the histogram equalization method. This also improves the accuracy of the classifiers.Step 4: the K-means algorithm is used to break up an image into parts. A way to do this is to split an image into several parts or segments. It helps you find the parts of an image that show signs of a disease. During this step, the image is broken down into parts.Step 5: applying classifiers to a set of already processed images. Noise and image segmentation are done when the dataset is ready to be classified after they are cleaned up. There are three different ways to do classification: C 4.5, support vector machine (SVM), and KNN.

The detailed description of the proposed methodology is available in the following sections.

3.1.1. Image Preprocessing-Noise Removal

It is essential that the image be filtered and improved in order to get the best results. As a result, the segmentation results from images taken with cell phones may differ. Image scaling, noise reduction, and picture enhancement are all steps in the preprocessing of an image. Digital images may contain a variety of artifacts, including noise. As a result of poor capture, a simple thresholding task may become difficult. As a result, it is vital to get rid of any visible noise from the image. A picture’s unpredictable lighting or color statistics are referred to as “image noise.” In pictures, Gaussian, salt and pepper, shot, quantization, grain, periodic, and other forms of noise can be seen. Filters such as median filters and Wiener filters can be used to remove these annoyances. In order to reduce noise, many morphological actions might be used. Gaussian filtering may be used to smooth pictures while median filtering can be used to modify the brightness of pixels. Gaussian filter (GF) was used to eliminate noise in this case. Image characteristics are kept while intensity importance is switched out for an average of the intensities of surrounding pixels in Gaussian filtering. Smoothing the image while keeping the image’s borders is achieved by using this method. It is smoothed with Gaussian kernels based on cumulative standard deviation [12]. The Gaussian function G(x) and the standard deviation (s) are given as follows:where Xi is the specific value in the dataset, X′ is the mean, and n is the aggregate set of values in the dataset.

3.1.2. Image Enhancement

In order to boost the human eye’s capacity to perceive information in a picture, images are enhanced after they have been filtered. The histogram equalization boosts contrast by communicating the intensity value of pixels in the input picture, such that the output image has a consistent intensity distribution and a constant histogram. When the image’s practical data is defined by tight contrast values, this technique enhances the image’s overall contrast on a regular basis. Using this method, the histogram’s intensities will be more evenly distributed [25]. As a result, areas with less local contrast might benefit from an increase in contrast. As a result of histogram equalization, the most frequently occurring intensity values are efficiently dispersed.

3.1.3. Image Segmentation

There are two stages to this process: first, the image is sharpened using dynamic fuzzy histogram equalization, and then, it is segmented to get the suitable ROI. Extracting useful information from these segments is done via feature extraction. In image segmentation, portions of a picture are identified and grouped together based on common traits. Region-based and edge-based segmentation techniques exist. Anatomical or functional aspects can be classified into groups based on patterns in intensity values surrounding a cluster of neighboring pixels using region-based segmentation.

Based on unique textures and patterns, this study uses a region-based segmentation technique to separate the ROI into pieces. When using K-means clustering, each observation is assigned to a cluster with the local mean, allowing for the creation of a cluster pattern. Using the total number of groups indicated by the variable k, this method seeks to discover clusters in the input data. Euclidean distances are squared to find the most relevant data points. Each data point is assigned to one of the k groups depending on the specified attributes. Feature similarity is used to group data points [26].

Whether the image has a white or black backdrop, K demonstrates that clustering is working as it should. When the image is captured with a static backdrop, the ROI ill region is correctly segmented. K indicates that clustering fails to properly extract the ROI ill region in the image with a living backdrop.

3.1.4. Classification of Images

The most prevalent job for sickness prediction and data categorization is classification. Classification is essentially a decision-making process. The three unique classifiers applied in this work to categorize the sick leaves are Naive Bayes, support vector machine, and k nearest neighbor.

A lot of research has utilized the K-NN classifier for classification. Numerous methods are utilized for the categorization of the objects in pattern recognition. K-NN is one of the classification algorithms that classify objects based on the closest training examples. Event-based learning incorporates K-NN. Calculations are held off until after the classification when employing a locally approximated function [27]. When there is very little prior knowledge about the data’s circulation, KNN is the central and most straightforward categorization strategy. KNN is one of the most well-known classification algorithms for pattern recognition. Numerous analysts have noted that the KNN calculation generates great outcomes in their studies on a range of datasets.

When K = 1, the nearest neighbor (NN) is the simplest kind of KNN. In this method, each sample should be classified in the same way as its neighbors. In this method, if the classification of a specific sample is uncertain, the classification of its nearest neighbor samples may be utilized to produce a forecast. A training set and a query set can be used to calculate the distance between the training set samples and the query set samples. A sample’s identity can be deduced from the information in its closest neighbor.

Each data point in an SVM model is represented by a single point in k-dimensional space (where k is the number of features). The feature’s value is derived from each coordinate’s value. Once the hyperplane has been chosen, classification may then be done by determining which classes are distinct from each other. SVM was first developed by Vapnik and has since grabbed the interest of scholars all around the globe. The input data collected by an SVM classifier is often divided into two categories. Training data are used to build a model that may be used to classify test data. Multiclass categorization happens on occasion. As a result, a slew of binary classifiers will be required. There have been a number of examinations of SVM’s classification accuracy, and it has been shown to be superior to other methods currently available. Classification of images may be done using SVMs [28]. SVMs outperform a variety of conventional classifiers in experiments, according to the findings. The SVM’s performance is strongly sensitive to the cost and kernel parameters for a range of datasets, though.

It is simple to use the Naive Bayes method to choose class labels for issue occurrences, which are represented as feature values in a vector. While there is no one strategy for developing these classifiers, a number of approaches are built on the same assumption. A feature’s value is independent of the value of any other feature in a Naive Bayes classification model [29].

3.2. Result Analysis

For the study, 250 images related to apples and mangoes are collected. It includes images of good fruits and damaged fruits as well. 137 images are related to mangoes. 94 images are of fresh mangoes and 43 images are of rotten mangoes. 113 images are related to apples. 68 images are of fresh apples, and 45 images are of rotten apples. First, Gaussian elimination is applied on images to remove noise from them. Then histogram equalization is applied on images to enhance image quality. Image segmentation is performed using the K-means clustering algorithm. Then machine learning methods such as KNN, SVM, and C4.5 are used for classifying fruit images. These algorithms classify fruits as damaged or good.

3.2.1. Sensitivity

The proportion of true positives that are accurately detected is known as sensitivity. It has to do with how well a test can detect positive results.where TP stands for true positive and FN stands for false negative.

3.2.2. Specificity

The degree of specificity is determined by the accuracy with which negatives may be correctly detected. The detection of negative results is the issue here.where TN stands for true negative and FP stands for false positive.

3.2.3. Accuracy

The recommended method’s accuracy may be measured using the TP/TN total number to total data ratio.

Comparison of different classifiers’ performances is presented in Table 1 and Figure 2. A comparison study was conducted using the following three parameters: accuracy, specificity, and sensitivity. Accuracy in SVM is better than ever before. With regard to precision, SVM and KNN are on par with each other. Sensitivity has improved with the use of SVM.

4. Conclusion

Food can be inspected and graded using image segmentation and machine learning. This article discusses how to use these technologies effectively. It can classify fruit and determine if it is rotten. The first Gaussian elimination method is used on photos to remove noise. After that, histogram equalization is employed to enhance the image’s quality. The K-means clustering algorithm is used to segment the images. The following stage utilizes machine learning methods such as KNN, SVM, and C4.5 to classify fruit photos. These algorithms determine whether fruits are healthy or unhealthy. Three factors are considered in a comparative study: accuracy, specificity, and sensitivity. SVM accuracy is higher than it has ever been, and it is improving. SVM and KNN are roughly equivalent in terms of their effectiveness. Sensitivity has increased with the aid of SVM. This information will aid future researchers in determining the most appropriate machine learning technique for food grading and quality assurance. Additionally, such strategies can be implanted into robots for the purpose of selecting and assessing food objects.

Data Availability

The data shall be made available on request.

Conflicts of Interest

The authors declare that they have no conflicts of interest.