Enhanced Canny edge detection for Covid-19 and pneumonia X-Ray images

In image processing, one of the most fundamental technique is edge detection. It is a process to detect edges from images by identifying discontinuities in brightness. In this research, we present an enhanced Canny edge detection technique. This method integrates local morphological contrast enhancement and Canny edge detection. Furthermore, the proposed edge detection technique was also applied for pneumonia and COVID-19 detection in digital x-ray images by utilising convolutional neural networks. Results show that this enhanced Canny edge detection technique is better than the traditional Canny technique. Also, we were able to produce classifiers that can classify edge x-ray images into COVID-19, normal, and pneumonia classes with high accuracy, sensitivity, and specificity.


Introduction
Edge detection is a fundamental image processing technique for locating the borders of objects in images. It works by identifying disjointedness in brightness. One of the edge detection algorithms is Canny. Edge detection methods can produce a new set of features. Edges are noted by serious or local changes in the image, and edges normally occur on the borders between two distinct areas in an image. Edges are important features for analysing digital images [1], [2]. Numerous edge detection techniques are available.
Traditional gradient-based edge detection techniques like Robert, Prewitt, Sobel were among the first algorithms proposed, but they are sensitive to noise conditions and did not give sharp edges [3]. Some flaws of Laplacian operators' flaws are a high likelihood of identifying false edges and huge localization error at rounded edges [2]. Canny proposed a multi-stage edge detection algorithm, and this technique is deemed as the optimal edge detection technique for images that with noise [4]. Canny proposed the optimum edge detection procedure that decreases the likelihood of identifying fake edges. Canny edge detection also gives sharp edges. However, the traditional Canny edge detection also has flaws. One of which is that the even though Gaussian filtering removed the noise, the important edges were also removed or smoothed [5]. This weakened the edges and increases false edge detection.
X-ray is a type of medical image in which a part of the patient's body is exposed to a minor dose of ionizing radiation, producing pictures of the body's inside. X-ray helps physicians treat and diagnose medical conditions [6]. In this research, we present an enhanced Canny edge detection method. Furthermore, we also apply the proposed edge detection technique for COVID-19 and pneumonia detection in digital chest x-ray images by utilising convolutional neural network (CNN).

Literature Review
In this section, the concepts of morphological contrast enhancement and Canny edge detection were presented. The usage of deep learning techniques in COVID-19 and pneumonia detection was also discussed.

Morphological Contrast Enhancement
Morphology image processing are processes that manipulate images based on structuring elements. Morphological operations accept an image as input, apply a structuring element to the image, and outputs the resulting image. The pixel of the output image is determined from a comparison between the corresponding pixel of the input image with its neighbours.
In morphological contrast enhancement, a filter is applied. If the central pixel is closer to the local maximum, this filter replaces it with the local maximum. Else, the central pixel is replaced by the local minimum. Figure 1 shows the pseudocode implementing morphological contrast enhancement.

Canny Edge Detection
The Canny edge detection technique is a multi-step procedure. A good edge detection algorithm should be able to detect edges with a low error rate, localize edge point on the centre of the edge, and mark an edge only once.
The Canny filter is a multi-stage edge detector. First, noise reduction was performed by implementing Gaussian smoothing. Then, the intensity gradient of the image is computed so that nonmaximum suppression can be employed. Likely edges are reduced to 1-pixel curves by discarding nonmaximum pixels of the gradient magnitude. Lastly, hysteresis thresholding is performed to determine whether or not to keep the edge pixels. The detailed explanations for Canny edge detection are as follows: Step 1: Noise Reduction Before attempting to locate and identify edges, noise reduction is carried out to remove noise in the original image. The noise here refers to a random variation of color or brightness in the image. Canny edge detection uses the Gaussian filter to perform noise reduction. A Gaussian mask is calculated and applied using standard convolution methods. In short, a Gaussian filter was used to smooth the image to reduce unwanted textures and details.
Step 2: Calculating Intensity Gradient After noise reduction, the image gradient is calculated to obtain the edge strength. The edge strength is also known as the absolute gradient magnitude. A 2D spatial gradient calculation is performed using the Sobel operator. This operator uses two convolutional masks to estimate the x-direction gradient and y-direction gradient. We can find the edge gradient as follows: Once the x and y gradients are known, the following formula can be used to find the edge direction: Step 3: Non-maximum Suppression After obtaining the gradient direction as well as the gradient magnitude, non-maximum suppression was performed. This was done to remove pixels that might not be a part of an edge. Each pixel is inspected to see if it is a local maximum in its neighbourhood in the direction of the gradient. This will result in a binary image with "thin edges".
Step 4: Hysteresis Thresholding This step classifies edges into real edges and fake edges. Two threshold values are needed, which are min-value and max-value. All edges with an intensity gradient greater than the max-value are considered as "sure-edges", thus kept, and any edges under the min-value are considered as fake edges, thus removed. The remaining lines that are between these two threshold values are categorised into real edges and fake edges based on their connection. If they are joined to "sure-edge" pixels, they are counted to be part of an edge. If not, they are also removed. Figure 2 provides some examples.

Figure 2. Hysteresis Thresholding.
Edge A is over the max-value, so it was counted as "sure-edge". Even though edge C is under maxvalue, it is joined to edge A, therefore it was counted as a proper edge and the full curve was obtained. Even though edge B is over the min-value and also in the same area as edge C, it is not joined to any "sure-edge", so is was removed. Therefore, it is highly imperative to choose max-value and min-value appropriately to obtain better result.
This step also assume that edges are long lines. Therefore, small pixels noises were discarded. Finally, an image with strong edges is produced.

CNN for COVID-19 and Pneumonia Detection
COVID-19 is diagnosed by the reverse transcription polymerase chain reaction (RT-PCR) test [7]. COVID-19 is caused by severe acute respiratory syndrome coronavirus 2 (SARS-CoV-2), and RT-PCR can detect SARS-CoV-2 strain. To perform the RT-PCR test, a swab is inserted into the nostril of a patient and gently moved into the nasopharynx to collect nasal secretions sample. The sample obtained will be used for the RT-PCR test. However, radiologists can also use chest x-ray images to identify COVID-19 infection [8]. On the other hand, pneumonia can also be detected from a chest x-ray [9]. However, COVID-19 share similar imaging features with pneumonia [10]. Therefore, it is imperative to speedily and accurately differentiate people infected with COVID-19 and people infected with pneumonia. Deep learning methods were proposed to carry out classification between healthy lungs, COVID-19 infected lungs, and pneumonia infected lungs [11]- [15]. [11] used CNN to classify computed tomography scan images into normal COVID-19 and Influenza-A-viral-pneumonia, infected lungs. [12] trained a CNN and used data augmentation such as horizontal flip, rotation, translation, and intensity shift to perform 3-class classification (normal, pneumonia and COVID-19) on chest x-rays. [13] and [14] both implemented similar classification using CNN while utilising transfer learning, classifying chest x-ray images into normal, viral pneumonia and COVID-19 cases. [15] utilised CNN as a fixed feature extractor, and used a support vector machine (SVM) for classification.
The usage of CNN contributed to the performance of these lung disease detection. CNN is very suitable for image classification and object detection because it automatically extracts and learns features, discarding the necessity for manually extracting features. The usage of deep learning can speed up the disease identification process [16].
In this paper, we demonstrate that it is possible to detect COVID-19 and pneumonia by only using edge images. Edge images were considered because edges represent the shape feature of an image, and shape is an important and powerful feature used for image classification [17]. Previous studies also showed that lungs with diseases produced unusual edges compared to normal lungs [18] [19].

Literature Review
In this section, the enhancement of Canny edge detection is explained. Subsequently, to investigate the benefit of our edge detection method, we applied the edge detection technique to several datasets which will later be used for COVID-19 and pneumonia detection.

Contrast Enhanced Canny Edge Detection
In this project, a method named Contrast Enhanced Canny Edge Detection (CEED-CANNY) was proposed. This method combines local morphological contrast enhancement and Canny edge detection.
First, morphological contrast enhancement was performed on a grayscale image, subsequently, Canny edge detection was applied. In morphological contrast enhancement, a filter is applied. If the central pixel is closer to the local maximum, this filter replaces it with the local maximum. Else, the central pixel is replaced by the local minimum. Afterwards, Canny edge detection was implemented to identify edges existing in the x-rays. Figure 3 Figure 3. Pseudocode for Contrast Enhanced Canny Edge Detection.

Application of the Edge Detection technique for COVID-19 and Pneumonia Detection in Digital X-Ray Images Using CNN
To conduct COVID-19 and Pneumonia Detection on Edge X-Ray using CNN, first, datasets were obtained from various sources. The datasets used were: Joseph Cohen's GitHub repository [20], Andrew's Kaggle dataset (available at https://www.kaggle.com/andrewmvd/convid19-X-rays) and Kermany's dataset [21]. These datasets contained x-ray images with lung conditions of COVID-19, pneumonia, and normal (healthy). 196 images from each lung condition were collected. Thus, a total of 588 images were used in this experiment.
Next, Contrast Enhanced Canny Edge Detection was applied to all the images, producing x-ray images with only the edges. This will be known as the Edge dataset.
Afterwards, the Edge dataset was divided into two separate sets. 90 percent of the images were put in a training set, while the remaining 10 percent were put in a testing set. The training set was used for classifier training, while the testing set was used for testing.
For training, two CNN architectures, namely VGG16 [22] and InceptionV3 [23], were used to extract features from these images. Then, the features extracted will become the input for a new model. And this produces two classifiers, namely VGG16 classifier and InceptionV3 classifier.
For testing, the VGG16 classifier and InceptionV3 classifier were used to classify the images in the testing set. Their accuracy, sensitivity, and specificity were recorded. False positive (FP), false negative (FN), true positive (TP) and true negative (TN) were recorded to determine accuracy, sensitivity, and specificity.
True positive rate, or more commonly known as sensitivity, is the likelihood that a test result will be positive when the disease is present.
(%) = + × 100 True negative rate, or more commonly known as specificity, is the likelihood that a test result will be negative when the disease is absent. Accuracy is the overall probability that a patient will be correctly classified.

Results and Discussion
For this research, two tests were conducted. The first one was the mean square error (MSE) test. This test was used to compare out edge detection method with the traditional Canny method. The second test was COVID-19 and Pneumonia Detection on Edge X-Ray Using CNN. This test was conducted to demonstrate that it is possible to detect COVID-19 and pneumonia by only using edge images.

MSE Test
In this section, we compare our CEED-CANNY with the traditional Canny technique. To compare their performances, MSE test was performed. The MSE permits the calculation of the "true" pixel values of the actual image to the noisy image. The average of the squares of the "error" between the original image and the degraded image are signified by the MSE. The error here refers to the difference between the values of the actual image and the noisy image. A lower MSE means that the image is produced with a better quality. The MSE is represented in the following mathematical equation: -m is the number of rows in the image, while i is the row index -n is the number of columns in the image, while j is the column index -f is the matrix of the actual image -g is the matrix of the noisy image in question -MAXf is the maximum signal value that in the actual image Five chest x-ray images were selected as samples. These images were obtained from Kermany's dataset and Cohen's dataset. Figure 4 to Figure 8 show the output images of Canny and CEED-Canny respectively.    Both techniques were able to detect edges remarkably. From our observation, the CEED-Canny method produced more edges. Table I shows the result of the MSE test.

COVID-19 and Pneumonia Detection on Edge X-Ray Using CNN
To investigate the benefit of our edge detection method, we applied the edge detection technique to produce an alternate dataset for COVID-19 detection. After the test was conducted, the results were taken and recorded.  Based on the result, it is established that the classifiers were able to categorize edge images into COVID-19, normal, and pneumonia cases. Not only that, but the accuracy, sensitivity, and specificity were quite high.

Conclusion
This paper presents a modified Canny edge detection method. This method, named CEED-Canny, was the combination of local morphological contrast enhancement and Canny edge detection. The MSE values for the proposed method was lower than that of the traditional Canny method. Furthermore, this paper also showed that edge images can be used to train COVID-19 and pneumonia detection classifiers with high accuracy, sensitivity and specificity.
There are some limitations to this study. First, even though CEED-Canny performed better when compared to the traditional Canny method, no comparison was made with other edge detection methods. This is because not all articles that proposed edge detection methods include source codes, and the sample images used are different. Future studies may perform a survey of all the recent edge detection method, and come up with a standardized test. Second, this lung disease detection approach was only tested on a relatively small dataset. In the future, more data should be gathered for training and testing, as this will most likely improve the classification accuracy and generalizability.