def change(arg): global panelA, points, img, imgA_handler, imgB_handler, panelB, blended, curr_label, to_save, before_circles, ori_right # compose new points new_points = [] for p in sh.points: new_points.append(p.x) new_points.append(p.y) if arg == "resetpoly": # convert point into [x,y] pair lists points = [[new_points[i], new_points[i+1]] for i in range(0,len(new_points),2)] points = np.array(points, np.int32) # initialize blank canvas blank = np.empty_like(curr_label.label_im) cv2.fillPoly(blank, [points], (1,1,1)) # reset polygon region curr_label.new_label[blank == (1,1,1)] = curr_label.label_im[blank==(1,1,1)] # recompute search region curr_label.recompute() label = curr_label.new_label elif arg == "resetall": # get original label curr_label.resetAll() label = curr_label.label_im # delete circles on panelB panelB.delete("all") # re-pack image on panelB img = ImageTk.PhotoImage(orig_image) imgB_handler = panelB.create_image((0,0), image = img, anchor = "nw") else: # add to original labels label = curr_label.add_label(new_points,arg) # blend again label = Image.fromarray(label) # label.thumbnail((window_size,window_size)) # gray = cv2.cvtColor(adj_image, cv2.COLOR_GRAY2RGB) # gray = Image.fromarray(gray) # gray.thumbnail((window_size,window_size)) blended = Image.blend(orig_image, label, 0.3) # before_circles = np.copy(mixed) blended = ImageTk.PhotoImage(blended) # delete original img panelA.delete("all") imgA_handler = panelA.create_image((0,0), image = blended, anchor = "nw") sh.reset() panelA.bind("<Button-1>", sh.draw) return imgA_handler, imgB_handler
def detect_EC(): global thresh, panelA, imgA, imgB, circles_left, before_circles, EC_count, panelB, circles_right tmp = np.copy(before_circles) # adjust adj_image size ori_image = Image.fromarray(adj_image) ori_image.thumbnail((window_size, window_size)) ori_image = np.array(ori_image) # detect EC circles_left, EC_count, circles_right = cnt.detect_EC( tmp, thresh, curr_label, ori_image) print("Number of ECs: " + str(EC_count)) # convert circles circles_left = Image.fromarray(circles_left) circles_left = ImageTk.PhotoImage(circles_left) circles_right = Image.fromarray(circles_right) circles_right = ImageTk.PhotoImage(circles_right) # reset panelA panelA.delete("all") imgA = panelA.create_image((0, 0), image=circles_left, anchor="nw") sh.reset() panelA.bind("<Button-1>", sh.draw) # reset panelB panelB.delete("all") imgB = panelB.create_image((0, 0), image=circles_right, anchor="nw") return imgA, imgB
def clear_ECs(): global blended, orig_image,imgB_handler, img # re-create panelA image label = Image.fromarray(curr_label.label_im) blended = Image.blend(orig_image, label, 0.3) blended = ImageTk.PhotoImage(blended) # reset panelA panelA.delete("all") imgA_handler = panelA.create_image((0,0), image = blended, anchor = "nw") sh.reset() panelA.bind("<Button-1>", sh.draw) # reset panelB img = ImageTk.PhotoImage(orig_image) panelB.delete("all") imgB_handler = panelB.create_image((0,0), image = img, anchor = "nw")
def change(arg): global panelA, points, imgA, imgB, panelB, mixed, curr_label, to_save, before_circles, ori_right # compose new points new_points = [] for p in sh.points: new_points.append(p.x) new_points.append(p.y) if arg == "resetpoly": points = [[new_points[i], new_points[i + 1]] for i in range(0, len(new_points), 2)] points = np.array(points, np.int32) # initialize blank canvas blank = np.empty_like(curr_label) cv2.fillPoly(blank, [points], (1, 1, 1)) # reset polygon region curr_label[blank == (1, 1, 1)] = origin[blank == (1, 1, 1)] elif arg == "resetall": curr_label = origin ori_right = Image.fromarray(adj_image) ori_right.thumbnail((window_size, window_size)) ori_right = ImageTk.PhotoImage(ori_right) panelB.delete("all") imgB = panelB.create_image((0, 0), image=ori_right, anchor="nw") else: # add to original labels label_im = cnt.add_label(curr_label, new_points, arg) curr_label = label_im to_save = curr_label # blend again label = Image.fromarray(curr_label) label.thumbnail((window_size, window_size)) gray = cv2.cvtColor(adj_image, cv2.COLOR_GRAY2RGB) gray = Image.fromarray(gray) gray.thumbnail((window_size, window_size)) mixed = Image.blend(gray, label, 0.3) before_circles = np.copy(mixed) mixed = ImageTk.PhotoImage(mixed) # delete original img panelA.delete("all") imgA = panelA.create_image((0, 0), image=mixed, anchor="nw") sh.reset() panelA.bind("<Button-1>", sh.draw) return imgA, imgB
def clear_EC(): global panelA, imgA, imgB, panelB, circles_right, circles_left # assign back the origin images circles_left = Image.fromarray(before_circles) circles_left = ImageTk.PhotoImage(circles_left) circles_right = Image.fromarray(adj_image) circles_right.thumbnail((window_size, window_size)) circles_right = ImageTk.PhotoImage(circles_right) # delete original img panelA.delete("all") imgA = panelA.create_image((0, 0), image=circles_left, anchor="nw") sh.reset() panelA.bind("<Button-1>", sh.draw) panelB.delete("all") imgB = panelB.create_image((0, 0), image=circles_right, anchor="nw") return imgA
def detect_ECs(): global imgB_handler, img, blended, imgA_handler, orig_image # detect ECs new_thresh = cv2.cvtColor(np.array(orig_image), cv2.COLOR_BGR2GRAY) new_thresh = bradley(new_thresh) circles = curr_label.detect_EC(new_thresh) print(circles) # re-create image for panel A label = Image.fromarray(curr_label.new_label) blended = Image.blend(orig_image, label, 0.3) blended = np.array(blended) # re-create image for panel B img = np.array(orig_image) # draw circles num = 0 for center in circles: cv2.circle(blended, center, 8, [255,0,0], thickness=2) cv2.circle(img, center, 8, [255,0,0], thickness=2) num += 1 # reset panelA blended = Image.fromarray(blended) blended = ImageTk.PhotoImage(blended) panelA.delete("all") imgA_handler = panelA.create_image((0,0), image = blended, anchor = "nw") sh.reset() panelA.bind("<Button-1>", sh.draw) # reset panelB img = Image.fromarray(img) img = ImageTk.PhotoImage(img) panelB.delete("all") imgB_handler = panelB.create_image((0,0), image = img, anchor = "nw") print("number of ECs: " + str(num))