# -*- coding: utf-8 -*-
"""
Created on Sat May  7 23:42:33 2022

@author: petra

evaluation only of the part result
take files from folder Finalni
"""


globals().clear()


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


plt.close('all')


dia_mask = scipy.io.loadmat('C:/Users/petka/OneDrive/Diplomka/Finalni/masks_dia_gt.mat')['mydata']
sys_mask = scipy.io.loadmat('C:/Users/petka/OneDrive/Diplomka/Finalni/masks_sys_gt.mat')['mydata']

segmented_dia_mask = scipy.io.loadmat('C:/Users/petka/OneDrive/Diplomka/Finalni/segmented_dia_masks.mat')['mydata']
segmented_sys_mask = scipy.io.loadmat('C:/Users/petka/OneDrive/Diplomka/Finalni/segmented_sys_masks.mat')['mydata']


voxel_volume = 0.0714111328125

# %%

edv_manual = np.sum(dia_mask) * voxel_volume
edv_auto = np.sum(segmented_dia_mask) * voxel_volume

esv_manual = np.sum(sys_mask) * voxel_volume
esv_auto = np.sum(segmented_sys_mask) * voxel_volume

ef_manual = (edv_manual - esv_manual)  / edv_manual
ef_auto = (edv_auto - esv_auto) / edv_auto



# %%

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

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

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


print(' ')
print('EDV calculated by manual segmentation is: ' + str(round(edv_manual, 2)) + ' mm3.')
print('EDV calculated by automated segmentation is: ' + str(round(edv_auto, 2)) + ' mm3.')
print('Absolute error for EDV is: ' + str(round(edv_error_abs, 2)) + ' and relative error is: ' + str(round(edv_error_rel * 100, 2)) + ' %')

print(' ')
print('ESV calculated by manual segmentation is: ' + str(round(esv_manual, 2)) + ' mm3.')
print('ESV calculated by automated segmentation is: ' + str(round(esv_auto, 2)) + ' mm3.')
print('Absolute error for ESV is: ' + str(round(esv_error_abs, 2)) + ' and relative error is: ' + str(round(esv_error_rel * 100, 2)) + ' %')

print(' ')
print('EFV calculated by manual segmentation is: ' + str(round(ef_manual, 2)))
print('EF calculated by automated segmentation is: ' + str(round(ef_auto, 2)))
print('Absolute error for EF is: ' + str(round(ef_error_abs, 2)) + ' and relative error is: ' + str(round(ef_error_rel * 100, 2)) + ' %')











