Openimage4problem option5 option6

This preview shows page 8 - 11 out of 11 pages.

Option4 = self.open_image('4',problem)Option5 = self.open_image('5',problem)Option6 = self.open_image('6',problem)options = {1 : Option1, 2 : Option2, 3 : Option3, 4: Option4, 5: Option5, 6: Option6}#use for loop(loop for each option) and calculate AB, C1 and AC, B1 for both metrics#each loop should give you 4 valuesfor i in range(1,7):dpr_AB = self.intersection_pixel_ratio(figA,figB)dpr_Ci = self.intersection_pixel_ratio(figC,options[i])dpr_AC = self.intersection_pixel_ratio(figA,figC)dpr_Bi = self.intersection_pixel_ratio(figB,options[i])
if i ==1:option_values = np.array([dpr_AB,dpr_Ci,dpr_AC,dpr_Bi])#square root of sum of squaresknn = np.array([np.sqrt((dpr_AB-dpr_Ci)**2 + (dpr_AC-dpr_Bi)**2)])else:option_values = np.vstack([option_values, [dpr_AB,dpr_Ci,dpr_AC,dpr_Bi]])knn = np.vstack([knn, [np.sqrt((dpr_AB-dpr_Ci)**2 + (dpr_AC-dpr_Bi)**2)]])#normalize dataknn_norm = (knn-np.min(knn))/(np.max(knn) - np.min(knn))#allign it from 01 to 1. 1 being the most confidentknn_norm = 1 - knn_norm#check if the second highest confidence is close to the first. If so, ignore and continue to do other transformations#print knn#print knn_norm#print 1.0 - knn_norm[knn_norm.flatten().argsort()[-2:][0]]if 1.0 - knn_norm[knn_norm.flatten().argsort()[-2:][0]] < 0.08: #8%percentreturn -1else:return np.argmin(knn)+1'''if np.partition(knn.flatten(), 2)[1]/np.min(knn) < 4.0:return -1else:return np.argmin(knn)+1'''def knn(self,problem):figA = self.open_image('A',problem)figB = self.open_image('B',problem)figC = self.open_image('C',problem)Option1 = self.open_image('1',problem)Option2 = self.open_image('2',problem)Option3 = self.open_image('3',problem)Option4 = self.open_image('4',problem)Option5 = self.open_image('5',problem)Option6 = self.open_image('6',problem)options = {1 : Option1, 2 : Option2, 3 : Option3, 4: Option4, 5: Option5, 6: Option6}#use for loop(loop for each option) and calculate AB, C1 and AC, B1 for both metrics#each loop should give you 4 valuesfor i in range(1,7):
dpr_AB = self.dark_pixel_ratio(figA,figB)dpr_Ci = self.dark_pixel_ratio(figC,options[i])dpr_AC = self.dark_pixel_ratio(figA,figC)dpr_Bi = self.dark_pixel_ratio(figB,options[i])ipr_AB = self.intersection_pixel_ratio(figA,figB)ipr_Ci = self.intersection_pixel_ratio(figC,options[i])ipr_AC = self.intersection_pixel_ratio(figA,figC)ipr_Bi = self.intersection_pixel_ratio(figB,options[i])if i ==1:option_values = np.array([dpr_AB,dpr_Ci,dpr_AC,dpr_Bi,ipr_AB,ipr_Ci,ipr_AC,ipr_Bi])#square root of sum of squaresknn = np.array([np.sqrt((dpr_AB-dpr_Ci)**2 + (dpr_AC-dpr_Bi)**2 + (ipr_AB-ipr_Ci)**2 + (ipr_AC-ipr_Bi)**2)])else:option_values = np.vstack([option_values, [dpr_AB,dpr_Ci,dpr_AC,dpr_Bi,ipr_AB,ipr_Ci,ipr_AC,ipr_Bi]])knn = np.vstack([knn, [np.sqrt((dpr_AB-dpr_Ci)**2 + (dpr_AC-dpr_Bi)**2 + (ipr_AB-ipr_Ci)**2 + (ipr_AC-ipr_Bi)**2)]])knn_norm = (knn-np.min(knn))/(np.max(knn) - np.min(knn))#allign it from 01 to 1. 1 being the most confidentknn_norm = 1 - knn_norm#print knn_norm#check if the second highest confidence is close to the first. If so, ignore and continue to do other transformationsif 1.0 - knn_norm[knn_norm.flatten().argsort()[-2:][0]] < 0.1: #10%percentreturn -1else:return np.argmin(knn)+1'''if np.partition(knn.flatten(), 2)[1]/np.min(knn) < 3.0:return -1else:return np.argmin(knn)+1'''

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture