The evaluation metric for this competition is Dice. The Dice, commonly used in segmentation, measures the similarity between two segmentations. Given an automatic segmentation A and a manual segmentation M, the Dice coefficient  is given by the following relation: \[ D = \frac{2|A \bigcap M|}{|A| + |M|} \]

where |A| and |M| refers to the number of elements in the sets A and M respectively.


Note that the Jaccard  is directly related to the Dice index  by the following relation: \[J = D/(2-D)\] 

A valid submission for the final project is one that gives you a Jaccard Index of at least 35%. This means you need a Dice of at least approximately 50%.

## Submission Format
You'll be submitting the binary segmentation masks for each ROI and each test subject. Note that there are 4 ROIs and 9 test subjects. Therefore, you should submit a CSV file with 36 rows = 9 subjects x 4 ROIs. The file should contain a header and have the following format:


The file should contain a header and have the following format:

```
Id, Predicted
 
8-left-wm, 11875 3 12130 3 12385 3 12640 3 12665 1 12918 4 
```


The Id is in the following format: {ID-{left/right}-{wm/cortex}}. The first number reflects the ID of the test subject. Note that you have the following IDs in the test set: {8, 9, 10, 11, 12, 13, 14, 16, 17}. Left/right refers to the side of the brain and wm/cortex represents the two regions of interest in the data, i.e., the white matter and the cerebral cortex respectively. For example, the Id 10-right-wm refers to the automatic binary segmentation mask of the right white-matter region of test subject IBSR_10  .



The 'Predicted' column contains the automatic binary segmentation masks in Run-Length Encoding  format.
You may use the following function to convert your binary segmentation image to RLE format:

 
```
def rle_encode(img):
    '''
    img: numpy array, 1 - mask, 0 - background
    Returns run length as string formated
    '''
    pixels = img.flatten()
    pixels = np.concatenate([[0], pixels, [0]])
    runs = np.where(pixels[1:] != pixels[:-1])[0] + 1
    runs[1::2] -= runs[::2]
    return ' '.join(str(x) for x in runs)
```
(Source: https://www.kaggle.com/paulorzp/run-length-encode-and-decode)


To convert all your automatic segmentations to CSV format during submission, you may find the pandas library useful:

```
import pandas as pd
### ids: list containing the 36 IDs as described above  ###
### data: list containing the 36 binary segmentation masks in RLE format ###
df = pd.DataFrame({"Id": labels, "Predicted": data})
df.to_csv('submission.csv', index = False) 
```

Finally, note that the orientation of the predicted segmentation images matters. You should stick with the default orientation of the coronal slice when loading the image using the nibabel library. For reference, see the mriorientation.png and segorientation.png files in the Data section to visualize the correct orientation of the segmentation images.

## You are allowed to submit up to a maximum of 15 entries per day.