# -*- coding: utf-8 -*-
"""
Created on Thu May 12 09:09:48 2022

@author: petra
"""


globals().clear()


# IMPORTS

import matplotlib.pyplot as plt
import numpy as np
import scipy
import skimage
import scipy.io
import scipy.ndimage
import scipy.interpolate
import skimage.segmentation
import skimage.color
from scipy.ndimage import zoom


# %%

def create_mask(N):
    '''
    function to crete mask from calculated contour
    N: given contour
    
    output: BW image, 1 == segmented area, 0 == area outside
    '''
    fig = plt.figure(num=100, figsize=(5,5))
    plt.fill(N[:,0], N[:,1])
    plt.xlim([0,191])
    plt.ylim([191,0])
    plt.show()
    
    fig.canvas.draw()
    mask = np.frombuffer(fig.canvas.tostring_rgb(), dtype=np.uint8)
    mask = mask.reshape(fig.canvas.get_width_height()[::-1] + (3,))
    mask = skimage.color.rgb2gray(mask)
    mask = mask[61:444, :]
    mask = mask[:, 65:448]
    mask_under = zoom(mask,0.5) #downsample the upsampled image
    mask_under[0,:] = 1
    mask_under[mask_under>=0.999999] = 1
    mask_fin = np.floor(mask_under)
    mask_fin = 1 - mask_fin

    plt.close(100)

    return mask_fin


plt.close('all')

# %%

contours_sys = scipy.io.loadmat('contours_sys_finalni.mat')
contours_sys = contours_sys['data']

contours_dia = scipy.io.loadmat('contours_dia_finalni.mat')
contours_dia = contours_dia['data']


masks_sys_orig = scipy.io.loadmat('masks_sys_orig.mat')
masks_sys_orig = masks_sys_orig['data']

masks_dia_orig = scipy.io.loadmat('masks_dia_orig.mat')
masks_dia_orig = masks_dia_orig['data']

voxel_volume = np.array([0.0714111, 0.0714111, 0.0714111, 0.0714111, 0.0714111, 0.0878906, 0.0878906, 0.0878906, 0.0878906, 
                         0.0878906, 0.0878906, 0.0878906, 0.0878906, 0.0878906, 0.0878906, 0.0878906, 0.0878906, 0.0878906, 
                         0.0878906, 0.0878906, 0.0878906, 0.0878906, 0.0714111, 0.0714111, 0.0823975, 0.10437, 0.087906])

shape1 = np.shape(contours_dia)[0]
shape2 = np.shape(contours_dia)[1]
# %%
# Calculate dice coefficient for systolas

masks_sys = []
dice_sys = []
for i in range(shape1):
    masks_sub = []
    dice_sub = []
    for j in range(shape2):
        contour = contours_sys[i,j,:,:]
        mask = create_mask(contour)
        gt = masks_sys_orig[i,:,:,j]
        
        if (np.sum(gt) != 0):
            
            dice = np.sum(mask[gt == 1]) * 2.0 / (np.sum(mask) + np.sum(gt))           
        else: 
            dice = -1
        
        
        masks_sub.append(mask)
        dice_sub.append(dice)
        
    masks_sys.append(masks_sub)
    dice_sys.append(dice_sub)


# Calculate dice coefficient for diastolas

masks_dia = []
dice_dia = []
for i in range(shape1):
    masks_sub = []
    dice_sub = []
    for j in range(shape2):
        contour = contours_dia[i,j,:,:]
        mask = create_mask(contour)
        gt = masks_dia_orig[i,:,:,j]
        
        if (np.sum(gt) != 0):
            
            dice = np.sum(mask[gt == 1]) * 2.0 / (np.sum(mask) + np.sum(gt))           
        else: 
            dice = -1
        
        
        masks_sub.append(mask)
        dice_sub.append(dice)
        
    masks_dia.append(masks_sub)
    dice_dia.append(dice_sub)


# scipy.io.savemat('dice_sys.mat', {'data': dice_sys})
# scipy.io.savemat('dice_dia.mat', {'data': dice_dia})

# scipy.io.savemat('masks_sys.mat', {'data': masks_sys})
# scipy.io.savemat('masks_dia.mat', {'data': masks_dia})

# %% EVALUATION OF DICE COEFFICIENTS


dice_sys = scipy.io.loadmat('dice_sys.mat')['data']
dice_dia = scipy.io.loadmat('dice_dia.mat')['data']


# diastolas

dia_max_col0 = np.max(dice_dia[:,0])
dia_min_col0 = np.min(dice_dia[:,0])
dia_mean_col0 = np.mean(dice_dia[:,0])
dia_median_col0 = np.median(dice_dia[:,0])
dia_std_col0 = np.std(dice_dia[:,0])

dia_max_col1 = np.max(dice_dia[:,1])
dia_min_col1 = np.min(dice_dia[:,1])
dia_mean_col1 = np.mean(dice_dia[:,1])
dia_median_col1 = np.median(dice_dia[:,1])
dia_std_col1 = np.std(dice_dia[:,1])

dia_max_col2 = np.max(dice_dia[:,2])
dia_min_col2 = np.min(dice_dia[:,2])
dia_mean_col2 = np.mean(dice_dia[:,2])
dia_median_col2 = np.median(dice_dia[:,2])
dia_std_col2 = np.std(dice_dia[:,2])

dia_max_col3 = np.max(dice_dia[:,3])
dia_min_col3 = np.min(dice_dia[:,3])
dia_mean_col3 = np.mean(dice_dia[:,3])
dia_median_col3 = np.median(dice_dia[:,3])
dia_std_col3 = np.std(dice_dia[:,3])

dia_max_col4 = np.max(dice_dia[:,4])
dia_min_col4 = np.min(dice_dia[:,4])
dia_mean_col4 = np.mean(dice_dia[:,4])
dia_median_col4 = np.median(dice_dia[:,4])
dia_std_col4 = np.std(dice_dia[:,4])

dia_max = np.max(dice_dia)
dia_min = np.min(dice_dia)
dia_mean = np.mean(dice_dia)
dia_median = np.median(dice_dia)
dia_std = np.std(dice_dia)


plt.figure(num=1)
plt.boxplot(dice_dia)
plt.title('Boxplot representing dice coefficients for diastolas', fontsize=20) # labelsize=20
plt.ylabel('Dice coefficients', fontsize=20) # labelsize=10
plt.xlabel('Slice number', fontsize=20) # labelsize=10
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()


# systolas

sys_max_col0 = np.max(dice_sys[:,0])
sys_min_col0 = np.min(dice_sys[:,0][dice_sys[:,0] >= 0])
sys_mean_col0 = np.mean(dice_sys[:,0][dice_sys[:,0] >= 0])
sys_median_col0 = np.median(dice_sys[:,0][dice_sys[:,0] >= 0])
sys_std_col0 = np.std(dice_sys[:,0][dice_sys[:,0] >= 0])

sys_max_col1 = np.max(dice_sys[:,1])
sys_min_col1 = np.min(dice_sys[:,1])
sys_mean_col1 = np.mean(dice_sys[:,1])
sys_median_col1 = np.median(dice_sys[:,1])
sys_std_col1 = np.std(dice_sys[:,1])

sys_max_col2 = np.max(dice_sys[:,2])
sys_min_col2 = np.min(dice_sys[:,2])
sys_mean_col2 = np.mean(dice_sys[:,2])
sys_median_col2 = np.median(dice_sys[:,2])
sys_std_col2 = np.std(dice_sys[:,2])

sys_max_col3 = np.max(dice_sys[:,3])
sys_min_col3 = np.min(dice_sys[:,3])
sys_mean_col3 = np.mean(dice_sys[:,3])
sys_median_col3 = np.median(dice_sys[:,3])
sys_std_col3 = np.std(dice_sys[:,3])

sys_max_col4 = np.max(dice_sys[:,4])
sys_min_col4 = np.min(dice_sys[:,4])
sys_mean_col4 = np.mean(dice_sys[:,4])
sys_median_col4 = np.median(dice_sys[:,4])
sys_std_col4 = np.std(dice_sys[:,4])

sys_max = np.max(dice_sys)
sys_min = np.min(dice_sys[dice_sys[:,0] > 0])
sys_mean = np.mean(dice_sys[dice_sys[:,0] > 0])
sys_median = np.median(dice_sys[dice_sys[:,0] > 0])
sys_std = np.std(dice_sys[dice_sys[:,0] > 0])


dice_sys[11,0] = sys_median_col0
dice_sys[19,0] = sys_median_col0
dice_sys[21,0] = sys_median_col0
dice_sys[26,0] = sys_median_col0


plt.figure(num=2)
plt.boxplot(dice_sys)
plt.title('Boxplot representing dice coefficients for systolas', fontsize=20) # labelsize=20
plt.ylabel('Dice coefficients', fontsize=20) # labelsize=10
plt.xlabel('Slice number', fontsize=20) # labelsize=10
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()



# %% EVALUATION OF CALCULATED VOLUMES

# end diastolic volume
# calculated as sum of segmented surfaces multiplied by voxel volume 

data_range = np.shape(dice_dia)[0]

edv_manual = np.array([])
edv_auto = np.array([])


for i in range(data_range):
     
    edv_manual = np.append(edv_manual, np.sum(masks_dia_orig[i][:,:,:]) * voxel_volume[i]) 
    edv_auto = np.append(edv_auto, np.sum(masks_dia[i]) * voxel_volume[i])

edv_error_abs = np.abs(edv_auto - edv_manual)
edv_error_rel = edv_error_abs / edv_manual


plt.figure(num=3, figsize=(4,4))
plt.boxplot([edv_manual, edv_auto], labels=('Manual', 'Auto'))
plt.title('Volumes of left ventricle during diastolas got \n from manual and auto segmentation', fontsize=20)
# plt.xlabel('Manual / automatic segmentation', fontsize=25) # labelsize=10
plt.ylabel('Calculated volumes [mm3]', fontsize=20) # labelsize=10
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()


edv_abs_min = np.min(edv_error_abs)
edv_abs_max = np.max(edv_error_abs)
edv_abs_mean = np.mean(edv_error_abs)
edv_abs_median = np.median(edv_error_abs)
edv_abs_std = np.std(edv_error_abs)

edv_rel_min = np.min(edv_error_rel)
edv_rel_max = np.max(edv_error_rel)
edv_rel_mean = np.mean(edv_error_rel)
edv_rel_median = np.median(edv_error_rel)
edv_rel_std = np.std(edv_error_rel)





# end systolic volumes

esv_manual = np.array([])
esv_auto = np.array([])

for i in range(data_range):
    
    esv_manual = np.append(esv_manual, np.sum(masks_sys_orig[i][:,:,:]) * voxel_volume[i]) 
    esv_auto = np.append(esv_auto, np.sum(masks_sys[i]) * voxel_volume[i])

esv_error_abs = np.abs(esv_auto - esv_manual)
esv_error_rel = esv_error_abs / esv_manual


plt.figure(num=4, figsize=(4,4))
plt.boxplot([esv_manual, esv_auto], labels=('Manual', 'Auto'))
plt.title('Volumes of left ventricle during systolas got \n from manual and auto segmentation', fontsize=20)
# plt.xlabel('Manual / automatic segmentation', fontsize=25) # labelsize=10
plt.ylabel('Calculated volumes [mm3]', fontsize=20) # labelsize=10
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()


esv_abs_min = np.min(esv_error_abs)
esv_abs_max = np.max(esv_error_abs)
esv_abs_mean = np.mean(esv_error_abs)
esv_abs_median = np.median(esv_error_abs)
esv_abs_std = np.std(esv_error_abs)

esv_rel_min = np.min(esv_error_rel)
esv_rel_max = np.max(esv_error_rel)
esv_rel_mean = np.mean(esv_error_rel)
esv_rel_median = np.median(esv_error_rel)
esv_rel_std = np.std(esv_error_rel)




# ejection fraction

ef_manual = np.array([])
ef_auto = np.array([])

for i in range(data_range):
    
    ef_manual = np.append(ef_manual, ((edv_manual[i] - esv_manual[i]) / edv_manual[i]))
    ef_auto = np.append(ef_auto, ((edv_auto[i] - esv_auto[i]) / edv_auto[i]))
    

ef_error_abs = np.abs(ef_auto - ef_manual)
ef_error_rel = ef_error_abs / ef_manual


plt.figure(num=5, figsize=(4,4))
plt.boxplot([ef_manual, ef_auto], labels=('Manual', 'Auto'))
plt.title('Calculated ejection fractions from \n manual and automatic segmentation', fontsize=20)
# plt.xlabel('Manual / automatic segmentation', fontsize=25) # labelsize=10
plt.ylabel('Calculated ejection fractions', fontsize=20) # labelsize=10
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()


ef_abs_min = np.min(ef_error_abs)
ef_abs_max = np.max(ef_error_abs)
ef_abs_mean = np.mean(ef_error_abs)
ef_abs_median = np.median(ef_error_abs)
ef_abs_std = np.std(ef_error_abs)

ef_rel_min = np.min(ef_error_rel)
ef_rel_max = np.max(ef_error_rel)
ef_rel_mean = np.mean(ef_error_rel)
ef_rel_median = np.median(ef_error_rel)
ef_rel_std = np.std(ef_error_rel)


# %% EVALUATION OF EJECTION FRACTION FOR EACH GROUP - 1st, 2nd, 3rd MEASURE, DEPENDENCY ON HEALTHY / FIBROTIC

# healthy groups are:
# healthy = 4, 5, 6, 7, 13, 14, 15, 16, 22, 23, 24, 26
# measure number:
# healthy = 4 - 1, 5 - 1, 6 - 1, 7 - 1, 13 - 2, 14 - 2, 15 - 2, 16 - 2, 22 - 3, 23 - 3, 24 - 3, 26 - 3

# fibrotic groups are:
# fibrotic = 0, 1, 2, 3, 8, 9, 10, 11, 12, 17, 18, 19, 20, 21, 25
# measure number:
# fibrotic = 0 - 1, 1 - 1, 2 - 1, 3 - 1, 8 - 1, 9 - 2, 10 - 2, 11 - 2, 12 - 2, 17 - 2, 18 - 3, 19 - 3, 20 - 3, 21 - 3, 25 - 3

h_ef_1_auto = np.array([ef_auto[4], ef_auto[5], ef_auto[6], ef_auto[7]])
h_ef_2_auto = np.array([ef_auto[13], ef_auto[14], ef_auto[15], ef_auto[16]])
h_ef_3_auto = np.array([ef_auto[22], ef_auto[23], ef_auto[24], ef_auto[26]])

f_ef_1_auto = np.array([ef_auto[0], ef_auto[1], ef_auto[2], ef_auto[3], ef_auto[8]])
f_ef_2_auto = np.array([ef_auto[9], ef_auto[10], ef_auto[11], ef_auto[12], ef_auto[17]])
f_ef_3_auto = np.array([ef_auto[18], ef_auto[19], ef_auto[20], ef_auto[21], ef_auto[25]])


h_ef_1_manual = np.array([ef_manual[4], ef_manual[5], ef_manual[6], ef_manual[7]])
h_ef_2_manual = np.array([ef_manual[13], ef_manual[14], ef_manual[15], ef_manual[16]])
h_ef_3_manual = np.array([ef_manual[22], ef_manual[23], ef_manual[24], ef_manual[26]])

f_ef_1_manual = np.array([ef_manual[0], ef_manual[1], ef_manual[2], ef_manual[3], ef_manual[8]])
f_ef_2_manual = np.array([ef_manual[9], ef_manual[10], ef_manual[11], ef_manual[12], ef_manual[17]])
f_ef_3_manual = np.array([ef_manual[18], ef_manual[19], ef_manual[20], ef_manual[21], ef_manual[25]])




plt.figure(num=6)
plt.subplot(2,2,1)
plt.boxplot([h_ef_1_auto, h_ef_2_auto, h_ef_3_auto], labels=('1', '2', '3'))
plt.title('Calculated ejection fraction during in \n healthy group, automated segmentation', fontsize=15)
# plt.xlabel('Measure number', fontsize=10) # labelsize=10
plt.ylabel('Calculated ejection fractions', fontsize=10) # labelsize=10
plt.ylim([0.55, 0.95])
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()

plt.subplot(2,2,2)
plt.boxplot([h_ef_1_manual, h_ef_2_manual, h_ef_3_manual], labels=('1', '2', '3'))
plt.title('Calculated ejection fraction during in \n healthy group, manual segmentation', fontsize=15)
# plt.xlabel('Measure number', fontsize=10) # labelsize=10
plt.ylabel('Calculated ejection fractions', fontsize=10) # labelsize=10
plt.ylim([0.55, 0.95])
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()


plt.subplot(2,2,3)
plt.boxplot([f_ef_1_auto, f_ef_2_auto, f_ef_3_auto], labels=('1', '2', '3'))
plt.title('Calculated ejection fraction during in \n fibrotic group, automated segmentation', fontsize=15)
plt.xlabel('Measure number', fontsize=10) # labelsize=10
plt.ylabel('Calculated ejection fractions', fontsize=10) # labelsize=10
plt.ylim([0.65, 0.95])
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()

plt.subplot(2,2,4)
plt.boxplot([f_ef_1_manual, f_ef_2_manual, f_ef_3_manual], labels=('1', '2', '3'))
plt.title('Calculated ejection fraction during in \n fibrotic group, manual segmentation', fontsize=15)
plt.xlabel('Measure number', fontsize=10) # labelsize=10
plt.ylabel('Calculated ejection fractions', fontsize=10) # labelsize=10
plt.ylim([0.65, 0.95])
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()



# %% EVALUATION OF LEFT VENTRICLE VOLUME FOR AUTOMATED SEGMENATION AND FOR MANUAL END DIASTOLIC VOLUME

h_1_esv_auto = np.array([esv_auto[4], esv_auto[5], esv_auto[6], esv_auto[7]])
h_2_esv_auto = np.array([esv_auto[13], esv_auto[14], esv_auto[15], esv_auto[16]])
h_3_esv_auto = np.array([esv_auto[22], esv_auto[23], esv_auto[24], esv_auto[26]])

f_1_esv_auto = np.array([esv_auto[0], esv_auto[1], esv_auto[2], esv_auto[3], esv_auto[8]])
f_2_esv_auto = np.array([esv_auto[9], esv_auto[10], esv_auto[11], esv_auto[12], esv_auto[17]])
f_3_esv_auto = np.array([esv_auto[18], esv_auto[19], esv_auto[20], esv_auto[21], esv_auto[25]])


h_1_edv_auto = np.array([edv_auto[4], edv_auto[5], edv_auto[6], edv_auto[7]])
h_2_edv_auto = np.array([edv_auto[13], edv_auto[14], edv_auto[15], edv_auto[16]])
h_3_edv_auto = np.array([edv_auto[22], edv_auto[23], edv_auto[24], edv_auto[26]])

f_1_edv_auto = np.array([edv_auto[0], edv_auto[1], edv_auto[2], edv_auto[3], edv_auto[8]])
f_2_edv_auto = np.array([edv_auto[9], edv_auto[10], edv_auto[11], edv_auto[12], edv_auto[17]])
f_3_edv_auto = np.array([edv_auto[18], edv_auto[19], edv_auto[20], edv_auto[21], edv_auto[25]])




# %% EVALUATION OF LEFT VENTRICLE VOLUME FOR AUTOMATED SEGMENATION AND FOR MANUAL END SYSTOLIC VOLUME

h_1_esv_manual = np.array([esv_manual[4], esv_manual[5], esv_manual[6], esv_manual[7]])
h_2_esv_manual = np.array([esv_manual[13], esv_manual[14], esv_manual[15], esv_manual[16]])
h_3_esv_manual = np.array([esv_manual[22], esv_manual[23], esv_manual[24], esv_manual[26]])

f_1_esv_manual = np.array([esv_manual[0], esv_manual[1], esv_manual[2], esv_manual[3], esv_manual[8]])
f_2_esv_manual = np.array([esv_manual[9], esv_manual[10], esv_manual[11], esv_manual[12], esv_manual[17]])
f_3_esv_manual = np.array([esv_manual[18], esv_manual[19], esv_manual[20], esv_manual[21], esv_manual[25]])


h_1_edv_manual = np.array([edv_manual[4], edv_manual[5], edv_manual[6], edv_manual[7]])
h_2_edv_manual = np.array([edv_manual[13], edv_manual[14], edv_manual[15], edv_manual[16]])
h_3_edv_manual = np.array([edv_manual[22], edv_manual[23], edv_manual[24], edv_manual[26]])

f_1_edv_manual = np.array([edv_manual[0], edv_manual[1], edv_manual[2], edv_manual[3], edv_manual[8]])
f_2_edv_manual = np.array([edv_manual[9], edv_manual[10], edv_manual[11], edv_manual[12], edv_manual[17]])
f_3_edv_manual = np.array([edv_manual[18], edv_manual[19], edv_manual[20], edv_manual[21], edv_manual[25]])


# %% PLOTTING


plt.figure(num=7)

plt.subplot(2,2,1)
plt.boxplot([f_1_edv_auto, f_2_edv_auto, f_3_edv_auto], labels=('1', '2', '3'))
plt.title('Modification of end-diastolic volume in fibrotic group \n during time, automated segmentation', fontsize=15)
# plt.xlabel('Measure number', fontsize=10) # labelsize=10
plt.ylabel('Calculated end diastolic volumes [mm3]', fontsize=10) # labelsize=10
plt.ylim([120, 450])
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()

plt.subplot(2,2,2)
plt.boxplot([f_1_edv_manual, f_2_edv_manual, f_3_edv_manual], labels=('1', '2', '3'))
plt.title('Modification of end-diastolic volume in fibrotic group \n during time, manual segmentation', fontsize=15)
# plt.xlabel('Measure number', fontsize=10) # labelsize=10
plt.ylabel('Calculated end diastolic volumes [mm3]', fontsize=10) # labelsize=10
plt.ylim([120, 450])
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()


plt.subplot(2,2,3)
plt.boxplot([h_1_edv_auto, h_2_edv_auto, h_3_edv_auto], labels=('1', '2', '3'))
plt.title('Modification of end-diastolic volume in healthy group \n during time, automated segmentation', fontsize=15)
plt.xlabel('Measure number', fontsize=10) # labelsize=10
plt.ylabel('Calculated end diastolic volumes [mm3]', fontsize=10) # labelsize=10
plt.ylim([160,320])
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()

plt.subplot(2,2,4)
plt.boxplot([h_1_edv_manual, h_2_edv_manual, h_3_edv_manual], labels=('1', '2', '3'))
plt.title('Modification of end-diastolic volume in healthy group \n during time, manual segmentation', fontsize=15)
plt.xlabel('Measure number', fontsize=10) # labelsize=10
plt.ylabel('Calculated end diastolic volumes [mm3]', fontsize=10) # labelsize=10
plt.ylim([160,320])
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()









plt.figure(num=8)

plt.subplot(2,2,1)
plt.boxplot([f_1_esv_auto, f_2_esv_auto, f_3_esv_auto], labels=('1', '2', '3'))
plt.title('Modification of end-systolic volume in fibrotic group \n during time, automated segmentation', fontsize=15)
# plt.xlabel('Measure number', fontsize=10) # labelsize=10
plt.ylabel('Calculated end diastolic volumes [mm3]', fontsize=10) # labelsize=10
plt.ylim([15,80])
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()


plt.subplot(2,2,2)
plt.boxplot([f_1_esv_manual, f_2_esv_manual, f_3_esv_manual], labels=('1', '2', '3'))
plt.title('Modification of end-systolic volume in fibrotic group \n during time, manual segmentation', fontsize=15)
# plt.xlabel('Measure number', fontsize=10) # labelsize=10
plt.ylabel('Calculated end diastolic volumes [mm3]', fontsize=10) # labelsize=10
plt.ylim([15,80])
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()


plt.subplot(2,2,3)
plt.boxplot([h_1_esv_auto, h_2_esv_auto, h_3_esv_auto], labels=('1', '2', '3'))
plt.title('Modification of end-systolic volume in healthy group \n during time, automated segmentation', fontsize=15)
plt.xlabel('Measure number', fontsize=10) # labelsize=10
plt.ylabel('Calculated end diastolic volumes [mm3]', fontsize=10) # labelsize=10
plt.ylim([20,100])
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()



plt.subplot(2,2,4)
plt.boxplot([h_1_esv_manual, h_2_esv_manual, h_3_esv_manual], labels=('1', '2', '3'))
plt.title('Modification of end-systolic volume in healthy group \n during time, manual segmentation', fontsize=15)
plt.xlabel('Measure number', fontsize=10) # labelsize=10
plt.ylabel('Calculated end diastolic volumes [mm3]', fontsize=10) # labelsize=10
plt.ylim([20,100])
plt.rc('xtick', labelsize=8) # labelsize=8
plt.rc('ytick', labelsize=8) # labelsize=8
plt.show()











