# Using Double Convolution Neural Network for Lung Cancer Stage Detection
## 3 Medical Image Classification Using Double DNN
### Data Preparation  
The data preparation is a crucial part in DNN training and testing. In our case, data preparation was done in several stages. The CT images were obtained from the Image & Data Archive of the University of South Carolina and the Laboratory of Neuro Imaging (LONI) database, (ida.loni.usc.edu). These images were analyzed and classified by medical personnel (as cancerous or not) by performing a biopsy of the lung cancer tissue to ensure high level of certainty about the labeling. The initial dataset contains CT scans of patients. When a patient does a CT scan, the scanner takes many images of the lung of the patient; each of these images is from a different part of the lung. These images are called slices (different angle images), which capture different parts or angles of the lung. Thus, one CT scan of one patient can produce many slices, and each of these slices is saved as an image. First, the initial dataset was divided into two piles; the first pile contained images from patients that were diagnosed with cancer, and the second pile contained images from patients without cancer. Thus, the two piles divided the images into cancerous or cancer-free. Next, the images of the two piles were further divided into groups, where each group contained images (slices) from the same part of the lung but from different patients. The initial dataset had 95 patients, where each patient had gone through one CT scanning process. One such process produced 64 CT images (slices) of the chest of the patient. This means that the initial dataset had 6080 images that the DNN used for training and testing. One of the 64 slices (images) is shown on Figure 1. Next, these images were labeled by medical personnel as cancerous or cancer-free and the initial dataset was divided into the two piles. In our case, we had 73 patients who were diagnosed the possibility of cancer (Pile 1) and 22 who were without cancer (Pile 2). Next, we needed to further group the images in the two piles, where each group represented images from same slice (angle of the chest of the patient). This way, we created 64 groups within each pile, where each group in Pile 1 (cancer pile) had 73 CT images. Each of the 64 groups of Pile 2 (cancer-free pile) had 22 CT images. A sample of different angle (slice) CT images is shown on Figure 2. The middle image is cancer-free (belongs to Pile 2) and the other two are with marked location of the cancer (form Pile 1). Creating the piles of images was done so that we can create positives and negatives to train and test the network, but the groups in each pile were created so that Deep Neural Network would focus on recognizing same slice (angle) images. The groups were created using K-means algorithm to group the image into the appropriate slice group. The reason we used the K-means clustering is because we had CT images that were taken from 16-, 32-, 64-, 128-, 256- and 320-slice CT scanners. We used 64 groups because most of the images we had were 64-sliced. For images obtained from a scanning that made more or fewer than 64 slices, we used the K-means algorithm to put them into the correct group. Figure 1: A cancerous Computed Tomography (CT) image predetermined by medical personnel and confirmed by using biopsy of the tissue. The number of slices determines the distance between one scanned image of the body to the next. If there are more slices, the distance between each slice is smaller, but we get more information about the patient. Furthermore, one scanner from one manufacturer can output images from first to last (or vice versa) or save them in files in their own file format name, thus even if patients were scanned by a 64-slice scanner, if images were from a different manufacturer or version of the software, the images might not be in the same order. We could discard images that are not compliant to our scanner, but since CT images are hard to obtain, we did not discard images. The \(K\)-means algorithm we used is given in Equation (1).