def otsu_one(img, img_file, man_img, mask=None): # cv2.GaussianBlur(img, (5,5),0) # Bilateral Filter is used separately so it can be adjusted for each type of segmentation blur = cv2.bilateralFilter(img, 5, 5, 5) th = single_threshold_otsu(blur, mask) if mask is None: ret, thresh = cv2.threshold(blur, th, 255, cv2.THRESH_BINARY) else: combined_img = cv2.bitwise_and(blur, blur, mask=mask) ret, thresh = cv2.threshold(combined_img, th, 255, cv2.THRESH_BINARY) # Otsu result image out_img_o = thresh # morphological ops kernel = morphologicalOps.open_center_kernel() out_img_o = morphologicalOps.opening(out_img_o, kernel) out_info_o = "_otsu_%d" % (th) out_str_o = out_info_o + '.png' out_file_o = re.sub(r'\.jpg', out_str_o, img_file) cv2.imwrite(out_file_o, out_img_o) t = evaluation.findTotals(out_img_o, man_img) f = open('o1_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def otsuTwo(img, img_file, man_img, mask=None): # blur = cv2.GaussianBlur(img, (5,5),0) blur = cv2.bilateralFilter(img, 5, 100, 100) thresholds = multithresholdOtsu(blur,mask) th1 = thresholds[0] th2 = thresholds[1] if mask is None: ret, thresh1 = cv2.threshold(blur,th1,255,cv2.THRESH_BINARY) ret, thresh2 = cv2.threshold(blur,th2,255,cv2.THRESH_BINARY_INV) else: combined_img = cv2.bitwise_and(blur, blur, mask=mask) ret, thresh1 = cv2.threshold(combined_img,th1,255,cv2.THRESH_BINARY) ret, thresh2 = cv2.threshold(combined_img,th2,255,cv2.THRESH_BINARY_INV) out_img_o = cv2.bitwise_and(thresh1, thresh2, mask=None) out_info_o = "_otsu_%d-%d" % (th1, th2) out_str_o = out_info_o + '.png' out_file_o = re.sub(r'\.jpg', out_str_o, img_file) cv2.imwrite(out_file_o, out_img_o) t = evaluation.findTotals(out_img_o, man_img) f = open('o2_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def otsuTwo(img, img_file, man_img, mask=None): # blur = cv2.GaussianBlur(img, (5,5),0) blur = cv2.bilateralFilter(img, 5, 100, 100) thresholds = multithresholdOtsu(blur, mask) th1 = thresholds[0] th2 = thresholds[1] if mask is None: ret, thresh1 = cv2.threshold(blur, th1, 255, cv2.THRESH_BINARY) ret, thresh2 = cv2.threshold(blur, th2, 255, cv2.THRESH_BINARY_INV) else: combined_img = cv2.bitwise_and(blur, blur, mask=mask) ret, thresh1 = cv2.threshold(combined_img, th1, 255, cv2.THRESH_BINARY) ret, thresh2 = cv2.threshold(combined_img, th2, 255, cv2.THRESH_BINARY_INV) out_img_o = cv2.bitwise_and(thresh1, thresh2, mask=None) out_info_o = "_otsu_%d-%d" % (th1, th2) out_str_o = out_info_o + '.png' out_file_o = re.sub(r'\.jpg', out_str_o, img_file) cv2.imwrite(out_file_o, out_img_o) t = evaluation.findTotals(out_img_o, man_img) f = open('o2_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def otsuThree(img, img_file, man_img, mask=None): # blur = cv2.GaussianBlur(img, (5,5),0) blur = cv2.bilateralFilter(img, 5, 100, 100) thresholds = threeThresholdOtsu(blur, mask) th1 = thresholds[0] th2 = thresholds[1] th3 = thresholds[2] # if mask is None: # ret, thresh1 = cv2.threshold(blur,th1,150,cv2.THRESH_BINARY) # ret, thresh2 = cv2.threshold(blur,th2,150,cv2.THRESH_BINARY_INV) # lower_img = cv2.bitwise_and(thresh1, thresh2, mask=None) # ret, thresh2 = cv2.threshold(blur, th2, 200, cv2.THRESH_BINARY) # ret, thresh3 = cv2.threshold(blur, th3, 200, cv2.THRESH_BINARY_INV) # middle_img = cv2.bitwise_and(thresh2, thresh3, mask=None) # ret, upper_img = cv2.threshold(blur, th3, 255, cv2.THRESH_BINARY) # else: # combined_img = cv2.bitwise_and(blur, blur, mask=mask) # ret, thresh1 = cv2.threshold(combined_img,th1,150,cv2.THRESH_BINARY) # ret, thresh2 = cv2.threshold(combined_img,th2,150,cv2.THRESH_BINARY_INV) # lower_img = cv2.bitwise_and(thresh1, thresh2, mask=mask) # ret, thresh2 = cv2.threshold(blur, th2, 200, cv2.THRESH_BINARY) # ret, thresh3 = cv2.threshold(blur, th3, 200, cv2.THRESH_BINARY_INV) # middle_img = cv2.bitwise_and(thresh2, thresh3, mask=mask) # ret, upper_img = cv2.threshold(blur, th3, 255, cv2.THRESH_BINARY) # out_img_one = cv2.bitwise_or(lower_img, middle_img, mask=mask) # out_img_o = cv2.bitwise_or(out_img_one, upper_img, mask=mask) if mask is None: ret, thresh = cv2.threshold(blur, th3, 255, cv2.THRESH_BINARY) else: combined_img = cv2.bitwise_and(blur, blur, mask=mask) ret, thresh = cv2.threshold(combined_img, th, 255, cv2.THRESH_BINARY) out_img_o = thresh out_info_o = "_otsu_%d-%d-%d" % (th1, th2, th3) out_str_o = out_info_o + '.png' out_file_o = re.sub(r'\.jpg', out_str_o, img_file) cv2.imwrite(out_file_o, out_img_o) t = evaluation.findTotals(out_img_o, man_img) # f = open('o3_all.txt', 'a') # f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") # f.close() # t = evaluation.findTotalsOtsu3(out_img_o, man_img, 150) # f = open('o3_t1-t2_all.txt', 'a') # f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") # f.close() # t = evaluation.findTotalsOtsu3(out_img_o, man_img, 200) # f = open('o3_t2-t3_all.txt', 'a') # f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") # f.close() t = evaluation.findTotalsOtsu3(out_img_o, man_img, 255) f = open('o3_t3-max_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def otsuThree(img, img_file, man_img, mask=None): # blur = cv2.GaussianBlur(img, (5,5),0) blur = cv2.bilateralFilter(img, 5, 100, 100) thresholds = threeThresholdOtsu(blur,mask) th1 = thresholds[0] th2 = thresholds[1] th3 = thresholds[2] # if mask is None: # ret, thresh1 = cv2.threshold(blur,th1,150,cv2.THRESH_BINARY) # ret, thresh2 = cv2.threshold(blur,th2,150,cv2.THRESH_BINARY_INV) # lower_img = cv2.bitwise_and(thresh1, thresh2, mask=None) # ret, thresh2 = cv2.threshold(blur, th2, 200, cv2.THRESH_BINARY) # ret, thresh3 = cv2.threshold(blur, th3, 200, cv2.THRESH_BINARY_INV) # middle_img = cv2.bitwise_and(thresh2, thresh3, mask=None) # ret, upper_img = cv2.threshold(blur, th3, 255, cv2.THRESH_BINARY) # else: # combined_img = cv2.bitwise_and(blur, blur, mask=mask) # ret, thresh1 = cv2.threshold(combined_img,th1,150,cv2.THRESH_BINARY) # ret, thresh2 = cv2.threshold(combined_img,th2,150,cv2.THRESH_BINARY_INV) # lower_img = cv2.bitwise_and(thresh1, thresh2, mask=mask) # ret, thresh2 = cv2.threshold(blur, th2, 200, cv2.THRESH_BINARY) # ret, thresh3 = cv2.threshold(blur, th3, 200, cv2.THRESH_BINARY_INV) # middle_img = cv2.bitwise_and(thresh2, thresh3, mask=mask) # ret, upper_img = cv2.threshold(blur, th3, 255, cv2.THRESH_BINARY) # out_img_one = cv2.bitwise_or(lower_img, middle_img, mask=mask) # out_img_o = cv2.bitwise_or(out_img_one, upper_img, mask=mask) if mask is None: ret, thresh = cv2.threshold(blur,th3,255,cv2.THRESH_BINARY) else: combined_img = cv2.bitwise_and(blur, blur, mask=mask) ret, thresh = cv2.threshold(combined_img,th,255,cv2.THRESH_BINARY) out_img_o = thresh out_info_o = "_otsu_%d-%d-%d" % (th1, th2, th3) out_str_o = out_info_o + '.png' out_file_o = re.sub(r'\.jpg', out_str_o, img_file) cv2.imwrite(out_file_o, out_img_o) t = evaluation.findTotals(out_img_o, man_img) # f = open('o3_all.txt', 'a') # f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") # f.close() # t = evaluation.findTotalsOtsu3(out_img_o, man_img, 150) # f = open('o3_t1-t2_all.txt', 'a') # f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") # f.close() # t = evaluation.findTotalsOtsu3(out_img_o, man_img, 200) # f = open('o3_t2-t3_all.txt', 'a') # f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") # f.close() t = evaluation.findTotalsOtsu3(out_img_o, man_img, 255) f = open('o3_t3-max_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def bilateral_filter(img, seed, th, img_file, out_info, man_img): img_b = cv2.bilateralFilter(img, 5, 5, 5) out_img_b = seeded_region_growing(img_b, seed, th) out_str_b = out_info + '_b.png' out_file_b = re.sub(r'\.jpg', out_str_b, img_file) cv2.imwrite(out_file_b, out_img_b) t = evaluation.findTotals(out_img_b, man_img) f = open('b_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def unsmoothed(img, seed, th, img_file, out_info, man_img): img_n = img out_img_n = seeded_region_growing(img_n, seed, th) out_str_n = out_info + '_n.png' out_file_n = re.sub(r'\.jpg', out_str_n, img_file) cv2.imwrite(out_file_n, out_img_n) t = evaluation.findTotals(out_img_n, man_img) f = open('n_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def bilateral_filter(img, eqImg, seed, th, img_file, out_info, man_img): img_b = cv2.bilateralFilter(img, 5, 10, 10) out_img_b = seeded_region_growing(img_b, seed, th) out_str_b = out_info + '_b.png' out_file_b = re.sub(r'\.jpg', out_str_b, img_file) cv2.imwrite(out_file_b, out_img_b) t = evaluation.findTotals(out_img_b, man_img) f = open('b_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def unsmoothed(img, eqImg, seed, th, img_file, out_info, man_img): img_n = img out_img_n = seeded_region_growing(img_n, seed, th) out_str_n = out_info + '_n.png' out_file_n = re.sub(r'\.jpg', out_str_n, img_file) cv2.imwrite(out_file_n, out_img_n) t = evaluation.findTotals(out_img_n, man_img) f = open('n_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def averageFilters(img, eqImg, seed, th, img_file, out_info, man_img): img_a = cv2.blur(img, (3,3)) img_ah = cv2.blur(eqImg, (3,3)) out_img_a = seeded_region_growing(img_a, seed, th) out_str_a = out_info + '_a.png' out_file_a = re.sub(r'\.jpg', out_str_a, img_file) cv2.imwrite(out_file_a, out_img_a) t = evaluation.findTotals(out_img_a, man_img) f = open('a.txt', 'a') f.write(str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close() out_img_ah = seeded_region_growing(img_ah, seed, th) out_str_ah = out_info + '_ah.png' out_file_ah = re.sub(r'\.jpg', out_str_ah, img_file) cv2.imwrite(out_file_ah, out_img_ah) t = evaluation.findTotals(out_img_ah, man_img) f = open('ah.txt', 'a') f.write(str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def GaussianFilters(img, eqImg, seed, th, img_file, out_info, man_img): img_g = cv2.GaussianBlur(img, (3,3), 0) img_gh = cv2.GaussianBlur(eqImg, (3,3), 0) out_img_g = seeded_region_growing(img_g, seed, th) out_str_g = out_info + '_g.png' out_file_g = re.sub(r'\.jpg', out_str_g, img_file) cv2.imwrite(out_file_g, out_img_g) t = evaluation.findTotals(out_img_g, man_img) f = open('g_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close() out_img_gh = seeded_region_growing(img_gh, seed, th) out_str_gh = out_info + '_gh.png' out_file_gh = re.sub(r'\.jpg', out_str_gh, img_file) cv2.imwrite(out_file_gh, out_img_gh) t = evaluation.findTotals(out_img_gh, man_img) f = open('gh_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def averageFilters(img, eqImg, seed, th, img_file, out_info, man_img): img_a = cv2.blur(img, (3,3)) img_ah = cv2.blur(eqImg, (3,3)) out_img_a = seeded_region_growing(img_a, seed, th) out_str_a = out_info + '_a.png' out_file_a = re.sub(r'\.jpg', out_str_a, img_file) cv2.imwrite(out_file_a, out_img_a) t = evaluation.findTotals(out_img_a, man_img) f = open('a_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close() out_img_ah = seeded_region_growing(img_ah, seed, th) out_str_ah = out_info + '_ah.png' out_file_ah = re.sub(r'\.jpg', out_str_ah, img_file) cv2.imwrite(out_file_ah, out_img_ah) t = evaluation.findTotals(out_img_ah, man_img) f = open('ah_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def GaussianFilters(img, eqImg, seed, th, img_file, out_info, man_img): img_g = cv2.GaussianBlur(img, (3,3), 0) img_gh = cv2.GaussianBlur(eqImg, (3,3), 0) out_img_g = seeded_region_growing(img_g, seed, th) out_str_g = out_info + '_g.png' out_file_g = re.sub(r'\.jpg', out_str_g, img_file) cv2.imwrite(out_file_g, out_img_g) t = evaluation.findTotals(out_img_g, man_img) f = open('g.txt', 'a') f.write(str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close() out_img_gh = seeded_region_growing(img_gh, seed, th) out_str_gh = out_info + '_gh.png' out_file_gh = re.sub(r'\.jpg', out_str_gh, img_file) cv2.imwrite(out_file_gh, out_img_gh) t = evaluation.findTotals(out_img_gh, man_img) f = open('gh.txt', 'a') f.write(str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def bilateral_filter(img, seed, th, img_file, out_info, man_img): img_b = cv2.bilateralFilter(img, 5, 5, 5) # SRG result image out_img_b = seeded_region_growing(img_b, seed, th) # morphological ops kernel = morphologicalOps.open_elliptical_kernel() out_img_b = morphologicalOps.opening(out_img_b, kernel) out_str_b = out_info + '_b.png' out_file_b = re.sub(r'\.jpg', out_str_b, img_file) cv2.imwrite(out_file_b, out_img_b) t = evaluation.findTotals(out_img_b, man_img) f = open('b_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def unsmoothed(img, seed, th, img_file, out_info, man_img): img_n = img # SRG result image out_img_n = seeded_region_growing(img_n, seed, th) # Morphological op kernel = morphologicalOps.open_elliptical_kernel() out_img_n = morphologicalOps.opening(out_img_n, kernel) out_str_n = out_info + '_n.png' out_file_n = re.sub(r'\.jpg', out_str_n, img_file) cv2.imwrite(out_file_n, out_img_n) t = evaluation.findTotals(out_img_n, man_img) f = open('n_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def unsmoothed(img, seed, th, img_file, out_info, man_img): img_n = img # SRG result image out_img_n = seeded_region_growing(img_n, seed, th) # Morphological op kernel = morphologicalOps.open_cross_kernel() out_img_n = morphologicalOps.opening(out_img_n, kernel) out_str_n = out_info + '_n.png' out_file_n = re.sub(r'\.jpg', out_str_n, img_file) cv2.imwrite(out_file_n, out_img_n) t = evaluation.findTotals(out_img_n, man_img) f = open('n_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def bilateral_filter(img, seed, th, img_file, out_info, man_img): img_b = cv2.bilateralFilter(img, 5, 5, 5) # SRG result image out_img_b = seeded_region_growing(img_b, seed, th) # morphological ops kernel = morphologicalOps.open_cross_kernel() out_img_b = morphologicalOps.opening(out_img_b, kernel) out_str_b = out_info + '_b.png' out_file_b = re.sub(r'\.jpg', out_str_b, img_file) cv2.imwrite(out_file_b, out_img_b) t = evaluation.findTotals(out_img_b, man_img) f = open('b_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def otsu_one(img, img_file, man_img, mask=None): # cv2.GaussianBlur(img, (5,5),0) # Bilateral Filter is used separately so it can be adjusted for each type of segmentation blur = cv2.bilateralFilter(img, 5, 100, 100) th = single_threshold_otsu(blur, mask) if mask is None: ret, thresh = cv2.threshold(blur,th,255,cv2.THRESH_BINARY) else: combined_img = cv2.bitwise_and(blur, blur, mask=mask) ret, thresh = cv2.threshold(combined_img,th,255,cv2.THRESH_BINARY) out_img_o = thresh out_info_o = "_otsu_%d" % (th) out_str_o = out_info_o + '.png' out_file_o = re.sub(r'\.jpg', out_str_o, img_file) cv2.imwrite(out_file_o, out_img_o) t = evaluation.findTotals(out_img_o, man_img) f = open('o1_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def otsuOne(img, img_file, man_img, mask=None): blur = cv2.GaussianBlur(img, (5,5),0) th = singlethresholdOtsu(blur,mask) if mask is None: ret, thresh = cv2.threshold(blur,th,255,cv2.THRESH_BINARY) else: combined_img = cv2.bitwise_and(blur, blur, mask=mask) ret, thresh = cv2.threshold(combined_img,th,255,cv2.THRESH_BINARY) out_img_o = thresh out_info_o = "_otsu_%d" % (th) out_str_o = out_info_o + '.png' out_file_o = re.sub(r'\.jpg', out_str_o, img_file) cv2.imwrite(out_file_o, out_img_o) t = evaluation.findTotals(out_img_o, man_img) f = open('o1.txt', 'a') f.write(str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def otsuOne(img, img_file, man_img, mask=None): blur = cv2.GaussianBlur(img, (5,5),0) th = singlethresholdOtsu(blur,mask) if mask is None: ret, thresh = cv2.threshold(blur,th,255,cv2.THRESH_BINARY) else: combined_img = cv2.bitwise_and(blur, blur, mask=mask) ret, thresh = cv2.threshold(combined_img,th,255,cv2.THRESH_BINARY) out_img_o = thresh out_info_o = "_otsu_%d" % (th) out_str_o = out_info_o + '.png' out_file_o = re.sub(r'\.jpg', out_str_o, img_file) cv2.imwrite(out_file_o, out_img_o) t = evaluation.findTotals(out_img_o, man_img) f = open('o1_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def otsuThree(img, img_file, man_img, mask=None): blur = cv2.GaussianBlur(img, (5,5),0) thresholds = threeThresholdOtsu(blur,mask) th1 = thresholds[0] th2 = thresholds[1] th3 = thresholds[2] if mask is None: ret, thresh1 = cv2.threshold(blur,th1,150,cv2.THRESH_BINARY) ret, thresh2 = cv2.threshold(blur,th2,150,cv2.THRESH_BINARY_INV) lower_img = cv2.bitwise_and(thresh1, thresh2, mask=None) ret, thresh2 = cv2.threshold(blur, th2, 200, cv2.THRESH_BINARY) ret, thresh3 = cv2.threshold(blur, th3, 200, cv2.THRESH_BINARY_INV) middle_img = cv2.bitwise_and(thresh2, thresh3, mask=None) ret, upper_img = cv2.threshold(blur, th3, 255, cv2.THRESH_BINARY) else: combined_img = cv2.bitwise_and(blur, blur, mask=mask) ret, thresh1 = cv2.threshold(combined_img,th1,150,cv2.THRESH_BINARY) ret, thresh2 = cv2.threshold(combined_img,th2,150,cv2.THRESH_BINARY_INV) lower_img = cv2.bitwise_and(thresh1, thresh2, mask=mask) ret, thresh2 = cv2.threshold(blur, th2, 200, cv2.THRESH_BINARY) ret, thresh3 = cv2.threshold(blur, th3, 200, cv2.THRESH_BINARY_INV) middle_img = cv2.bitwise_and(thresh2, thresh3, mask=mask) ret, upper_img = cv2.threshold(blur, th3, 255, cv2.THRESH_BINARY) out_img_one = cv2.bitwise_or(lower_img, middle_img, mask=mask) out_img_o = cv2.bitwise_or(out_img_one, upper_img, mask=mask) out_info_o = "_otsu_%d-%d-%d" % (th1, th2, th3) out_str_o = out_info_o + '.png' out_file_o = re.sub(r'\.jpg', out_str_o, img_file) cv2.imwrite(out_file_o, out_img_o) t = evaluation.findTotals(out_img_o, man_img) f = open('o3.txt', 'a') f.write(str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()
def otsu_three(img, img_file, man_img, mask=None): # blur = cv2.GaussianBlur(img, (5,5),0) # Bilateral Filter is used separately so it can be adjusted for each type of segmentation blur = cv2.bilateralFilter(img, 3, 20, 20) thresholds = three_threshold_otsu(blur, mask) th1 = thresholds[0] th2 = thresholds[1] th3 = thresholds[2] if mask is None: ret, thresh = cv2.threshold(blur,th3,255,cv2.THRESH_BINARY) else: combined_img = cv2.bitwise_and(blur, blur, mask=mask) ret, thresh = cv2.threshold(combined_img,th,255,cv2.THRESH_BINARY) out_img_o = thresh out_info_o = "_otsu_%d-%d-%d" % (th1, th2, th3) out_str_o = out_info_o + '.png' out_file_o = re.sub(r'\.jpg', out_str_o, img_file) cv2.imwrite(out_file_o, out_img_o) t = evaluation.findTotals(out_img_o, man_img) f = open('o3_t3-max_all.txt', 'a') f.write(img_file + " " + str(t[0]) + " " + str(t[1]) + " " + str(t[2]) + " " + str(t[3]) + "\n") f.close()