def color_pipeline(self, image, show_dict, save_dict): # maybe multiprocessing when showing images, otherwise you might have to wait to run depth_pipeline gray = wp.grayscale(image) # grayscaling is necessary to the process show_dict.update({"Grayscaled": (gray, 'gray')}) save_dict.update({"Gray": (gray, f'{ESAT7A1}/Images/grayscaled images/')}) # gray is the reference, don't change it if self.gauss_bool.get(): gauss = wp.gaussian_blur(gray, self.gauss_reps.get()) show_dict.update({"Gaussian Blur": (gauss, 'gray')}) save_dict.update({"Gauss": (gauss, f'{ESAT7A1}/Images/blurred images/')}) else: gauss = gray if self.sobel_bool.get(): sobel = wp.sobel(gauss) show_dict.update({"Sobel": (sobel, 'gray')}) save_dict.update({"Sobel": (sobel, f'{ESAT7A1}/Images/sobel images/')}) else: sobel = gauss if self.hyst_bool.get(): hyst = wp.hysteresis(sobel, self.low_th.get(), self.high_th.get()) show_dict.update({"Hysteresis": (hyst, 'gray')}) save_dict.update({"Hyst": (hyst, f'{ESAT7A1}/Images/hysteresis images/')}) else: hyst = sobel if self.fill_bool.get(): filled = ndimage.binary_fill_holes(hyst) show_dict.update({"Filled": (filled, 'gray')}) save_dict.update({"Filled": (filled, f'{ESAT7A1}/Images/filled images/')}) else: filled = hyst if self.senne_bool.get(): sobel2 = wp.sobel(filled) senne_obj, nb_obj = wp.detect_objects_senne(0, sobel2, 100) show_dict.update({f"BROPAS: {nb_obj} objects": (senne_obj, 'gray')}) save_dict.update({"BROPAS": (senne_obj, f'{ESAT7A1}/Images/sobel images/')}) else: sobel2 = filled if self.count_bool.get(): # hier dan sennes algoritme in steken db, nb_objects = wp.detect_objects(filled) show_dict.update({"DBSCAN": (db, 'viridis')}) save_dict.update({"DetectedObjects": (db, f'{ESAT7A1}/Images/object images/')}) else: db = filled nb_objects = None if self.box_bool.get(): boxes = wp.draw_boxes(image, db) show_dict.update({"boxes": (boxes, 'gray')}) save_dict.update({"Boxes": (boxes, f'{ESAT7A1}/Images/draw boxes/')}) # save and show if self.show_bool.get(): p = Process(target=wp.show_images, args=(show_dict, nb_objects)) p.start() # p.join() # wp.show_images(show_dict) if self.save_bool.get(): wp.save_images(save_dict)
def sobel_en_thin(): global th_low structure = np.array([[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]]) filepath = filedialog.askopenfilename() image = np.array(Image.open(filepath)) image = grayscale(image) image = gaussian_blur(image, 1) m, t = sobel(image) thin = thin_edges(m, t, th_low) t0 = time.time() hyst1 = hysteresis(m, 10, 80) t1 = time.time() hyst_thin = hysteresis(thin, 10, 80) t2 = time.time() filled1 = ndimage.binary_fill_holes(hyst1) t3 = time.time() filled_thin = ndimage.binary_fill_holes(hyst_thin) t4 = time.time() obj = detect_objects(filled1) t5 = time.time() obj_thin = detect_objects(filled_thin) t6 = time.time() print(f"hyst: {t1-t0}") print(f"hyst_thinned: {t2-t1}") print(f"filled: {t3-t2}") print(f"filled_thinned: {t4-t3}") print(f"db: {t5-t4}") print(f"db_thinned: {t6-t5}") f = plt.figure() f.suptitle("zoom in als ge de lijnen wilt zien") f.add_subplot(2, 4, 1) plt.imshow(m, cmap='gray') plt.title('sobel') f.add_subplot(2, 4, 5) plt.imshow(thin, cmap='gray') plt.title('thinned edges') f.add_subplot(2, 4, 2) plt.imshow(hyst1, cmap='gray') plt.title('hysteresis') f.add_subplot(2, 4, 6) plt.imshow(hyst_thin, cmap='gray') plt.title('hysteresis (thinned)') f.add_subplot(2, 4, 3) plt.imshow(filled1, cmap='gray') plt.title('filled') f.add_subplot(2, 4, 7) plt.imshow(filled_thin, cmap='gray') plt.title('filled (thinned)') f.add_subplot(2, 4, 4) plt.imshow(obj, cmap='gray') plt.title('db') f.add_subplot(2, 4, 8) plt.imshow(obj_thin, cmap='gray') plt.title('db (thinned)') plt.show()