Comparison of Dairy Cow on Morphological Image Segmentation Model with Support Vector Machine Classification

Pattern recognition is viral in object recognition and classification, as it can cope with the complexity of problems related to the object of the image. For example, the category of dairy cows is essential for farmers to distinguish the quality of dairy cows for motherhood. The current problem with breeders is still using the selection process manually. If the selection process using the morphology of dairy cows requires the presence of computer vision. The purpose of this study is to make it easier for dairy farmers to choose the mothers to be farmed. This work uses several processes ranging from preprocessing, segmentation, and classification of images . This study used the classification of three segmentation algorithms, namely Canny, Mask Region-Based Convolutional Neural Networks (R-CNN), and K-Means. This method aims to compare the results of the segmentation algorithm model with SVM) ; the model is measured with accuracy, precision, recall, and F1 Score. The expected results get the most optimal model by using multiple resistant segmentation. The most optimal model testing achieved 90.29% accuracy, 92.49% precision, 89.39% recall, and 89.95% F1 Score with a training and testing ratio of 90:10. So the most optimal segmentation method uses the K-Means algorithm with a test ratio of 90:10.


Introduction
Information regarding the quality of dairy cows related to milk production and the impact on farmers needs tools to help make decisions seen from the morphology of dairy cows; one that has very high milk production is the Holstein Friesian (FH) type cow. Another benefit for the farmer is that it does not cost much to get information about the cow. The problem of milk production, which is still low compared to national consumption, certainly requires a solution. The solution from the government through the Ministry of Agriculture is to strive to optimize national milk production. Indonesian government targets in the year 2025, production of national needs to be met by 60% by the 2013 to 2025 Press Blueprint issued by the Coordinating Ministry for the Economy. Currently, breeders in Indonesia still use manual selection. The ability of tacit knowledge possessed by experts and breeders based on experience by seeing quantitative characteristics inspired this research. The idea is to duplicate this capability into the concept of Artificial Intelligence (AI) does develop a classification model based on machine learning and visual observations of two-dimensional data.
Digital images resulting from visual observations are formed from a limited number of elements or pixels, each of which has a specific location and value. In addition, each pixel contains a number (discrete value) that represents the level of brightness, which reflects the characteristics of the object being imaged [1]. Computer vision and image processing have similar basic concepts, so sometimes, the mention of computer vision and image processing is used interchangeably.
However, both have a primary purpose; computer vision aims to create models and extract data and information from images. Image processing implements computational transformations for images, such as sharpening, contrast, segmentation, and others. The image understanding machine attempts to find the relationship between the image input and the predefined model. The transition from image input to the model can reduce the information possessed so that the presence of preprocessing is beneficial for suppressing irrelevant information [2].
Many previous studies have approached cow image detection with simple regression methods and image processing techniques to improve the precision of dairy cow selection. First, the study used several features, such as chest circumference, through a mobile application. Second, research on the correlation between parameters in assessing goat milk production levels with height, body length, and shoulder height [3]. Third, a study to measure cow's milk productivity using the features of cow length and cow width [4], [5], [6]. Fourth, the study used morphometrics to calculate body and live weight [7]-Furthermore (Fifth), research by measuring the body of FH cows through image analysis.
Machine learning, synonymous with AI, can solve complex problems related to the algorithms used. The general machine learning model comprises six components: datasets, expansion of features with segmentation, algorithms selection, models and parameters, and training and performance evaluation. Improving the model's accuracy requires a segmentation process for classification, which is necessary to distinguish backgrounds and image objects. Research related to segmentation by assessing the position of spatial points becomes feasible to give relatively accurate information about the location of livestock objects, but it does not provide higher semantics.
Current progress in deep learning enriches by addressing these challenges. For example, the potential of neural networks in feature learning [4] has enabled significant advances in computer vision, object detection, and segmentation. In object detection, the Faster R-CNN method [3], from which the Mask R-CNN method [8] was created, has significantly contributed to the detection of powerful objects. Regarding object segmentation, mask R-CNN has an excellent image object detection and segmentation strategy [3]. However, the Mask R-CNN instance segmentation algorithm cannot fully distinguish between foreground and background images during segmentation.
This study is valid to compare the results of Machine learning performance with the SVM algorithm as the classifier used to optimize the preprocessing stage of the morphology image of dairy cows with the segmentation method consisting of the Canny Algorithm, Mask RCNN, and K-Means. The model was measured with accuracy, precision, recall, and F1-score and tested using the ratio of test of 90:10 and 80:20. The best model can use as an automatic classification model for FH dairy cow selection with three categories high, medium, and low.

Research Methods
The research method proposed has several stages, namely data collection, preprocessing with the segmentation of FH dairy cow images, and Support Vector Machine (SVM) modeling, followed by model evaluation. This method aims to maximize the results of the classification model, as shown in Figure 1, the proposed research method. The data used in this study used primary data taken from FH cattle farms in Kunak Bogor and Cibugary farms in east Jakarta. The data used in this study is FH dairy cattle morphology data, taken on kunak farms in Bogor and Cibugary, East Jakarta. The dataset consists of 102 cows, side and back views, and is taken five times each position so that the total dataset in training is 102 x 2 x 5 = 1020 images, of which 102 cows, 2 positions, and 5 shots each position. The total dataset from the kunak farm is 72 cows, and Cibugary is 30 cows. Five-time shooting is when each cow's side view is taken five times and the back view five times. It is time to take some pictures of a cow; the object of study for the dataset spans between 04.30 and 06.30 WIB, and the distance between a cow and the camera needed to snap a picture is 2-2.5 meters. The picture's dimensions in terms of its resolution are as follows: 3456 x 5184 pixels with a Digital DSLR camera Canon, 1200D series. Then, each image is placed in a different folder based on class type. Each image in PNG format contains an RGB image, and the change image size is 256 x 256 pixels; figure 2 is an example of the dataset used with medium classification.

. Edge Detection Canny
Edge detection is a step on the image to produce the edges of the object or photo to mark parts of the image into detail or detail-a well-considered and robust algorithm for edge detection using the Canny algorithm [9]. Edge detection is a change in the maximum value of the child value to 1 and experiencing a maximum value or a child value to 2 of 0. The Canny filter is a multi-stage edge detector that uses filters based on Derivatives from Gaussian to calculate gradient intensity. There are several steps of the edge detection process, which are as follows.
Noise reduction is a way to remove noise or dirt in an image and apply a gaussian blur to smooth the appearance. If the kernel size is small, then the result of its blur is less clear and vice versa. The canny algorithm detects edges by reducing noise or dirt by the equation [10]. Equation 1 is to reduce noise.
Where Equation 2 is for a Gaussian filter kernel.
Gradient calculation to calculate the gradient of the image in both direction and intensity using the edge detection technique. The power of the edges will change according to the change in the control of the pixels. The gradient calculation g(m,n) uses one of the gradient operators to get. Equation 3 is the image gradient calculation, there are two important properties associated with gradients: 1. the vector G(m,n) points in the direction of the maximum rate of increase of the function f(m,n), and 2. the magnitude of the gradient.
The formula for threshold can express as equation 5.
If T is selected, all edge elements are retained while most of the noise is suppressed.
Non-maximum suppression to obtain pixels by maximizing the values in the direction of the edges and reading all of the points from the gradient intensity matrix. If this is the case, keep MT (m,n) unchanged; otherwise, it should be set to 0.
The double threshold aims to identify three kinds of pixels such as robust, irrelevant, and weak. Weak pixels have low intensity. Limit the previous result with two different threshold values, T_1, and T_2, if T_1> T_2 to get two binary images, T_1 and T_2. Note that T_2 is larger than t_2 and has less noise and fewer false edges but a larger one between the edge segments compared to T_1 with a smaller t_1 Edge tracking by input to turn strong pixels into weak and vice versa. Then, connect the edge segments inside the T_2 to form a continuous edge. To get it, trace each segment T_2 to the end and then trace the T_1 to connect the gap until it reaches the other edge segment in the T_2.

Mask R-CNN
The mask R-CNN is a development of the R-CNN concept that is faster to have two outputs for each object, a class label, and a bounding box. Mask R-CNN has three branches that display object masks in addition to R-CNN and are a natural and intuitive idea. Nevertheless, the other output mask differs from the output and bounding box classes, which requires extracting an object's much better spatial layout. Next, it introduces critical elements of the Mask R-CNN, including pixel-to-pixel alignment, which is a significant part of the missing Fast/Faster R-CNN. R-CNN faster consists of two stages.

K-Means
This study conducted data analysis with the K-means algorithm with the aim of quantitative grouping data into 16 groups. The performance of the K-means algorithm by dividing the data into groups according to the selection of k. K-means algorithms include unsupervised learning without labeling or are often called clustering algorithms [13]. The learning algorithm will be studying the data itself into a dataset by not being marked or classed. The input received is grouped into clusters. Each group has a centroid (central point) to represent the group, according to how the K-means algorithm works as below. Grouping data into groups can be done by calculating the distance system, commonly known as Euclidian Distance, Manhattan, and Minkowski calculated by the spread between 2 data. This study used Euclidian Distance to calculate the distance. Equation 6 calculates the distance with Euclidian Distance.
( , ) = √( 2 − 1 ) 2 + ( 2 − 1 ) 2 (6) Description: , = the distance is a length from a point to another point, example abs(x(i+1) -xi) = Distance Equation 7 is to calculate the central point update [14]. Description: = the main point of the group to k = the amount of data on the group to k = data to q on the group to k 2.4. Classification of SVM Support Vector Machine is a classification algorithm that uses hypothetical spaces consisting of bidirectional linear functions in feature spaces with high dimensions. SVM is used to classify data with only two classes to find hyperplanes with optimal margins [15]. The SVM algorithm applies for statistical vector support, developed on SVM to categorize unlabeled data, and is the most popular clustering algorithm in the application industry. SVM can solve two types of data, namely: 1) Linear SVM is used for separable data, where datasets can be classified into two classes using one straight line; the data is said to be separable linear data, and the classifier used is called SVM linear classifier, and 2) Non-linear SVM is used data separated no linearly, meaning that the dataset cannot be classified using straight lines, so it is called non-linear data and the classifier used is called non-linear SVM [10].

Model Evaluation
The evaluation model is critical in research because the evaluation model used depends on the condition of the research data to maximize the evaluation results by expectations. The evaluation model includes the type of test and the method of testing. For example, a confusion matrix will analyze the success rate of classifiers that can mark records on different classes or labels. In addition to two-dimensional applications, a confusion matrix can also be used in multi classes. The test method with accuracy is the success rate of the predicted value with the actual value. Accounting is the sum of actual data values divided by all negative and positive data. Equation 8 is the accuracy formula.
= + + + + × 100% (8) Testing with precision is a comparison of the amount of relevant information that the model has successfully taken with the sum of all information taken by the model, both positive and negative. Equation 9 is the precision formula.
The recall test method compares the amount of all information obtained by the model with the sum of all relevant ones present on the document. Equation 10 is the recalled formula.
F1 Score is a recall testing method by comparing the amount of all genuinely positive information with a true positive plus false negative. Equation 11 is the F1 Score formula

Results and Discussions
This study had three classes: high, medium, and low. all test results with an evaluation of accuracy, precision, recall, and F1 Score. Figure 3 shows the results of Canny segmentation, where the cow object is given a white edge mark. Algorithms have advantages in research in addition to marking things and can also minimize the size of morphological images.   Figure 5 shows the results of K-means segmentation, the cow image does not seem to experience much difference, but when viewed from the color statistics, it has 16 groups. K-means use 16 groups. K-means use 16 groups so that the naked eye sees a difference.

SVM Classification Results
The classification results use the SVM algorithm with various test ratios between training and validation. Previous studies conducted a division of training and testing models with a ratio of 90:10 and 80:20. The first test performed data splitting, which was 90% for training data and 10% for data validation (90:10) [16], and the second with a test ratio of 80% for training and 20% for validation (80:20) [17]. Figure 6 is the result of a comparison of the three segmentation methods used against the SVM algorithm. At the graph, the maximum impact at the 90:10 train-test ratio is that the K-Means segmentation reaches an accuracy of 90  The results in figure 6 and figure 7 show that each segmentation does test with the SVM classification.
The test is carried out with two types, namely the division of the trial ratio and testing 90:10 and 80:20.

Discussion
Testing using two kinds of ratios, namely 90:10 and 80:20, it turns out that the difference in ratios can affect the results of the model used; for example, in this case, the smaller the test ratio, the higher the model performance is well measured with accuracy, precision, recall, and F1 Score. The best performance study was K-means which used 16 color groups for segmentation.
Segmentation using canny has less than optimal performance in this case; from several tests, the image of FH cows with less than optimal black, white, and red colors results in edge detection corresponding to the morphological shape. Nevertheless, the Canny algorithm is well used to reduce the image size to speed up the training process. On the other hand, segmentation with Mask R-CNN has drawbacks in this study because using mask output, as in figure 4, is not optimal for cleaning the image's background.
Algorithms K-means have a performance for image segmentation by grouping the number of colors used; this case uses 16 colors. Based on the test results, the image quality in the dataset is quite good. In contrast, k-means can group colors to facilitate object recognition, and the image data used has color in cows, so the K-means approach is effective in this study. This study also conducted tests with K=4 and K=8, getting fewer positive results, where the performance was below K=16.
The SVM algorithm has an advantage in image classification by using images with support, namely data close to the hyperplane. In contrast, images far from the line are not used to classify images, so SVM is excellent if it has several datasets with small and medium categories.
In the case of cow morphology images with the SVM, an algorithm dramatically affects the segmentation process; compared to the three methods used by Canny, the ability to detect the edges of objects and reduce the image size turned out to be not optimal using the SVM algorithm. Mask R-CNN, one approach to reducing noise, also does not experience maximum results by using color grouping with K-Means is an excellent performance with machine learning methods. However, in the case of this study, FH cattle images are strongly influenced by color, so the color segmentation approach is very appropriate for classifying objects

Conclusion
The results of morphological image segmentation models can impact optimal performance. Based on research on the classification of the quality of dairy cows to be used as the mothers to be farmed related to milk productivity, using the Machine learning method. The most optimal performance is segmentation using K-Means, reaching an accuracy of 90.29%, Precision 92.49%, Recall 89.39%, and F1-Score 89.95%. The most optimal train-test ratios for this case are 90% and 10% training as validation data. So, the possibility of FH cattle classification is very compelling using a color-based approach because FH cattle have many colors. In this case, the SVM algorithm is perfect for statistics-related issues using color intensity