# Heart Attack Detection in Colour Images Using Convolutional Neural Networks
## 3 Methodology
### Creation of the Image Data Set  
A data set of images with people in non-infarction situations and others with a possible infarction was generated. The data set is made up of images created by the authors plus others downloaded from the Internet. All these pictures contain only one person. In regards to images tagged as an infarct, all people show a posture in which they have one or both hands on the chest. As regards to no infarct situations, images where people are performing daily activities were used. Some of these latter images include similar postures to a possible infarct, but they are not labelled as such. The initial image data set contained a total of 1520 images, 760 images of class \"Infract\" and 760 images of class \"No Infract\". To increase the number of images in the data set, the following actions were performed:  
* Each image was scaled to a maximum size of \(256\times 256\) pixels, maintaining the original proportion, both for \"Infract\" and \"No Infract\" images. This was done in order to reduce the amount of data to be processed during the augmented data technique. * After that, the images were classified into two categories, \"Infract\" and \"No Infract\". Furthermore, each category was split into the three subcategories of training, validation, and testing, as shown in Table 1. This process was done manually in order to ensure that the images from each subcategory would not be repeated. This means that an image that is being used for training, for instance, will not be used again for validation or testing purposes, thus avoiding an alteration of the final results. * As the CNNs only have to infer a possible heart attack, people were extracted from the background of the image by reducing the noise caused by the variation of the background in order to improve the training set (see Figure 2). * People were automatically located in each image. For this purpose, the Mask R-CNN software for object detection and instance segmentation was used [36]. * From the previous result, the background of the image was removed, replacing the value of each pixel with purple colour. * Finally, the augmented data technique was applied [37]. Data augmentation is a process for generating new samples by transforming training data with the target of improving the accuracy  
Figure 1: Stages of the system. and robustness of the classifiers. In this case, each original picture generated 20 more different images. For this, six transformations were combined and applied to each image (rotation, increase/decrease in width or height, zoom, horizontal flip, and brightness change). As a result, a total of 31,920 images were obtained by adding the augmented images to the original pictures, as shown in Table 2. It is important to mention that each image generated by the transformations during the data augmentation process was kept in the same set to which the original image belonged, ensuring that both the original image and its transformations belonged to no more that one set. Figure 3 introduces an example of the resulting images, both of people with a heart attack and others in different positions. The data set includes images of the same people in different postures, as this allows the neural networks to identify the key features in the posture rather than to recognise the person shown in the image. \begin{table}
\begin{tabular}{c c c c c c} \hline \hline \multirow{2}{*}{**Class**} & **Training** & **Validation** & **Test** & **Total** \\  & **70\%** & **15\%** & **15\%** & **Total** \\ \hline Infract & 532 & 114 & 114 & 760 \\ No Infract & 532 & 114 & 114 & 760 \\ \hline Total & 1064 & 228 & 228 & 1520 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Data in selected distribution: Images per class and set.