Beispiel #1
0
 def save_results(self):
     #save the results in a txt and xls files. There are two modes, one if
     #there is no patient and another is the is a patient (two photos)
     if self._Patient is None:  #this implies that there is a single photo
         if self._file_name is not None:
             if self.displayImage._shape is not None:
                 save_txt_file(self._file_name, self.displayImage._shape,
                               self.displayImage._lefteye,
                               self.displayImage._righteye,
                               self.displayImage._boundingbox)
                 MeasurementsLeft, MeasurementsRight, MeasurementsDeviation, MeasurementsPercentual = get_measurements_from_data(
                     self.displayImage._shape, self.displayImage._lefteye,
                     self.displayImage._righteye)
                 save_xls_file(self._file_name, MeasurementsLeft,
                               MeasurementsRight, MeasurementsDeviation,
                               MeasurementsPercentual)
     else:  #this implies that the user created a patient and wants to analize two photos
         save_txt_file(self._Patient.FirstPhoto._file_name,
                       self._Patient.FirstPhoto._shape,
                       self._Patient.FirstPhoto._lefteye,
                       self._Patient.FirstPhoto._righteye,
                       self._Patient.FirstPhoto._boundingbox)
         save_txt_file(self._Patient.SecondPhoto._file_name,
                       self._Patient.SecondPhoto._shape,
                       self._Patient.SecondPhoto._lefteye,
                       self._Patient.SecondPhoto._righteye,
                       self._Patient.SecondPhoto._boundingbox)
         save_xls_file_patient(self._file_name, self._Patient)
Beispiel #2
0
def save_xls_file_patient(path, Patient, CalibrationType, CalibrationValue):
    #saves the facial metrics into a xls file. It works only for a patient (two photos)

    number_of_measurements = 9
    Columns = ['Right', 'Left', 'Deviation (absolute)', 'Deviation (percent)']
    Columns = Columns * number_of_measurements

    temp = [
        'Brow Height', 'Marginal Reflex Distance 1',
        'Marginal Reflex Distance 2', 'Commisure Excursion',
        'Commisure Height Deviation', 'Smile Angle',
        'Upper Lip Height Deviation', 'Dental Show',
        'Lower Lip Height Deviation'
    ]
    number_of_repetitions = 4
    Header = [item for item in temp for i in range(number_of_repetitions)]

    elements = ['BH', 'MRD1', 'MRD2', 'CE', 'CH', 'SA', 'UVH', 'DS', 'LVH']
    #first photo
    MeasurementsLeftFirst, MeasurementsRightFirst, MeasurementsDeviation, MeasurementsPercentual = get_measurements_from_data(
        Patient.FirstPhoto._shape, Patient.FirstPhoto._lefteye,
        Patient.FirstPhoto._righteye, CalibrationType, CalibrationValue)

    BH = np.array([[
        MeasurementsRightFirst.BrowHeight, MeasurementsLeftFirst.BrowHeight,
        MeasurementsDeviation.BrowHeight, MeasurementsPercentual.BrowHeight
    ]],
                  dtype=object)
    MRD1 = np.array([[
        MeasurementsRightFirst.MarginalReflexDistance1,
        MeasurementsLeftFirst.MarginalReflexDistance1,
        MeasurementsDeviation.MarginalReflexDistance1,
        MeasurementsPercentual.MarginalReflexDistance1
    ]],
                    dtype=object)
    MRD2 = np.array([[
        MeasurementsRightFirst.MarginalReflexDistance2,
        MeasurementsLeftFirst.MarginalReflexDistance2,
        MeasurementsDeviation.MarginalReflexDistance2,
        MeasurementsPercentual.MarginalReflexDistance2
    ]],
                    dtype=object)
    CE = np.array([[
        MeasurementsRightFirst.CommissureExcursion,
        MeasurementsLeftFirst.CommissureExcursion,
        MeasurementsDeviation.CommissureExcursion,
        MeasurementsPercentual.CommissureExcursion
    ]],
                  dtype=object)
    CH = np.array(
        [['', '', MeasurementsDeviation.CommisureHeightDeviation, '']],
        dtype=object)
    SA = np.array([[
        MeasurementsRightFirst.SmileAngle, MeasurementsLeftFirst.SmileAngle,
        MeasurementsDeviation.SmileAngle, MeasurementsPercentual.SmileAngle
    ]],
                  dtype=object)
    UVH = np.array(
        [['', '', MeasurementsDeviation.UpperLipHeightDeviation, '']],
        dtype=object)
    DS = np.array([[
        MeasurementsRightFirst.DentalShow, MeasurementsLeftFirst.DentalShow,
        MeasurementsDeviation.DentalShow, MeasurementsPercentual.DentalShow
    ]],
                  dtype=object)
    LVH = np.array(
        [['', '', MeasurementsDeviation.LowerLipHeightDeviation, '']],
        dtype=object)

    fillFirst = BH
    for i in elements:
        if i is not 'BH':
            fillFirst = np.append(fillFirst, eval(i), axis=1)

    #Second photo
    MeasurementsLeftSecond, MeasurementsRightSecond, MeasurementsDeviation, MeasurementsPercentual = get_measurements_from_data(
        Patient.SecondPhoto._shape, Patient.SecondPhoto._lefteye,
        Patient.SecondPhoto._righteye, CalibrationType, CalibrationValue)

    BH = np.array([[
        MeasurementsRightSecond.BrowHeight, MeasurementsLeftSecond.BrowHeight,
        MeasurementsDeviation.BrowHeight, MeasurementsPercentual.BrowHeight
    ]],
                  dtype=object)
    MRD1 = np.array([[
        MeasurementsRightSecond.MarginalReflexDistance1,
        MeasurementsLeftSecond.MarginalReflexDistance1,
        MeasurementsDeviation.MarginalReflexDistance1,
        MeasurementsPercentual.MarginalReflexDistance1
    ]],
                    dtype=object)
    MRD2 = np.array([[
        MeasurementsRightSecond.MarginalReflexDistance2,
        MeasurementsLeftSecond.MarginalReflexDistance2,
        MeasurementsDeviation.MarginalReflexDistance2,
        MeasurementsPercentual.MarginalReflexDistance2
    ]],
                    dtype=object)
    CE = np.array([[
        MeasurementsRightSecond.CommissureExcursion,
        MeasurementsLeftSecond.CommissureExcursion,
        MeasurementsDeviation.CommissureExcursion,
        MeasurementsPercentual.CommissureExcursion
    ]],
                  dtype=object)
    CH = np.array(
        [['', '', MeasurementsDeviation.CommisureHeightDeviation, '']],
        dtype=object)
    SA = np.array([[
        MeasurementsRightSecond.SmileAngle, MeasurementsLeftSecond.SmileAngle,
        MeasurementsDeviation.SmileAngle, MeasurementsPercentual.SmileAngle
    ]],
                  dtype=object)
    UVH = np.array(
        [['', '', MeasurementsDeviation.UpperLipHeightDeviation, '']],
        dtype=object)
    DS = np.array([[
        MeasurementsRightSecond.DentalShow, MeasurementsLeftSecond.DentalShow,
        MeasurementsDeviation.DentalShow, MeasurementsPercentual.DentalShow
    ]],
                  dtype=object)
    LVH = np.array(
        [['', '', MeasurementsDeviation.LowerLipHeightDeviation, '']],
        dtype=object)

    fillSecond = BH
    for i in elements:
        if i is not 'BH':
            fillSecond = np.append(fillSecond, eval(i), axis=1)

    #difference
    BH = np.array([[
        MeasurementsRightFirst.BrowHeight - MeasurementsRightSecond.BrowHeight,
        MeasurementsLeftFirst.BrowHeight - MeasurementsLeftSecond.BrowHeight,
        '', ''
    ]],
                  dtype=object)
    MRD1 = np.array([[
        MeasurementsRightFirst.MarginalReflexDistance1 -
        MeasurementsRightSecond.MarginalReflexDistance1,
        MeasurementsLeftFirst.MarginalReflexDistance1 -
        MeasurementsLeftSecond.MarginalReflexDistance1, '', ''
    ]],
                    dtype=object)
    MRD2 = np.array([[
        MeasurementsRightFirst.MarginalReflexDistance2 -
        MeasurementsRightSecond.MarginalReflexDistance2,
        MeasurementsLeftFirst.MarginalReflexDistance2 -
        MeasurementsLeftSecond.MarginalReflexDistance2, '', ''
    ]],
                    dtype=object)
    CE = np.array([[
        MeasurementsRightFirst.CommissureExcursion -
        MeasurementsRightSecond.CommissureExcursion,
        MeasurementsLeftFirst.CommissureExcursion -
        MeasurementsLeftSecond.CommissureExcursion, '', ''
    ]],
                  dtype=object)
    CH = np.array([['', '', '', '']], dtype=object)
    SA = np.array([[
        MeasurementsRightFirst.SmileAngle - MeasurementsRightSecond.SmileAngle,
        MeasurementsLeftFirst.SmileAngle - MeasurementsLeftSecond.SmileAngle,
        '', ''
    ]],
                  dtype=object)
    UVH = np.array([['', '', '', '']], dtype=object)
    DS = np.array([[
        MeasurementsRightFirst.DentalShow - MeasurementsRightSecond.DentalShow,
        MeasurementsLeftFirst.DentalShow - MeasurementsLeftSecond.DentalShow,
        '', ''
    ]],
                  dtype=object)
    LVH = np.array([['', '', '', '']], dtype=object)

    fillDifference = BH
    for i in elements:
        if i is not 'BH':
            fillDifference = np.append(fillDifference, eval(i), axis=1)

    Index = [Patient.FirstPhoto._ID, Patient.SecondPhoto._ID, 'Difference']

    df = pd.DataFrame(np.vstack((fillFirst, fillSecond, fillDifference)),
                      index=Index,
                      columns=Columns)
    df.columns = pd.MultiIndex.from_tuples(list(zip(Header, df.columns)))

    delimiter = os.path.sep
    temp = path.split(delimiter)
    path = temp[:-1]
    path = delimiter.join(path)

    file_name = path + delimiter + Patient.patient_ID + '.xlsx'

    df.to_excel(file_name, index=True)
Beispiel #3
0
    def create_new_window(self):
        #this creates a new window to display all the facial metrics, there
        #are two modes, one if there is no Patient (self._Patient = None)
        #and another if there is a patient (two photos)
        if self._Patient is None:

            if self.displayImage._shape is not None:
                #if the measurements window is already open then close it
                if self._new_window is not None:
                    self._new_window.close()
                    self._new_window = None

                #compute the facial metrics using the landmarks
                MeasurementsLeft, MeasurementsRight, MeasurementsDeviation, MeasurementsPercentual = get_measurements_from_data(
                    self.displayImage._shape, self.displayImage._lefteye,
                    self.displayImage._righteye)

                #send all the information the the appropiate places in the window
                self._tab1_results = CustomTabResult()

                #filling t_new_window_tab1_results he info for the right
                self._tab1_results._CE_right.setText('{0:.2f}'.format(
                    MeasurementsRight.CommissureExcursion))
                self._tab1_results._SA_right.setText('{0:.2f}'.format(
                    MeasurementsRight.SmileAngle))
                self._tab1_results._DS_right.setText('{0:.2f}'.format(
                    MeasurementsRight.DentalShow))
                self._tab1_results._MRD1_right.setText('{0:.2f}'.format(
                    MeasurementsRight.MarginalReflexDistance1))
                self._tab1_results._MRD2_right.setText('{0:.2f}'.format(
                    MeasurementsRight.MarginalReflexDistance2))
                self._tab1_results._BH_right.setText('{0:.2f}'.format(
                    MeasurementsRight.BrowHeight))

                #filling the info for the left
                self._tab1_results._CE_left.setText('{0:.2f}'.format(
                    MeasurementsLeft.CommissureExcursion))
                self._tab1_results._SA_left.setText('{0:.2f}'.format(
                    MeasurementsLeft.SmileAngle))
                self._tab1_results._DS_left.setText('{0:.2f}'.format(
                    MeasurementsLeft.DentalShow))
                self._tab1_results._MRD1_left.setText('{0:.2f}'.format(
                    MeasurementsLeft.MarginalReflexDistance1))
                self._tab1_results._MRD2_left.setText('{0:.2f}'.format(
                    MeasurementsLeft.MarginalReflexDistance2))
                self._tab1_results._BH_left.setText('{0:.2f}'.format(
                    MeasurementsLeft.BrowHeight))

                #deviation
                self._tab1_results._CE_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.CommissureExcursion))
                self._tab1_results._SA_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.SmileAngle))
                self._tab1_results._MRD1_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.MarginalReflexDistance1))
                self._tab1_results._MRD2_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.MarginalReflexDistance2))
                self._tab1_results._BH_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.BrowHeight))
                self._tab1_results._DS_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.DentalShow))
                self._tab1_results._CH_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.CommisureHeightDeviation))
                self._tab1_results._UVH_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.UpperLipHeightDeviation))
                self._tab1_results._LVH_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.LowerLipHeightDeviation))

                self._tab1_results._CE_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.CommissureExcursion))
                self._tab1_results._SA_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.SmileAngle))
                self._tab1_results._MRD1_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.MarginalReflexDistance1))
                self._tab1_results._MRD2_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.MarginalReflexDistance2))
                self._tab1_results._BH_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.BrowHeight))
                self._tab1_results._DS_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.DentalShow))

                delimiter = os.path.sep
                temp = self._file_name.split(delimiter)
                photo_name = temp[-1]
                photo_name = photo_name[0:-4]
                self._tab1_results._tab_name = photo_name

                #say to the window that presents the results that there is only 1 tab
                self._new_window = ShowResults(self._tab1_results)
                #show the window with the results
                self._new_window.show()
                self.displayImage.update_view()

        else:
            #here there is a patient and so the result window will have three tabs
            if (self._Patient.FirstPhoto._shape
                    is not None) and (self._Patient.SecondPhoto._shape
                                      is not None):
                #if the measurements window is already open then close it
                if self._new_window is not None:
                    self._new_window.close()
                    self._new_window = None

                #compute the facial metrics for the first photo and fill the information
                MeasurementsLeftFirst, MeasurementsRightFirst, MeasurementsDeviation, MeasurementsPercentual = get_measurements_from_data(
                    self._Patient.FirstPhoto._shape,
                    self._Patient.FirstPhoto._lefteye,
                    self._Patient.FirstPhoto._righteye)

                self._tab1_results = CustomTabResult()

                #filling t_new_window_tab1_results he info for the right
                self._tab1_results._CE_right.setText('{0:.2f}'.format(
                    MeasurementsRightFirst.CommissureExcursion))
                self._tab1_results._SA_right.setText('{0:.2f}'.format(
                    MeasurementsRightFirst.SmileAngle))
                self._tab1_results._DS_right.setText('{0:.2f}'.format(
                    MeasurementsRightFirst.DentalShow))
                self._tab1_results._MRD1_right.setText('{0:.2f}'.format(
                    MeasurementsRightFirst.MarginalReflexDistance1))
                self._tab1_results._MRD2_right.setText('{0:.2f}'.format(
                    MeasurementsRightFirst.MarginalReflexDistance2))
                self._tab1_results._BH_right.setText('{0:.2f}'.format(
                    MeasurementsRightFirst.BrowHeight))

                #filling the info for the left
                self._tab1_results._CE_left.setText('{0:.2f}'.format(
                    MeasurementsLeftFirst.CommissureExcursion))
                self._tab1_results._SA_left.setText('{0:.2f}'.format(
                    MeasurementsLeftFirst.SmileAngle))
                self._tab1_results._DS_left.setText('{0:.2f}'.format(
                    MeasurementsLeftFirst.DentalShow))
                self._tab1_results._MRD1_left.setText('{0:.2f}'.format(
                    MeasurementsLeftFirst.MarginalReflexDistance1))
                self._tab1_results._MRD2_left.setText('{0:.2f}'.format(
                    MeasurementsLeftFirst.MarginalReflexDistance2))
                self._tab1_results._BH_left.setText('{0:.2f}'.format(
                    MeasurementsLeftFirst.BrowHeight))

                #deviation
                self._tab1_results._CE_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.CommissureExcursion))
                self._tab1_results._SA_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.SmileAngle))
                self._tab1_results._MRD1_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.MarginalReflexDistance1))
                self._tab1_results._MRD2_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.MarginalReflexDistance2))
                self._tab1_results._BH_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.BrowHeight))
                self._tab1_results._DS_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.DentalShow))
                self._tab1_results._CH_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.CommisureHeightDeviation))
                self._tab1_results._UVH_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.UpperLipHeightDeviation))
                self._tab1_results._LVH_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.LowerLipHeightDeviation))

                self._tab1_results._CE_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.CommissureExcursion))
                self._tab1_results._SA_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.SmileAngle))
                self._tab1_results._MRD1_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.MarginalReflexDistance1))
                self._tab1_results._MRD2_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.MarginalReflexDistance2))
                self._tab1_results._BH_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.BrowHeight))
                self._tab1_results._DS_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.DentalShow))

                self._tab1_results._tab_name = self._Patient.FirstPhoto._ID

                #compute the facial metrics for the second photo and fill the information
                MeasurementsLeftSecond, MeasurementsRightSecond, MeasurementsDeviation, MeasurementsPercentual = get_measurements_from_data(
                    self._Patient.SecondPhoto._shape,
                    self._Patient.SecondPhoto._lefteye,
                    self._Patient.SecondPhoto._righteye)

                self._tab2_results = CustomTabResult()

                #filling t_new_window_tab1_results he info for the right
                self._tab2_results._CE_right.setText('{0:.2f}'.format(
                    MeasurementsRightSecond.CommissureExcursion))
                self._tab2_results._SA_right.setText('{0:.2f}'.format(
                    MeasurementsRightSecond.SmileAngle))
                self._tab2_results._DS_right.setText('{0:.2f}'.format(
                    MeasurementsRightSecond.DentalShow))
                self._tab2_results._MRD1_right.setText('{0:.2f}'.format(
                    MeasurementsRightSecond.MarginalReflexDistance1))
                self._tab2_results._MRD2_right.setText('{0:.2f}'.format(
                    MeasurementsRightSecond.MarginalReflexDistance2))
                self._tab2_results._BH_right.setText('{0:.2f}'.format(
                    MeasurementsRightSecond.BrowHeight))

                #filling the info for the left
                self._tab2_results._CE_left.setText('{0:.2f}'.format(
                    MeasurementsLeftSecond.CommissureExcursion))
                self._tab2_results._SA_left.setText('{0:.2f}'.format(
                    MeasurementsLeftSecond.SmileAngle))
                self._tab2_results._DS_left.setText('{0:.2f}'.format(
                    MeasurementsLeftSecond.DentalShow))
                self._tab2_results._MRD1_left.setText('{0:.2f}'.format(
                    MeasurementsLeftSecond.MarginalReflexDistance1))
                self._tab2_results._MRD2_left.setText('{0:.2f}'.format(
                    MeasurementsLeftSecond.MarginalReflexDistance2))
                self._tab2_results._BH_left.setText('{0:.2f}'.format(
                    MeasurementsLeftSecond.BrowHeight))

                #deviation
                self._tab2_results._CE_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.CommissureExcursion))
                self._tab2_results._SA_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.SmileAngle))
                self._tab2_results._MRD1_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.MarginalReflexDistance1))
                self._tab2_results._MRD2_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.MarginalReflexDistance2))
                self._tab2_results._BH_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.BrowHeight))
                self._tab2_results._DS_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.DentalShow))
                self._tab2_results._CH_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.CommisureHeightDeviation))
                self._tab2_results._UVH_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.UpperLipHeightDeviation))
                self._tab2_results._LVH_dev.setText('{0:.2f}'.format(
                    MeasurementsDeviation.LowerLipHeightDeviation))

                self._tab2_results._CE_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.CommissureExcursion))
                self._tab2_results._SA_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.SmileAngle))
                self._tab2_results._MRD1_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.MarginalReflexDistance1))
                self._tab2_results._MRD2_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.MarginalReflexDistance2))
                self._tab2_results._BH_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.BrowHeight))
                self._tab2_results._DS_dev_p.setText('{0:.2f}'.format(
                    MeasurementsPercentual.DentalShow))

                self._tab2_results._tab_name = self._Patient.SecondPhoto._ID

                #compute the the different between both photos and fill the information
                self._tab3_results = CustomTabResult()

                #filling tab3_results with the difference between the two photos
                self._tab3_results._CE_right.setText('{0:.2f}'.format(
                    -MeasurementsRightFirst.CommissureExcursion +
                    MeasurementsRightSecond.CommissureExcursion))
                self._tab3_results._SA_right.setText(
                    '{0:.2f}'.format(-MeasurementsRightFirst.SmileAngle +
                                     MeasurementsRightSecond.SmileAngle))
                self._tab3_results._DS_right.setText(
                    '{0:.2f}'.format(-MeasurementsRightFirst.DentalShow +
                                     MeasurementsRightSecond.DentalShow))
                self._tab3_results._MRD1_right.setText('{0:.2f}'.format(
                    -MeasurementsRightFirst.MarginalReflexDistance1 +
                    MeasurementsRightSecond.MarginalReflexDistance1))
                self._tab3_results._MRD2_right.setText('{0:.2f}'.format(
                    -MeasurementsRightFirst.MarginalReflexDistance2 +
                    MeasurementsRightSecond.MarginalReflexDistance2))
                self._tab3_results._BH_right.setText(
                    '{0:.2f}'.format(-MeasurementsRightFirst.BrowHeight +
                                     MeasurementsRightSecond.BrowHeight))

                #filling the info for the left
                self._tab3_results._CE_left.setText('{0:.2f}'.format(
                    -MeasurementsLeftFirst.CommissureExcursion +
                    MeasurementsLeftSecond.CommissureExcursion))
                self._tab3_results._SA_left.setText(
                    '{0:.2f}'.format(-MeasurementsLeftFirst.SmileAngle +
                                     MeasurementsLeftSecond.SmileAngle))
                self._tab3_results._DS_left.setText(
                    '{0:.2f}'.format(-MeasurementsLeftFirst.DentalShow +
                                     MeasurementsLeftSecond.DentalShow))
                self._tab3_results._MRD1_left.setText('{0:.2f}'.format(
                    -MeasurementsLeftFirst.MarginalReflexDistance1 +
                    MeasurementsLeftSecond.MarginalReflexDistance1))
                self._tab3_results._MRD2_left.setText('{0:.2f}'.format(
                    -MeasurementsLeftFirst.MarginalReflexDistance2 +
                    MeasurementsLeftSecond.MarginalReflexDistance2))
                self._tab3_results._BH_left.setText(
                    '{0:.2f}'.format(-MeasurementsLeftFirst.BrowHeight +
                                     MeasurementsLeftSecond.BrowHeight))

                #say to the window that presents the results that there are 3 tabs
                self._new_window = ShowResults(self._tab1_results,
                                               self._tab2_results,
                                               self._tab3_results)
                #show the window with the results
                self._new_window.show()
Beispiel #4
0
def compute_health_score(path_, Healthy_Side, pandas_df=None):

    path_ = path_
    all_Files = os.listdir(path_)
    all_Files.sort()
    ext_txt = ('.txt')
    Files = [i for i in all_Files if i.endswith(tuple(ext_txt))]
    ext_jpg = ('.jpg')
    Images = [i for i in all_Files if i.endswith(tuple(ext_jpg))]

    shape = []
    lefteye = []
    righteye = []
    boundingbox = []
    for file in Files:
        try:
            shape_, lefteye_, righteye_, boundingbox_ = get_info_from_txt(
                os.path.join(path_, file))
        except:
            print(os.path.join(path_, file))
            return

        shape.append(shape_)
        lefteye.append(lefteye_)
        righteye.append(righteye_)
        boundingbox.append(boundingbox_)

    CalibrationType = 'Iris'
    CalibrationValue = 11.77
    LeftRest, RightRest, _, _, IPrest = get_measurements_from_data(
        shape[0], lefteye[0], righteye[0], CalibrationType, CalibrationValue)
    LeftEyeBrow, RightEyeBrow, _, _, IPEyeBrow = get_measurements_from_data(
        shape[1], lefteye[1], righteye[1], CalibrationType, CalibrationValue)
    LeftEyeClosureGently, RightEyeClosureGently, _, _, IPEyeClosureGently = get_measurements_from_data(
        shape[2], lefteye[2], righteye[2], CalibrationType, CalibrationValue)
    LeftEyeClosureTight, RightEyeClosureTight, _, _, IPEyeClosureTight = get_measurements_from_data(
        shape[3], lefteye[3], righteye[3], CalibrationType, CalibrationValue)
    LeftSmallSmile, RightSmallSmile, _, _, IPSmallSmile = get_measurements_from_data(
        shape[4], lefteye[4], righteye[4], CalibrationType, CalibrationValue)
    LeftLargeSmile, RightLargeSmile, _, _, IPLargeSmile = get_measurements_from_data(
        shape[5], lefteye[5], righteye[5], CalibrationType, CalibrationValue)
    LeftPuckeringLips, RightPuckeringLips, _, _, IPPuckeringLips = get_measurements_from_data(
        shape[6], lefteye[6], righteye[6], CalibrationType, CalibrationValue)
    LeftDentalShow, RightDentalShow, _, _, IPDentalShow = get_measurements_from_data(
        shape[7], lefteye[7], righteye[7], CalibrationType, CalibrationValue)

    ##Static Measures
    # I'm following Tessa's nomenclature

    # 1) EyeBrow Elevation at rest
    a_left, a_right = LeftRest.BrowHeight, RightRest.BrowHeight
    if Healthy_Side == 'Right':
        Brow_at_rest = a_left / a_right
    else:
        Brow_at_rest = a_right / a_left

    Brow_at_rest = np.round(Brow_at_rest * 100, 1)

    # 2) Palpebral Fissure width at rest
    c_left, c_right = LeftRest.PalpebralFissureHeight, RightRest.PalpebralFissureHeight

    if Healthy_Side == 'Right':
        PalpebralFissure_at_rest = c_right / c_left
    else:
        PalpebralFissure_at_rest = c_left / c_right

    PalpebralFissure_at_rest = np.round(PalpebralFissure_at_rest * 100, 1)

    # 3) Oral commissure at rest
    e_right, d_right = np.sin((RightRest.SmileAngle - 90) * np.pi /
                              180) * RightRest.CommissureExcursion, np.cos(
                                  (RightRest.SmileAngle - 90) * np.pi /
                                  180) * RightRest.CommissureExcursion
    e_left, d_left = np.sin((LeftRest.SmileAngle - 90) * np.pi /
                            180) * LeftRest.CommissureExcursion, np.cos(
                                (LeftRest.SmileAngle - 90) * np.pi /
                                180) * LeftRest.CommissureExcursion
    if Healthy_Side == 'Right':
        #e_left is the disease side
        if e_left < e_right and e_left > 0:
            OralCommissure_at_rest = 1 - ((e_right - e_left) / e_right)
        else:
            OralCommissure_at_rest = d_left / d_right
    else:
        #e_right is the disease side
        if e_right < e_left and e_right > 0:
            OralCommissure_at_rest = 1 - ((e_left - e_right) / e_left)
        else:
            OralCommissure_at_rest = d_right / d_left

    OralCommissure_at_rest = np.round(OralCommissure_at_rest * 100, 1)

    #Static_Score = np.array([abs(100-Brow_at_rest), abs(100-PalpebralFissure_at_rest), abs(100-OralCommissure_at_rest )]).sum()
    #np.round(Static_Score,1)

    ##Dynamic Measures
    # 4) Brow Elevation
    b_left, b_right = LeftEyeBrow.BrowHeight, RightEyeBrow.BrowHeight
    if Healthy_Side == 'Right':
        EyeBrowElevation = (b_left - a_left) / (b_right - a_right)
    else:
        EyeBrowElevation = (b_right - a_right) / (b_left - a_left)

    EyeBrowElevation = np.round(EyeBrowElevation * 100, 1)

    # 5)Eye closure gentle
    g_left_gentle, g_right_gentle = LeftEyeClosureGently.PalpebralFissureHeight, RightEyeClosureGently.PalpebralFissureHeight
    if g_left_gentle < 1: g_left_gentle = 0
    if g_right_gentle < 1: g_right_gentle = 0
    #g might be negative (measurement errors)
    if Healthy_Side == 'Right':
        GentleEyeClosure = (c_left - abs(g_left_gentle)) / c_left
    else:
        GentleEyeClosure = (c_right - abs(g_right_gentle)) / c_right

    GentleEyeClosure = np.round(GentleEyeClosure * 100, 1)

    # 6)Eye closure full
    g_left_full, g_right_full = LeftEyeClosureTight.PalpebralFissureHeight, RightEyeClosureTight.PalpebralFissureHeight
    if g_left_full < 1: g_left_full = 0
    if g_right_full < 1: g_right_full = 0
    if Healthy_Side == 'Right':
        FullEyeClosure = (c_left - abs(g_left_full)) / c_left
    else:
        FullEyeClosure = (c_right - abs(g_right_full)) / c_right

    FullEyeClosure = np.round(FullEyeClosure * 100, 1)

    # 6) Oral Commissure with Smile
    # question for Tessa -> Is this with small or large smile? I'll do it with large smile for the moment
    f_left, f_right = LeftRest.CommissureExcursion, RightRest.CommissureExcursion
    h_left, h_right = LeftLargeSmile.CommissureExcursion, RightLargeSmile.CommissureExcursion
    #if with small smile, then comment above line an uncomment line below
    # h_left, h_right = LeftSmallSmile.CommissureExcursion, RightSmallSmile.CommissureExcursion
    if Healthy_Side == 'Right':
        OralCommissureWithSmile = (h_left - f_left) / (h_right - f_right)
    else:
        OralCommissureWithSmile = (h_right - f_right) / (h_left - f_left)

    OralCommissureWithSmile = np.round(OralCommissureWithSmile * 100, 1)

    #7) Lower Lip EEE

    j_left, j_right = LeftDentalShow.DentalShow, RightDentalShow.DentalShow
    if Healthy_Side == 'Right':
        #making sure that it will work if j_right is zero
        try:
            LowerLipEEE = j_left / j_right
        except:
            LowerLipEEE = np.nan
    else:
        #making sure that it will work if j_left is zero
        try:
            LowerLipEEE = j_right / j_left
        except:
            LowerLipEEE = np.nan

    LowerLipEEE = np.round(LowerLipEEE * 100, 1)

    #Dynamic_Score = np.array([abs(100-EyeBrowElevation), abs(100-GentleEyeClosure), abs(100-FullEyeClosure), abs(100-OralCommissureWithSmile), abs(100-LowerLipEEE)]).sum()
    #np.round(Dynamic_Score,1)

    ##Synkineis Measurements
    #Ocular synkinesis
    k1_left, k1_right = LeftLargeSmile.PalpebralFissureHeight, RightLargeSmile.PalpebralFissureHeight
    k2_left, k2_right = LeftPuckeringLips.PalpebralFissureHeight, RightPuckeringLips.PalpebralFissureHeight
    if Healthy_Side == 'Right':
        OcularSynkinesis1 = k1_left / k1_right
        OcularSynkinesis2 = k2_left / k2_right
    else:
        OcularSynkinesis1 = k1_right / k1_left
        OcularSynkinesis2 = k2_right / k2_left

    if OcularSynkinesis1 <= OcularSynkinesis2:
        OcularSynkinesis = OcularSynkinesis1
    else:
        OcularSynkinesis = OcularSynkinesis2

    OcularSynkinesis = np.round(OcularSynkinesis * 100, 1)

    #apply corrections to remove everything less than zero
    if Brow_at_rest < 0: Brow_at_rest = 0
    if PalpebralFissure_at_rest < 0: PalpebralFissure_at_rest = 0
    if OralCommissure_at_rest < 0: OralCommissure_at_rest = 0
    if EyeBrowElevation < 0: EyeBrowElevation = 0
    if GentleEyeClosure < 0: GentleEyeClosure = 0
    if FullEyeClosure < 0: FullEyeClosure = 0
    if OralCommissureWithSmile < 0: OralCommissureWithSmile = 0
    if LowerLipEEE < 0: LowerLipEEE = 0
    if OcularSynkinesis < 0: OcularSynkinesis = 0

    #    ##Computing the score based on Tessa's idea
    #    if Brow_at_rest<= 100:
    score_brow_rest = 100 - abs(100 - Brow_at_rest)
    score_PalpebralFissure_rest = 100 - abs(100 - PalpebralFissure_at_rest)
    score_OralCommissure_rest = 100 - abs(100 - OralCommissure_at_rest)

    score_EyeBrowElevation = 100 - abs(100 - EyeBrowElevation)
    score_GentleEyeClosure = 100 - abs(100 - GentleEyeClosure)
    score_FullEyeClosure = 100 - abs(100 - FullEyeClosure)
    score_OralCommissureWithSmile = 100 - abs(100 - OralCommissureWithSmile)
    score_LowerLipEEE = 100 - abs(100 - LowerLipEEE)

    score_OcularSynkinesis = 100 - abs(100 - OcularSynkinesis)

    print(score_brow_rest, score_PalpebralFissure_rest,
          score_OralCommissure_rest)

    StaticScore = (score_brow_rest + score_PalpebralFissure_rest +
                   score_OralCommissure_rest) / 3
    DynamicScore = (score_EyeBrowElevation + score_GentleEyeClosure +
                    score_FullEyeClosure + score_OralCommissureWithSmile +
                    score_LowerLipEEE) / 5
    SynkinesisScore = score_OcularSynkinesis

    TotalScore = (StaticScore + DynamicScore + SynkinesisScore) / 3
    #StaticScore, DynamicScore, SynkinesisScore ,TotalScore

    if pandas_df is not None:  #Save results in a data frame

        df_columns = [
            'Diagnosis', 'Subject', 'Healthy_Side', 'Eyebrow at Rest',
            'Palpebral Fissure at Rest', 'Oral Commissure at Rest',
            'Static Score', 'Eyebrow Elevation', 'Gentle Eye Closure',
            'Full Eye Closure', 'Oral Commissure with Smile',
            'Lower Lip with EEE', 'Dynamic Score', 'Ocular Synkenisis',
            'Total Score'
        ]

        #create the dataframe and set the index
        if os.path.isfile(pandas_df):  #the dataframe alreasy exists, opne it
            DataFrame = pd.read_csv(pandas_df, index_col=0)
        else:  #the file doesn't exist, create it
            DataFrame = pd.DataFrame(columns=df_columns)

        if 'normal' in path_:
            diag = 'normal'
        elif 'completeflaccid' in path_:
            diag = 'completeflaccid'
        else:
            diag = 'completeSynkinetic'

        subject = path_.split('\\')[-1]

        #datus = [diag, subject, Healthy_Side, Brow_at_rest, PalpebralFissure_at_rest, OralCommissure_at_rest, StaticScore,
        #         EyeBrowElevation, GentleEyeClosure, FullEyeClosure, OralCommissureWithSmile, LowerLipEEE, DynamicScore,
        #         OcularSynkinesis, TotalScore]

        datus = [
            diag, subject, Healthy_Side, Brow_at_rest,
            PalpebralFissure_at_rest, OralCommissure_at_rest, StaticScore,
            score_EyeBrowElevation, score_GentleEyeClosure,
            score_FullEyeClosure, score_OralCommissureWithSmile,
            score_LowerLipEEE, DynamicScore, score_OcularSynkinesis, TotalScore
        ]

        DataFrame = DataFrame.append(pd.Series(datus, index=df_columns),
                                     ignore_index=True)

        DataFrame.to_csv(pandas_df)
Beispiel #5
0
def Compute_eFace(Patient):

    #compute the different measures from each photo

    LeftRest, RightRest, _, _ = get_measurements_from_data(
        Patient._Rest._shape, Patient._Rest._lefteye, Patient._Rest._righteye,
        Patient._CalibrationType, Patient._CalibrationValue)

    LeftSmallSmile, RightSmallSmile, _, _ = get_measurements_from_data(
        Patient._SmallSmile._shape, Patient._SmallSmile._lefteye,
        Patient._SmallSmile._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    LeftLargeSmile, RightLargeSmile, _, _ = get_measurements_from_data(
        Patient._LargeSmile._shape, Patient._LargeSmile._lefteye,
        Patient._LargeSmile._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    LeftEyeBrow, RightEyeBrow, _, _ = get_measurements_from_data(
        Patient._EyeBrow._shape, Patient._EyeBrow._lefteye,
        Patient._EyeBrow._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    LeftEyeClosureGently, RightEyeClosureGently, _, _ = get_measurements_from_data(
        Patient._EyeClosureGently._shape, Patient._EyeClosureGently._lefteye,
        Patient._EyeClosureGently._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    LeftEyeClosureTight, RightEyeClosureTight, _, _ = get_measurements_from_data(
        Patient._EyeClosureTight._shape, Patient._EyeClosureTight._lefteye,
        Patient._EyeClosureTight._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    LeftPuckeringLips, RightPuckeringLips, DeviationPuckeringLips, _ = get_measurements_from_data(
        Patient._PuckeringLips._shape, Patient._PuckeringLips._lefteye,
        Patient._PuckeringLips._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    LeftDentalShow, RightDentalShow, _, _ = get_measurements_from_data(
        Patient._DentalShow._shape, Patient._DentalShow._lefteye,
        Patient._DentalShow._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    #Brow at Rest
    if Patient._HealthySide == 'Right':

        DeltaBrow = RightEyeBrow.BrowHeight - RightRest.BrowHeight

        BrowatRest = (RightRest.BrowHeight - LeftRest.BrowHeight) / DeltaBrow

    elif Patient._HealthySide == 'Left':

        DeltaBrow = LeftEyeBrow.BrowHeight - LeftRest.BrowHeight

        BrowatRest = (LeftRest.BrowHeight - RightRest.BrowHeight) / DeltaBrow

    #Brow Elevantion with Brow Raising
    if Patient._HealthySide == 'Right':

        DeltaBrow = RightEyeBrow.BrowHeight - RightRest.BrowHeight

        BrowatRaising = (LeftRest.BrowHeight -
                         LeftEyeBrow.BrowHeight) / DeltaBrow

    elif Patient._HealthySide == 'Left':

        DeltaBrow = LeftEyeBrow.BrowHeight - LeftRest.BrowHeight

        BrowatRaising = (RightRest.BrowHeight -
                         RightEyeBrow.BrowHeight) / DeltaBrow

    #Palpebral Fisure at Rest
    PalpebralFissureRest = palpebral_fissure(
        Patient._Rest, Patient._CalibrationType,
        Patient._CalibrationValue)  #[Rigth, Left]
    if Patient._HealthySide == 'Right':

        DeltaPalpebralFissureRest = PalpebralFissureRest[
            1] / PalpebralFissureRest[0]

    elif Patient._HealthySide == 'Left':

        DeltaPalpebralFissureRest = PalpebralFissureRest[
            0] / PalpebralFissureRest[1]

    #Oral commisure at rest
    if Patient._HealthySide == 'Right':

        DeltaOralCommissure = RightLargeSmile.CommissureExcursion - RightRest.CommissureExcursion

        OralCommissureatRest = (
            RightRest.CommissureExcursion -
            LeftRest.CommissureExcursion) / DeltaOralCommissure

    elif Patient._HealthySide == 'Left':

        DeltaOralCommissure = LeftLargeSmile.CommissureExcursion - LeftRest.CommissureExcursion

        OralCommissureatRest = (
            LeftRest.CommissureExcursion -
            RightRest.CommissureExcursion) / DeltaOralCommissure

    #Oral commisure with Smile
    if Patient._HealthySide == 'Right':

        DeltaOralCommissure = RightLargeSmile.CommissureExcursion - RightRest.CommissureExcursion

        OralCommissureatSmile = (
            RightLargeSmile.CommissureExcursion -
            LeftLargeSmile.CommissureExcursion) / DeltaOralCommissure

    elif Patient._HealthySide == 'Left':

        DeltaOralCommissure = LeftLargeSmile.CommissureExcursion - LeftRest.CommissureExcursion

        OralCommissureatSmile = (
            LeftLargeSmile.CommissureExcursion -
            RightLargeSmile.CommissureExcursion) / DeltaOralCommissure

    #Palpebral Fisure at Gentle eye closure
    PalpebralFissureEyeClosureGently = palpebral_fissure(
        Patient._EyeClosureGently, Patient._CalibrationType,
        Patient._CalibrationValue)  #[Rigth, Left]
    if Patient._HealthySide == 'Right':
        #Right eye is healthy, measure how much left eye is open with respect to paralized eye at rest
        GentleEyeClossure = 1 - PalpebralFissureEyeClosureGently[
            1] / PalpebralFissureRest[1]

    elif Patient._HealthySide == 'Left':
        #Left eye is healthy, measure how much right eye is open with respect to paralized eye at rest
        GentleEyeClossure = 1 - PalpebralFissureEyeClosureGently[
            0] / PalpebralFissureRest[0]

    #Palpebral Fisure at Tight eye closure
    PalpebralFissureEyeClosureTight = palpebral_fissure(
        Patient._EyeClosureTight, Patient._CalibrationType,
        Patient._CalibrationValue)  #[Rigth, Left]
    if Patient._HealthySide == 'Right':
        #Right eye is healthy, measure how much left eye is open with respect to paralized eye at rest
        EyeClosureTight = 1 - PalpebralFissureEyeClosureTight[
            1] / PalpebralFissureRest[1]

    elif Patient._HealthySide == 'Left':
        #Left eye is healthy, measure how much right eye is open with respect to paralized eye at rest
        EyeClosureTight = 1 - PalpebralFissureEyeClosureTight[
            0] / PalpebralFissureRest[0]

    #lower lip movement with EEEE
    if Patient._HealthySide == 'Right':

        LowerLipMovementEEEE = LeftDentalShow.LoweLipActivation / RightDentalShow.LoweLipActivation

    elif Patient._HealthySide == 'Left':

        LowerLipMovementEEEE = RightDentalShow.LoweLipActivation / LeftDentalShow.LoweLipActivation

    #Ocular Synkinesis
    PalpebralFissureLargeSmile = palpebral_fissure(
        Patient._LargeSmile, Patient._CalibrationType,
        Patient._CalibrationValue)  #[Rigth, Left]
    PalpebralFissurePuckeringLips = palpebral_fissure(
        Patient._PuckeringLips, Patient._CalibrationType,
        Patient._CalibrationValue)  #[Rigth, Left]
    if Patient._HealthySide == 'Right':

        DeltaPalpebralFissureLargeSmile = PalpebralFissureLargeSmile[
            1] / PalpebralFissureLargeSmile[0]
        DeltaPalpebralFissurePuckeringLips = PalpebralFissurePuckeringLips[
            1] / PalpebralFissurePuckeringLips[0]

        OcularSynkinesis_Smile = (
            PalpebralFissureLargeSmile[1] / PalpebralFissureRest[1]) / (
                PalpebralFissureLargeSmile[0] / PalpebralFissureRest[0])
        OcularSynkinesis_Pucker = (
            PalpebralFissurePuckeringLips[1] / PalpebralFissureRest[1]) / (
                PalpebralFissurePuckeringLips[0] / PalpebralFissureRest[0])

    elif Patient._HealthySide == 'Left':

        DeltaPalpebralFissureLargeSmile = PalpebralFissureLargeSmile[
            0] / PalpebralFissureLargeSmile[1]
        DeltaPalpebralFissurePuckeringLips = PalpebralFissurePuckeringLips[
            0] / PalpebralFissurePuckeringLips[1]

        OcularSynkinesis_Smile = (
            PalpebralFissureLargeSmile[0] / PalpebralFissureRest[0]) / (
                PalpebralFissureLargeSmile[1] / PalpebralFissureRest[1])
        OcularSynkinesis_Pucker = (
            PalpebralFissurePuckeringLips[0] / PalpebralFissureRest[0]) / (
                PalpebralFissurePuckeringLips[1] / PalpebralFissureRest[1])

    if OcularSynkinesis_Smile <= OcularSynkinesis_Pucker:
        OcularSynkinesis = OcularSynkinesis_Smile
    else:
        OcularSynkinesis = OcularSynkinesis_Pucker

    return BrowatRest, DeltaPalpebralFissureRest, OralCommissureatRest, BrowatRaising, GentleEyeClossure, EyeClosureTight, OralCommissureatSmile, LowerLipMovementEEEE, OcularSynkinesis
Beispiel #6
0
def Compute_eFace(Patient):

    #compute the different measures from each photo

    LeftRest, RightRest, _, _, IPrest = get_measurements_from_data(
        Patient._Rest._shape, Patient._Rest._lefteye, Patient._Rest._righteye,
        Patient._CalibrationType, Patient._CalibrationValue)

    # LeftSmallSmile, RightSmallSmile, _, _, IPSmallSmile = get_measurements_from_data(Patient._SmallSmile._shape, Patient._SmallSmile._lefteye, Patient._SmallSmile._righteye, Patient._CalibrationType, Patient._CalibrationValue)

    LeftLargeSmile, RightLargeSmile, _, _, IPLargeSmile = get_measurements_from_data(
        Patient._LargeSmile._shape, Patient._LargeSmile._lefteye,
        Patient._LargeSmile._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    LeftEyeBrow, RightEyeBrow, _, _, IPEyeBrow = get_measurements_from_data(
        Patient._EyeBrow._shape, Patient._EyeBrow._lefteye,
        Patient._EyeBrow._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    LeftEyeClosureGently, RightEyeClosureGently, _, _, IPEyeClosureGently = get_measurements_from_data(
        Patient._EyeClosureGently._shape, Patient._EyeClosureGently._lefteye,
        Patient._EyeClosureGently._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    LeftEyeClosureTight, RightEyeClosureTight, _, _, IPEyeClosureTight = get_measurements_from_data(
        Patient._EyeClosureTight._shape, Patient._EyeClosureTight._lefteye,
        Patient._EyeClosureTight._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    LeftPuckeringLips, RightPuckeringLips, _, _, IPPuckeringLips = get_measurements_from_data(
        Patient._PuckeringLips._shape, Patient._PuckeringLips._lefteye,
        Patient._PuckeringLips._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    LeftDentalShow, RightDentalShow, _, _, IPDentalShow = get_measurements_from_data(
        Patient._DentalShow._shape, Patient._DentalShow._lefteye,
        Patient._DentalShow._righteye, Patient._CalibrationType,
        Patient._CalibrationValue)

    # 1) EyeBrow Elevation at rest
    a_left, a_right = LeftRest.BrowHeight, RightRest.BrowHeight
    if Patient._HealthySide == 'Right':
        Brow_at_rest = a_left / a_right
    else:
        Brow_at_rest = a_right / a_left

    Brow_at_rest = np.round(Brow_at_rest * 100, 1)

    # 2) Palpebral Fissure width at rest
    c_left, c_right = LeftRest.PalpebralFissureHeight, RightRest.PalpebralFissureHeight

    if Patient._HealthySide == 'Right':
        PalpebralFissure_at_rest = c_right / c_left
    else:
        PalpebralFissure_at_rest = c_left / c_right

    PalpebralFissure_at_rest = np.round(PalpebralFissure_at_rest * 100, 1)

    # 3) Oral commissure at rest
    e_right, d_right = np.sin((RightRest.SmileAngle - 90) * np.pi /
                              180) * RightRest.CommissureExcursion, np.cos(
                                  (RightRest.SmileAngle - 90) * np.pi /
                                  180) * RightRest.CommissureExcursion
    e_left, d_left = np.sin((LeftRest.SmileAngle - 90) * np.pi /
                            180) * LeftRest.CommissureExcursion, np.cos(
                                (LeftRest.SmileAngle - 90) * np.pi /
                                180) * LeftRest.CommissureExcursion
    if Patient._HealthySide == 'Right':
        #e_left is the disease side
        if e_left < e_right and e_left > 0:
            OralCommissure_at_rest = 1 - ((e_right - e_left) / e_right)
        else:
            OralCommissure_at_rest = d_left / d_right
    else:
        #e_right is the disease side
        if e_right < e_left and e_right > 0:
            OralCommissure_at_rest = 1 - ((e_left - e_right) / e_left)
        else:
            OralCommissure_at_rest = d_right / d_left

    OralCommissure_at_rest = np.round(OralCommissure_at_rest * 100, 1)

    #Static_Score = np.array([abs(100-Brow_at_rest), abs(100-PalpebralFissure_at_rest), abs(100-OralCommissure_at_rest )]).sum()
    #np.round(Static_Score,1)

    ##Dynamic Measures
    # 4) Brow Elevation
    b_left, b_right = LeftEyeBrow.BrowHeight, RightEyeBrow.BrowHeight
    if Patient._HealthySide == 'Right':
        EyeBrowElevation = (b_left - a_left) / (b_right - a_right)
    else:
        EyeBrowElevation = (b_right - a_right) / (b_left - a_left)

    EyeBrowElevation = np.round(EyeBrowElevation * 100, 1)

    # 5)Eye closure gentle
    g_left_gentle, g_right_gentle = LeftEyeClosureGently.PalpebralFissureHeight, RightEyeClosureGently.PalpebralFissureHeight
    if g_left_gentle < 1: g_left_gentle = 0
    if g_right_gentle < 1: g_right_gentle = 0
    #g might be negative (measurement errors)
    if Patient._HealthySide == 'Right':
        GentleEyeClosure = (c_left - abs(g_left_gentle)) / c_left
    else:
        GentleEyeClosure = (c_right - abs(g_right_gentle)) / c_right

    GentleEyeClosure = np.round(GentleEyeClosure * 100, 1)

    # 6)Eye closure full
    g_left_full, g_right_full = LeftEyeClosureTight.PalpebralFissureHeight, RightEyeClosureTight.PalpebralFissureHeight
    if g_left_full < 1: g_left_full = 0
    if g_right_full < 1: g_right_full = 0
    if Patient._HealthySide == 'Right':
        FullEyeClosure = (c_left - abs(g_left_full)) / c_left
    else:
        FullEyeClosure = (c_right - abs(g_right_full)) / c_right

    FullEyeClosure = np.round(FullEyeClosure * 100, 1)

    # 6) Oral Commissure with Smile
    # question for Tessa -> Is this with small or large smile? I'll do it with large smile for the moment
    f_left, f_right = LeftRest.CommissureExcursion, RightRest.CommissureExcursion
    h_left, h_right = LeftLargeSmile.CommissureExcursion, RightLargeSmile.CommissureExcursion
    #if with small smile, then comment above line an uncomment line below
    # h_left, h_right = LeftSmallSmile.CommissureExcursion, RightSmallSmile.CommissureExcursion
    if Patient._HealthySide == 'Right':
        OralCommissureWithSmile = (h_left - f_left) / (h_right - f_right)
    else:
        OralCommissureWithSmile = (h_right - f_right) / (h_left - f_left)

    OralCommissureWithSmile = np.round(OralCommissureWithSmile * 100, 1)

    #7) Lower Lip EEE

    j_left, j_right = LeftDentalShow.DentalShow, RightDentalShow.DentalShow
    if Patient._HealthySide == 'Right':
        #making sure that it will work if j_right is zero
        try:
            LowerLipEEE = j_left / j_right
        except:
            LowerLipEEE = np.nan
    else:
        #making sure that it will work if j_left is zero
        try:
            LowerLipEEE = j_right / j_left
        except:
            LowerLipEEE = np.nan

    LowerLipEEE = np.round(LowerLipEEE * 100, 1)

    #Dynamic_Score = np.array([abs(100-EyeBrowElevation), abs(100-GentleEyeClosure), abs(100-FullEyeClosure), abs(100-OralCommissureWithSmile), abs(100-LowerLipEEE)]).sum()
    #np.round(Dynamic_Score,1)

    ##Synkineis Measurements
    #Ocular synkinesis
    k1_left, k1_right = LeftLargeSmile.PalpebralFissureHeight, RightLargeSmile.PalpebralFissureHeight
    k2_left, k2_right = LeftPuckeringLips.PalpebralFissureHeight, RightPuckeringLips.PalpebralFissureHeight
    if Patient._HealthySide == 'Right':
        OcularSynkinesis1 = k1_left / k1_right
        OcularSynkinesis2 = k2_left / k2_right
    else:
        OcularSynkinesis1 = k1_right / k1_left
        OcularSynkinesis2 = k2_right / k2_left

    if OcularSynkinesis1 <= OcularSynkinesis2:
        OcularSynkinesis = OcularSynkinesis1
    else:
        OcularSynkinesis = OcularSynkinesis2

    OcularSynkinesis = np.round(OcularSynkinesis * 100, 1)

    #apply corrections to remove everything less than zero
    if Brow_at_rest < 0: Brow_at_rest = 0
    if Brow_at_rest > 200: Brow_at_rest = 200
    if PalpebralFissure_at_rest < 0: PalpebralFissure_at_rest = 0
    if PalpebralFissure_at_rest > 200: PalpebralFissure_at_rest = 200
    if OralCommissure_at_rest > 200: OralCommissure_at_rest = 200

    if OralCommissure_at_rest < 0: OralCommissure_at_rest = 0
    if OralCommissure_at_rest > 100: OralCommissure_at_rest = 100
    if EyeBrowElevation < 0: EyeBrowElevation = 0
    if EyeBrowElevation > 100: EyeBrowElevation = 100
    if GentleEyeClosure < 0: GentleEyeClosure = 0
    if GentleEyeClosure > 100: GentleEyeClosure = 100
    if FullEyeClosure < 0: FullEyeClosure = 0
    if FullEyeClosure > 100: FullEyeClosure = 100
    if OralCommissureWithSmile < 0: OralCommissureWithSmile = 0
    if OralCommissureWithSmile > 100: OralCommissureWithSmile = 100
    if LowerLipEEE < 0: LowerLipEEE = 0
    if LowerLipEEE > 100: LowerLipEEE = 100
    if OcularSynkinesis < 0: OcularSynkinesis = 0
    if OcularSynkinesis > 100: OcularSynkinesis = 100

    #Computing the score based on Tessa's idea

    score_brow_rest = 100 - abs(100 - Brow_at_rest)
    score_PalpebralFissure_rest = 100 - abs(100 - PalpebralFissure_at_rest)
    score_OralCommissure_rest = 100 - abs(100 - OralCommissure_at_rest)

    score_EyeBrowElevation = EyeBrowElevation  #100-abs(100-EyeBrowElevation)
    score_GentleEyeClosure = GentleEyeClosure  #100-abs(100-GentleEyeClosure)
    score_FullEyeClosure = FullEyeClosure  #100- abs(100-FullEyeClosure)
    score_OralCommissureWithSmile = OralCommissureWithSmile  #100 - abs(100-OralCommissureWithSmile)
    score_LowerLipEEE = LowerLipEEE  #100 - abs(100-LowerLipEEE)

    score_OcularSynkinesis = OcularSynkinesis  #100-abs(100-OcularSynkinesis)

    StaticScore = (score_brow_rest + score_PalpebralFissure_rest +
                   score_OralCommissure_rest) / 3
    DynamicScore = (score_EyeBrowElevation + score_GentleEyeClosure +
                    score_FullEyeClosure + score_OralCommissureWithSmile +
                    score_LowerLipEEE) / 5
    SynkinesisScore = score_OcularSynkinesis

    return Brow_at_rest, PalpebralFissure_at_rest, OralCommissure_at_rest, EyeBrowElevation, GentleEyeClosure, FullEyeClosure, OralCommissureWithSmile, LowerLipEEE, OcularSynkinesis, StaticScore, DynamicScore, SynkinesisScore
Beispiel #7
0
    def save_results(self):
        #save the results in a txt and xls files.
        if self._file_name is not None:
            if self.displayImage._shape is not None:
                MeasurementsLeft, MeasurementsRight, MeasurementsDeviation, MeasurementsPercentual, _ = get_measurements_from_data(
                    self.displayImage._shape, self.displayImage._lefteye,
                    self.displayImage._righteye, self._CalibrationType,
                    self._CalibrationValue)
                #
                temp = SaveWindow(self, self._file_name, self._photograph._Tag,
                                  MeasurementsLeft, MeasurementsRight,
                                  MeasurementsDeviation,
                                  MeasurementsPercentual)
                temp.exec_()

                if temp._acceptSave:

                    save_txt_file(self._file_name, self.displayImage._shape,
                                  self.displayImage._lefteye,
                                  self.displayImage._righteye,
                                  self.displayImage._boundingbox)
Beispiel #8
0
    def create_new_window(self):
        #this creates a new window to display all the facial metrics, there

        if self.displayImage._shape is not None:
            #if the measurements window is already open then close it
            if self._new_window is not None:
                self._new_window.close()
                self._new_window = None

            #compute the facial metrics using the landmarks
            MeasurementsLeft, MeasurementsRight, MeasurementsDeviation, MeasurementsPercentual, _ = get_measurements_from_data(
                self.displayImage._shape, self.displayImage._lefteye,
                self.displayImage._righteye, self._CalibrationType,
                self._CalibrationValue)

            #send all the information the the appropiate places in the window
            self._tab1_results = CustomTabResult()

            #filling t_new_window_tab1_results he info for the right
            self._tab1_results._CE_right.setText('{0:.2f}'.format(
                MeasurementsRight.CommissureExcursion))
            self._tab1_results._SA_right.setText('{0:.2f}'.format(
                MeasurementsRight.SmileAngle))
            self._tab1_results._DS_right.setText('{0:.2f}'.format(
                MeasurementsRight.DentalShow))
            self._tab1_results._MRD1_right.setText('{0:.2f}'.format(
                MeasurementsRight.MarginalReflexDistance1))
            self._tab1_results._MRD2_right.setText('{0:.2f}'.format(
                MeasurementsRight.MarginalReflexDistance2))
            self._tab1_results._BH_right.setText('{0:.2f}'.format(
                MeasurementsRight.BrowHeight))

            #filling the info for the left
            self._tab1_results._CE_left.setText('{0:.2f}'.format(
                MeasurementsLeft.CommissureExcursion))
            self._tab1_results._SA_left.setText('{0:.2f}'.format(
                MeasurementsLeft.SmileAngle))
            self._tab1_results._DS_left.setText('{0:.2f}'.format(
                MeasurementsLeft.DentalShow))
            self._tab1_results._MRD1_left.setText('{0:.2f}'.format(
                MeasurementsLeft.MarginalReflexDistance1))
            self._tab1_results._MRD2_left.setText('{0:.2f}'.format(
                MeasurementsLeft.MarginalReflexDistance2))
            self._tab1_results._BH_left.setText('{0:.2f}'.format(
                MeasurementsLeft.BrowHeight))

            #deviation
            self._tab1_results._CE_dev.setText('{0:.2f}'.format(
                MeasurementsDeviation.CommissureExcursion))
            self._tab1_results._SA_dev.setText('{0:.2f}'.format(
                MeasurementsDeviation.SmileAngle))
            self._tab1_results._MRD1_dev.setText('{0:.2f}'.format(
                MeasurementsDeviation.MarginalReflexDistance1))
            self._tab1_results._MRD2_dev.setText('{0:.2f}'.format(
                MeasurementsDeviation.MarginalReflexDistance2))
            self._tab1_results._BH_dev.setText('{0:.2f}'.format(
                MeasurementsDeviation.BrowHeight))
            self._tab1_results._DS_dev.setText('{0:.2f}'.format(
                MeasurementsDeviation.DentalShow))
            self._tab1_results._CH_dev.setText('{0:.2f}'.format(
                MeasurementsDeviation.CommisureHeightDeviation))
            self._tab1_results._UVH_dev.setText('{0:.2f}'.format(
                MeasurementsDeviation.UpperLipHeightDeviation))
            self._tab1_results._LVH_dev.setText('{0:.2f}'.format(
                MeasurementsDeviation.LowerLipHeightDeviation))

            self._tab1_results._CE_dev_p.setText('{0:.2f}'.format(
                MeasurementsPercentual.CommissureExcursion))
            self._tab1_results._SA_dev_p.setText('{0:.2f}'.format(
                MeasurementsPercentual.SmileAngle))
            self._tab1_results._MRD1_dev_p.setText('{0:.2f}'.format(
                MeasurementsPercentual.MarginalReflexDistance1))
            self._tab1_results._MRD2_dev_p.setText('{0:.2f}'.format(
                MeasurementsPercentual.MarginalReflexDistance2))
            self._tab1_results._BH_dev_p.setText('{0:.2f}'.format(
                MeasurementsPercentual.BrowHeight))
            self._tab1_results._DS_dev_p.setText('{0:.2f}'.format(
                MeasurementsPercentual.DentalShow))

            delimiter = os.path.sep
            temp = self._file_name.split(delimiter)
            photo_name = temp[-1]
            photo_name = photo_name[0:-4]
            self._tab1_results._tab_name = photo_name

            #say to the window that presents the results that there is only 1 tab
            self._new_window = ShowResults(self._tab1_results)
            #show the window with the results
            self._new_window.show()