Paper—A Portable Cattle Tagging Based on Muzzle Pattern A Portable Cattle Tagging Based on Muzzle Pattern

This research focuses on developing an Android-based cattle identification system that is applicable and easy to use. This system uses a Scale Invariant Feature Transform (SIFT) algorithm to extract features from the muzzle images, and Random Sample Consensus (RANSAC) algorithm to eliminate features incompatibility. The system is experimented with four threshold values, i.e. 10, 15, 20, and 30 using a total data of 460 muzzle images. In the first experiment, 3 images from each individual are used in the training stage and 2 images are used as the data test. In the second experiment, 5 images from each cattle are used in the training stage and 5 images are used as the data test. Data used in training stage are 244 images and in testing stage is 816 images. From the experiment, the highest accuracy rate is 98.1% with threshold values of 15 and 20. The execution time is also calculated to measure the processing time of the system. The average time taken to store an image to the database is 1.3 seconds. The main contribution of this research is technology implementation and more portable muzzle identification for local cattle in Makassar. Keywords—Cattle identification, SIFT, RANSAC, muzzle pattern.


Introduction
Identifying livestock, especially cattle, is an important issue in maintaining livestock availability. Cattle identification is related to livestock management and tracking, which are necessary parameters to breed, inseminate, and distribute the cattle. Cattle identification can also prevent the occurrence of cattle manipulation [1]. Not only for the rancher, but cattle identification is also an essential issue for veterinarians. The rapidly increasing stock also brings up problems related to the health of cattle. Cattle identification is also important for production management, disease management, legal ownership validation, and monitoring and tracking of livestock [2].
Traditionally, there are several methods to identify cattle, which are ear tagging, branding, and neck labeling. However, those methods still have drawbacks in their applications. Branding and ear tagging require a lot of time, inconvenient, and can be hurtful to the cattle. The labels used in the labeling method are often lost, broken, or covered with dirt [3]. In addition to the traditional techniques, researches have been conducted for the same purpose, such as SURF (Speed Up Robust Features), which produced an accuracy of 93.87% [4]. Moreover, another research used SIFT (Scale UMSGC-SIFT demonstrated better performance in HSI matching and classification than several other algorithms. The average accuracy with the proposed UMSGC-SIFT is 91.38%, which is 3.64%, 6.03%, and 21.70% higher than 3D SIFT, 3D Harris, and 2D SIFT, respectively [11].
Despite the outstanding results of previous systems, they are built on immobile platform. Therefore, the use of mobile device such as smartphones should be regarded. Several researches have already tried to embed computer vision technology into smartphone and proved that it can be a more convenient alternative to a computer-based system. For example, mobile learning application to facilitate children in learning of simple multiplication, Javanese letters classifier with mobile client-server architecture, and smartphone-based image color correction for color blindness [12][13] [14].
This research presents an android based cattle identification based on muzzle pattern. The system is built using Android Studio and OpenCV library. Scale Invariant Feature Transform (SIFT) is implemented to identify and extract features from the muzzle image. SIFT detects features by searching for DoG (Difference of Gaussian) in a scalespaced image. Each feature found will be assigned a descriptor to distinguish one feature from another. Then, the features obtained using the SIFT method will be compared with features from other images to determine whether the image is from the same cattle or not. Identification is done by calculating the distance or length of each feature descriptor. However, it was found that some features have similarities. Therefore, the Random Sample Consensus (RANSAC) method is used to eliminate the incompatibility of the features. The system is experimented using 10, 15, 20, and 30 thresholds (hereinafter referred to as Th) to determine which Th value fits the system best.

2
Background Theory

Object recognition using computer vision
Computer Vision can be briefly interpreted as a way to make a computer understand the contents of images and videos. The core of the computer vision is how to give a computer such abilities of the human eye. Computer vision processes image data using a particular algorithm so that the computer can extract information from an image or video. Generally, computer vision is comprised of several steps, namely image acquisition, image preprocessing, quality enhancement, feature extraction, and image storage and access to the database. Various kinds of real-world applications using computer vision include optical character recognition (OCR), face detection, object recognition, 3D model building, automotive safety, and surveillance system [15].

Muzzle pattern
The process of recognizing individual animals conventionally such as ear tagging and tattooing has weaknesses. In 2016, Awad conducted research to look for biometric information from cattle muzzle. The process of recognizing individual animal conventionally such as ear tagging and tattooing has weaknesses. Therefore, the results of his research prove that in addition to iris, cattle muzzle patterns also become biometric features for animals such as cow and buffalo [16]. Hybrid feature extraction and recognition for the identification of cattle with muzzle pattern had been presented in 2016. The system used 5000 images of muzzle cattle with eight texture features for recognition. The result of this proposed by applying KNN and Fuzzy KNN classification technique is 94.5% and 96.74%, respectively. The system can provide better solutions to problems of registration, missed, swapped, false insurance claims, and traceability of cattle in the classical animal recognition-based methodologies [17].
The presentation related to the classical recognition of animal biometrics was also carried out by Kumar and Singh in 2019. Not only in muzzle cattle but special characteristics of other animals such as Fowler's toad species and face of Chimpanzee are biometric characteristics. In this research, animal biometric-based cattle recognition systems are demonstrated to solve the biggest problems of missed, swapped and reallocation at slaughterhouses of animals by recognizing the biometric characteristics. The use of several algorithms for the extraction of features from the animal is also presented so that a state of the art for face and muzzle-based biometric feature recognition is formed [18].
Cattle's muzzle is a unique physiological part of the cattle body. Muzzle pattern is a dermatoglyphic trait of cattle similar to fingerprints in human beings. Similar to human fingerprints, cattle muzzle prints have some discriminative attributes known as beads and ridges. The bead is an irregular region looked like an island, and the ridge is an elongated area that looked like a river with irregular widths [1]. These features are the determinants in cattle identification. Figure 1 shows the beads and the ridges of the muzzle pattern.

Scale Invariant Feature Transform (SIFT)
The SIFT method is a means in the computer vision field, which can be used in image and object detection. Unlike other methods, SIFT is invariant or not affected by the rotation and scale of the image. There are mainly four steps involved in the SIFT algorithm which are Scale Space Extrema Detection, keypoint localization, orientation assignment, and keypoint descriptor. Scale Space Extrema Detection is done using a scale-spaced method, carried out by generating several octaves of the original image. The size of each octave is half the previous one. Within an octave, images are progressively blurred using the Gaussian Blur operator to reduce the details of the image.
The blurred images are used to generate another set of images, the Difference of Gaussians (DoG). The function of DoG operation is to simplify the search of keypoints by subtracting images in one octave. The candidates of features or keypoints are obtained from the DoG images by locating the maxima and minima values of the image. The next step is keypoint localization. This step is carried out by iterating through each pixel and check all of its neighbors. The checking is done within the current image, and also the one above and below it. Some of the keypoints found lies along an edge, or do not have enough contrast. In both cases, they are removed using the Harris Corner Detector.
The next step is the orientation assignment. The features are given orientation by specifying the direction of the gradient and value of pixel around the features. This step is needed to ensure the features will not be affected by rotation. Each feature is given a descriptor to distinguish one feature from another. At this stage, the gradient in the local image is measured using a scale value. The scale is obtained from around each keypoint area. Then it is transformed into a representation that makes the features invariant to lighting or orientation changes on the image [19].

Random Sample Consensus (RANSAC)
The RANSAC algorithm is an algorithm for the robust fitting of models in the presence of many outliers. RANSAC attempts to eliminate the outliers and find a linear model that only uses the inliers in its calculation [20]. This process is done by fitting linear models to several random samplings of the data and returning the model that has the best fit to a subset of the data.

Proposed System Scheme
The data collection process was carried out in three locations, which are Integrated Animal Husbandry of Hasanuddin University, Samata Animal Slaughter House and Farmer Group's Animal Husbandry in Tanete Riaja District, Barru Regency, Indonesia. The images are taken within 15-20 cm from the cattle to simulate a real-world application. Some cattle are sensitive, so extended hardware must be attached to their muzzles to assist researcher when taking the image, which can be seen in Figure 2. In this research, the data collection process was conducted twice. On the first data sampling, the data was collected from 28 individual cattle, where 5 data sampling are taken from each individual. In the second data sampling, 10 data were collected from each individual from 32 cattle. The total images collected are 460 images. Example of the muzzle image can be seen in Figure 3.

Fig. 3. Example of muzzle images of a cattle taken in different angles
Generally, the system can be divided into two stages, which are the recording stage and the matching stage. The recording stage starts with data acquisition in the form of muzzle images. Then, pre-process methods are applied to uniform all the images. From the images, the feature extraction process is carried out, and the obtained features are saved to the database.
If there is a new image data, the feature extraction process will be performed, and the features will go through the matching stage. The features will be compared with the features that exist in the database. If the number of matching features exceed certain Th value, the cattle will be identified. Otherwise, the cattle will be unidentified. Figure 4 shows the illustration of the system.

Recording stage
Recording stage is the process where the features are recorded and saved into the database. The recording stage is composed of several steps. The first step is to input the data to the system, which is the images obtained from the data acquisition process. The total images used in the recording stage is 244 images. The images are taken in broad daylight using Xiaomi Redmi 4A smartphone with a resolution of 3120x4160 pixels and in jpg extension. These images then will be preprocessed to make it suitable for the system and to prepare them for further processing. The next step is image preprocessing that is comprised of several steps, namely Region of Interest (RoI), cropping, grayscaling, and histogram equalization. The result of each preprocessing step can be seen in Figure 5. Image cropping is performed to fit the Region of Interest (RoI), which is a portion of an image that becomes the concern or interest. The RoI of this system is the specific area with a size of 300x300 pixels in the middle of the muzzle. The second step is to transform the image from RGB to grayscale. This is needed to reduce the color complexity of the image. The last step is histogram equalization, which is a technique used to increase the contrast of an image by adjusting the intensity of the image. This will increase the possibility of feature detection and extraction to be more accurate.
The output of the preprocessing will be used in the feature extraction process, where SIFT algorithm is applied to extract the features from the muzzle image. SIFT algorithm will create several versions of original images that vary in size and blurring level. This was done to create features that were not affected by scale changes.
After that, the obtained features are given orientation by specifying the direction of the gradient and the value of the pixel around the features. The values and orientations are calculated around the feature area which then will be visualized in a histogram. This process aims to make the image invariant to orientation changes. The result is shown in Figure 6.

Recording stage
In the matching stage, the initial steps are carried out generally the same as in the recording stage which includes input data, image preprocessing and feature extraction. Following these steps is the feature comparison process, which is performed by calculating the distance or length differences between the feature in the test data and the feature that already exist in the database. If the results of the comparison do not differ significantly, then it can be concluded that the features are matched. Figure 8 shows the result of feature comparison. The RANSAC algorithm is used to eliminate the outliers by looking at the similarities of the form of features, not by the distance. In this research, RANSAC algorithm can be divided into 3 parts, which are sample, model, and score.
In the sampling process, coordinate points are created based on the index of the features of the two images that have been obtained from the previous process. The next step is to create models. In this stage, five random coordinate points are selected to be proposed as the models. The sample features are then used as a reference in finding similarities from other features. This process will be performed repeatedly to the specified number of iterations. Every iteration is followed by scoring the models that have been produced. Finally, a straight line will be drawn to take the features that have similarities with the models. Then, the number of scores is calculated, which are the coordinate points located close to the line. The model with the highest score will be considered as the optimal model. It can be seen that there are not many matching features, so the whole process will be iterated until a good model is found. Figure 10 shows a model that gets a high score so it is considered suitable to be a model. It can be seen that many coordinate points approximately can be fitted to the line. The output of the matching stage is the decision on whether the test data was identified successfully or not. The result depends on the number of matching features. If it exceeds the assigned threshold, then the cattle will be identified.

Results
The experiment is conducted twice. Each experiment is carried out using Th value of 10, 15, 20, and 30. In the first experiment, 3 images from each individual are used in the recording stage and 2 images are used as the data test. In the second experiment, 5 images from each cattle are used in the recording stage and 5 images are used as the data test. Total images used in the training stage are 244 images, while 216 images are used as positive testing data. In addition, 600 data are used to find out how the system will perform using negative data. In total, there are 816 data used in the testing stage.
The performance of the system is measured using the confusion matrix that will count the number of correct and incorrect predictions and classify them into 4 categories. These categories are True Positive (TP), False Negative (FN), False Positive (FP), and True Negative (TN). TP is data in the database that successfully recognized by the system, and TN is data that does not exist in the database and is not recognized by the system. Both are considered as positive results. On the other hand, FP is data recognized by the system but does not exist in the database, and FN is data that unrecognized by the system but present in the database. From the confusion matrix, the system accuracy can be calculated using Equation (1): The accuracy of each Th value represented using the confusion matrix are shown in Table 1.
iJIM -Vol. 14, No. 13, 2020 The lowest accuracy is obtained using 10 Th value, which is only 81.48%. This is caused by features of similarities that exist in each data. These similarities will make two different objects considered as the same object by the system due to the number of matching features between those images. Therefore, when fault tolerance is increased to 15 and 20, the number of FP immediately increases. Meanwhile, the accuracy rate decreased to 95.1% when Th 30 is used. This is caused by the number of matching features that are under the Th value. Therefore, only a few data pass the fault tolerance and categorized as TP data.
The process of saving all the data to the database takes the longest time, which is 336.3 seconds. It means that every image takes 1.3 seconds to be stored in the database. The average time for comparing the features and extracting features from an image is 120.06 seconds and 8.7 seconds respectively.
The determinant that affects the amount of time for storing the feature in the database is a large number of data. The amount of time needed for the features comparison process is affected by the search method, which compares the test data to all data in the database. The execution time is also influenced by SIFT algorithm that detects features at each point or pixel in each image. Therefore, the greater the image resolution, the more time it takes to detect the features.
Implementation of the SIFT method is very suitable to be applied to identification problem related to feature detection and feature matching. This is because the SIFT method will try to find unique and repetitive features from the muzzle images. The test data in this study were also taken with several types of angles and distances (15-20cm). This process is carried out to simulate conditions in the field directly. The SIFT algorithm has advantages such as being invariant to rotation, scale, light, and noise can be proven in this study. Therefore, the SIFT algorithm can be applied to the muzzle, which is a biometrics feature of cattle.

Conclusion
Cattle identification system based on the muzzle pattern is applied to a smartphone with Android operating system. The SIFT algorithm is applied to detect and extract the features, and RANSAC algorithm is used to eliminate incompatible features. This system is tested to 60 muzzle images and it is capable to identify cattle with the highest accuracy of 93.05%. The average time needed by the system to store the features to the database is 336.3 seconds. This is the highest processing time when compared to the data matching process time that only needs 120.06 seconds.
Sri R. A. Bugiwati was born in Bandung, West-Java, Indonesia. She received a bachelor's degree in Animal Husbandry from Universitas Padjajaran, Ban-dung, Indonesia in 1993. She also received a Master of Science in Animal Breeding from Miyazaki University, Jepang in 1988 and Doctor of Philosophy in 2001. She studied on Selecting Japanese beef cattle using Body dimension and ultrasound machine. Now, she focuses some researches related to animal breeding, animal selection, the biodiversity of livestock (focus on Bali cattle, native goat, native singing chicken).
Anugrayani Bustamin was born in Sengkang, 1 December 1990. Graduated S1 Informatics Engineering majors on Universitas Hasanuddin, Makassar. In 2014 continuing education in Informatics Engineering Study Program, Department Of Electrical Engineering, Universitas Hasanuddin, Makassar, Indonesia. As students also joined the of research group in artificial intelligence and multimedia processing (AIMP) Universitas Hasanuddin. Her research interests include speech recognition and natural language processing.
Muhammad Rahmatullah studied Informatics Engineering in Universitas Hasanuddin. He passionate about Artificial Intelligence and Mobile Technology, those passion made him decided to pursue his research in Image Processing on mobile devices in AIMP (Artificial Intelligence and Multimedia Processing) research group at Universitas Hasanuddin. During his leisure time, he enjoyed read self-improvement books and playing basketball.