## 2 Materials and Methods
### Method
#### 2.2.4 Data Augmentation Approach  
Once the priors are defined, the data augmentation algorithm consists of the following steps:  
**Initialization**: Given the original image and its corresponding ground truth as inputs, the type and location of MI are defined randomly. The size of the MI corresponds to a percentage sampled randomly from a uniform distribution within the range [0.1,0.5]. The algorithm then calculates the adequate MI size as a multiplication of the total myocardium area by the randomly sampled percentage.  
**Extraction of contours**: As a second step, the contours for the left ventricle cavity and the myocardium are extracted, as shown in image b from Figure 5.  
**Division of contours in quadrants:** Once the contours have been extracted successfully, four binary images are generated, which contain the parts of both contours that fall within the range of coordinates of the previously defined quadrants. As a final step, one of the quadrants is selected for the MI generation, and its binary image is kept.  
**Definition of boundary points:** As a fourth step, one random pair of coordinates from the left ventricle cavity contour, located within the selected quadrant, is chosen as the starting point (_start CV_) for generating the MI shape. Afterwards, the left ventricle cavity end point (_end CV_) is chosen as the one whose distance with the _start CV_ is the closest to the effective MI size. The starting and end points of the myocardium correspond to the closest points (measured in Euclidean distance) to _start CV_ and _end CV_, respectively.  
**MI contour generation (TMI)**: An ROI is generated from the boundary points by first painting all pixels belonging to each contour and falling between the extreme points, then closing it through lines using [PERSON]'s line algorithm [PERSON] (1996).  
**MI contour generation (NTMI)**: The process is quite similar to the one described for TMI, with the difference that the myocardium contour is not painted since the MI falls between the two contours. The intermediate coordinates are determined by a thickness variable that is sampled from a random distribution that ranges between [0.2,0.8]. It cannot be assured that the intermediate points can always be connected through a line since the algorithm selects them randomly in order to generate a variety of MI scar shapes. Therefore, the breadth first search algorithm is used to close the contour and generate  
Figure 5: Summary of the data augmentation method for a case of TMI: (**a**) original DE MRI; (**b**) segmentation of myocardial contours; (**c**) selection of working quadrant; (**d**) MI ROI generation; (**e**) MI generation in DE MRI.  
the final ROI [20]. An example of an intermediate-generated path from this algorithm for NTMI is shown in Figure 6.  
**Creation of MI mask:** Once the contour is closed, it is filled, and the final MI is generated, as shown in image d from Figure 5.  
**Generation of MI perturbation on the MRI:** Following the rule described in Section 2.2.4, the MI is generated as the mean value of the left ventricle cavity plus the prior knowledge value. As a final step, some blurring was applied to smooth the intensity variations in the borders of the MI. The blurring was applied on the area delimited by a dilated mask (for one iteration) of the myocardium using a 3 \(\times\) 3 kernel. The final result of the algorithm is depicted in image e from Figure 5.