A Self-Construction of Automatic Crescent Detection Using Haar-Cascade Classifier and Support Vector Machine

Developing an automatic detection method based on computer vision applied to the moon crescent is an innovative concept that can be further developed. This program will be highly useful for observers during the Moon crescent observation because it can help them recognize objects quickly. This paper proposes an automatic crescent moon detection method based on visual mechanisms and training using the Cascade Classifier algorithm. The stages of this method consist of building Haar structural features, extracting feature samples using Haar structural features, and training 981 images consisting of 654 positive images and 327 negative images using the Cascade Classifier. The results show that the crescent moon detection performance is quite good at detecting the crescent Moon. The developed program can recognize crescent moon objects, although it is limited to relatively large lunar illumination in the range of greater than 10% to less than 50%. Furthermore, our program can be applied in real-time situations.


Introduction
The observational method of crescent visibility is still a topic that needs to be thoroughly studied.Moreover, in Indonesia, where Muslims make up most of the population, it is undeniably significant, especially at the start of Ramadhan, Shawwal, and Dzulhijjah months, and frequently causes different timing.Heterogeneities in weather conditions and unique micro-climates related to the locations cause different human perceptions of the new Moon's visibility.Usually, to increase the chance of observing the Hilal (a young crescent or the crescent Moon visible after a new moon; this determines the beginning of a month in the Islamic calendar), we must look for locations where the west horizon sky is free of any obstacles, such as beaches and mountain peaks.Nevertheless, observing the crescent in these places is still very difficult, first because of the different manners of methods and techniques adopted by users when using the telescope.Second, there is the problem of the contrast between the crescent and sky backgrounds.
Another study found that observing crescents with large telescopes produces high magnification while generating a high noise level.Furthermore, there is a low contrast between the crescent and its background, making it indistinguishable.Consequently, it may appear to have a false contour [1].Because noise and artifacts appear alongside true data in some images, subjective judgments rely on the human eye's sensitivity to confirm correct observations.Using spatial filters to extract feature crescents from observed images was investigated as a possible solution [2].This technique can produce accurate results except for images with extremely low SNR (signal-to-noise ratio).
As a result, they suggested a spatial filtering algorithm with a circular window to improve SNR [3] and used many images in a short time to reduce noise [4].Another technique is based on image processing algorithms that use the Circular Hough Transform (CHT) to extract the crescent from the image observation result [5].When the SNR is low, more false edges appear in the detection output, and the CHT method fails to identify the true center.Until now, image processing methods have been the mainstay for detecting the crescent Moon.Image processing refers to the techniques or processes used to analyze images, extract features from images, detect objects, and so on [6].Previously, image processing relied on human visual abilities to assess and analyze objects.As a result, each person will offer interpretation and assessment differently.
The machine learning techniques, especially the implementation of computer vision in astronomy related to the crescent Moon, are fascinating.So far, the most common technique for detecting the crescent Moon has been utilizing human vision and image processing tools to manually enhance the contrast of the crescent Moon.We can use Computer Vision to create algorithms that allow computers to automatically analyze images and videos to recognize information about an object as a basis for decision-making, data processing, and identifying objects [7,8].Machine learning techniques have been applied to astronomical studies, including star-galaxy identification and morphology classification [9,10,11,12].Moon detection using computer vision has also been applied to detect craters on the Moon's surface [13,14].Meanwhile, this study shows how to detect crescent moons automatically using the Harr-Cascade classification approach in combination with the AdaBoost algorithm and Support Vector Machine.

Dataset collection
We used the crescent images database, which contains images from crescent observations using the ITERA Robotic Telescope (IRT) (D = 102 mm, F/8.8) and OZT-ALTS Robotic Telescope (D = 152 mm, F/8) at the ITERA Astronomical Observatory (IAO).A total of 654 crescent images with various sky conditions, shapes, and positions of objects have been used as primary data.The crescent images are displayed as positive images (see Figure 1).In addition, to improve the performance of the training results using the cascade classifier, we added several crescent Moon images with open access permission from various online sites, including 215 images from the website database https://www.mondatlas.de/,37 images from https://www.moonsighting.org.uk/, and 75 images from https://www.astronomycenter.net/.For negative images, we use the dataset of landscape images as negative images from the Kaggle database are open access permission for members and the public (https://www.kaggle.com/).We selected 1000 images of objects such as buildings, mountains, trees, the sea, beaches, roads, etc. (see Figure 2).Haar-like features are extracted from a set of positive and negative images and used as training data to recognize patterns and classify them as objects or non-objects.We chose some negative objects based on general conditions during the practice of observing the crescent Moon, such as mountains, buildings, clouds, electricity poles, rainbows, and other objects.Once the training is finished, we apply each extracted feature to all images used for validation.Each generated feature has the best threshold value for classifying the detected objects as positive or negative.Classification errors can still arise during the validation process.We choose image extraction features with a minimum error rate, indicating that these features are the most accurate in classifying images into crescent or noncrescent categories.If the detection results show features around the crescent moon object, it will be classified as positive, and a box will be drawn around it.If none of the objects are found, the program will classify them as negative images and make the region detection process over.

The proposed algorithm for classifier training
The proposed crescent moon detection technique consists of three steps: The first stage is pre-processing to enhance image contrast using the CLAHE and Threshold to Zero approaches [15], followed by training with a Cascade Classifier on positive and negative images [16], and finally, testing for crescent moon detection.The Cascade Classifier training process consists of the following steps: • Feature extraction using a Haar-Wavelet of 24 × 24 pixels.The process will combine the black and white boxes by subtracting the average pixels in the dark area from the average pixels in the lighter areas.• Integral image processing to rapidly determine the presence of objects in all Haar features created • The process of removing features considered inappropriate by combining weak classifiers to produce a robust classifier, also known as adaptive-boost (AdaBoost).• The object validation process uses the Support Vector Machine (SVM) method.The function of SVM is to obtain optimal hyperplane or classifier values that can separate two sets of data from two different classes [17].

The experiment
We used the results of previous training on detecting a crescent moon object using the Cascade Classifier for the experiment.Then, we tested it with two cameras on an image of a crescent object.First, we used an HD Web Camera with a resolution of 2 Megapixels and a rate of 30 frames per second (fps) to detect crescents with varying illumination displayed on the smartphone screen.If the object is successfully detected, a green box will appear to indicate that the program has detected the object.In the second experiment, we used images from the Manta G-031B camera mounted on the OZT-ALTS robotic telescope to see how effectively our training program could detect the crescent moon object.Manta G-301B has an exposure time of 58 μs to 60 s with a maximum rate of 125 fps and a quantum efficiency of 71% at 529 nm.The camera has a field of view of 21 × 15 arcseconds.If the object is successfully detected, the object detection results using the cascade classifier will be displayed sequentially based on Haar features.

Applying Contrast Limited Adaptive Histogram Equalization (CLAHE)
The first step before applying contrast enhancement is to convert the original image (see Figure 4) into a grayscale image.Figure 4 shows the existence of a crescent.If the arrow is omitted in the original image by the naked eye, the existence of the crescent object is very difficult to identify.Therefore, image processing techniques are needed to increase object contrast.The CLAHE method increased contrast in object areas and reduced noise by determining the kernel matrix.It works by calculating the average of the kernel weighting values for each neighbouring pixel and the pixel itself for each input image pixel.The results of the contrast and histogram changes with CLAHE are shown in Figure 5. Figure 5 presents images and their histogram distributions obtained using two different methods.The left-most image is the original image converted to a grayscale image.The middle image is obtained by histogram equalization (HE), and the right-most images are obtained using CLAHE.HE distributes pixels equally at all levels, producing a uniform distribution of grey levels for the resulting image, but eventually, much noise is produced with this technique.Meanwhile, the result of CLAHE shows that it is clearly superior in preserving details and significantly enhances the image's quality.The CLAHE method is very effective in automatic image processing that is fast and sensitive to changes in the contrast between objects and their backgrounds.According to the test results, it only takes 2.3 milliseconds.Image processing-derived quantitative metric feature values typically employ Root Mean Square Error (RMSE) and Peak Signal-to-Noise Ratio (PSNR) calculations [18,19].The mean square error (MSE) is the most widely used and straightforward complete reference metric for determining image quality.It is calculated by averaging the squared intensity differences of distorted and reference image pixels with the related quantity's peak signal-to-noise ratio (PSNR).Because the bit depth of the Manta camera is 12-bit, the image quality after CLAHE should be between 30 and 70 dB.The RMSE and PSNR values are 0.015 and 36 dB, respectively.

Automatic Crescent Detection Test Result
After the training process using the cascade classifier approach is finished.The next stage is testing the image containing a crescent moon object.Some images from the observation result will be transformed to grayscale so the trained detection program can detect the crescent object.The detection process using the Cascade Classifier will apply Haar-like features in a rectangular shape to compare pixels that contain 10th Asian Physics Symposium (APS 2023) Journal of Physics: Conference Series 2734 (2024) 012007 IOP Publishing doi:10.1088/1742-6596/2734/1/0120076 information about objects and neighbouring pixels that do not contain objects.The detection results can be seen in Figure 6. Figure 6 shows the success of the data that has been trained with a cascade classifier, being able to detect crescent objects by selecting the highest intensity.It can be seen that the white rectangles represent pixels that contain parts of the image with higher intensity and would, therefore, be "whiter" in the grayscale image.
As you can see, the algorithm classifies the transition from the top left to the bottom right until the crescent object can be detected, represented by a Harr-like feature that dominates the region of interest object.This is just one example of how the algorithm could classify these parts of the crescent.The program's success in recognizing the crescent Moon is highly reliant on the conditions (i.e., obscured by clouds), the light source of the crescent Moon coming from various angles, and the camera's Field of View (FoV).Figure 7 shows the results of real-time object detection using a web camera.We tested the crescent detection program with various crescent moon shapes and illumination to see whether it correctly detected and recognized crescent objects.The test results showed that the program we developed by training with 981 images successfully detected the crescent Moon in real-time using a web camera.considered non-objects.This is because the data provided during training using the cascade classifier is only limited to lunar objects with an illumination phase less than 50%, so objects with an illumination greater than 50% are classified as non-objects.This study aims to distinguish only the crescent Moon rather than the Moon in all phases.The results of the successful detection test using a webcam are shown in Figure 7, where a green box appears automatically when the program detects an object in the form of a crescent moon.The system will look for crescent moons and mark them with a green box in all pixels in the presented image.The program takes between 0.5 and 2 seconds to detect the correct object and then provides the object's coordinates in the image.

Conclusion
The study concluded that the Haar-Cascade Classifier detection method successfully detected crescent moon objects in high-contrast images.Therefore, image pre-processing is required using CLAHE before being applied to the crescent object to be detected.From the experimental results, the cascade-AdaBoost-SVM classifier proves suitable for separating the two databases.In addition, it can also solve the SVM problem, which is time-consuming when deploying to a large set of training samples, and generate a higher percentage of the detected crescent object.This system can be used effectively in practical applications to detect crescent objects, making it easier for observers to distinguish between the crescent and other objects in real-time, such as cloud strokes or other terrestrial objects.

Figure 3 .
Figure 3. Flowchart of the training process using a Haar -Cascade classifier using AdaBoost Algorithm and Support Vector Machine (SVM).

10thFigure 4 .
Figure 4.The results of the waning crescent observation before the new moon observation in the month of Shaban 1443H.

Figure 6 .
Figure 6.The sequential process of object detection using Haar-like features.

Figure 7 .
Figure 7. Implementation of the Haar-Cascade Classifier with AdaBoost and SVM for crescent detection.

Table 1 . Illumination Test Result Moon Illumination (%) Cascade -AdaBoost Cascade -AdaBoost -SVM Estimation Time Detection (s) Accuracy Detection Rate (%) Estimation Time Detection (s)
Table1shows the test results of various lunar illumination detection accuracy levels.When tested on the Moon, which has a phase greater than 50%, there is a discrepancy in results.Lunar objects are [1] Gonzales R C, Woods R E and Eddins S L 2020 Digital Image Processing Using Matlab Third Edition (Gatesmark Publishing) [2] Fatemi S and Lesani M 2008 3rd Calendar Conference [3] Rezaiee H, Bromandnia A, and Feiziderakhshi M R 2011 3rd National Conference on Computer Science and Information Technology [4] Elsässer M 2010 2nd Emirates Astronomical Conference 10th Asian Physics Symposium (APS 2023) Journal of Physics: Conference Series 2734 (2024) 012007