def smooth_temperatures(self, method='mean', window=3):
        if method == 'mean':
            self.T1_smooth = filters.mean_filter(self.T1, window)
            self.T2_smooth = filters.mean_filter(self.T2, window)
        elif method == 'median':
            self.T1_smooth = filters.median_filter(self.T1, window)
            self.T2_smooth = filters.median_filter(self.T2, window)
        else:
            raise ValueError("Unsupported method. Use only 'mean' or 'median'")

        self.T1_res = self.T1 - self.T1_smooth
        self.T2_res = self.T2 - self.T2_smooth
Пример #2
0
def main():
    parser = build_parser()
    args = vars(parser.parse_args(sys.argv[1:]))
    min_range = args['min_range']
    max_range = args['max_range']
    measurement_interval = args["measurement_interval"]
    scan_rate = args["scan_rate"]
    seed = args["seed"]
    num_measurements = args["num_measurements"]
    num_previous_scans = args["D"]

    transform = compose(range_filter(min_range, max_range),
                        median_filter(num_measurements, num_previous_scans))

    queue = Queue()
    t1 = LidarDriver(queue,
                     scan_rate=scan_rate,
                     num_measurements=num_measurements,
                     rand_interval=measurement_interval,
                     seed=seed)

    t1.daemon = True
    t1.start()
    process_events(queue,
                   reactive_transduce(transducer=transform, target=rprint()))
def generate_median_filter_input():
    interface = InterfaceInfo.get_instance()
    if interface.current_image is not None:
        interface.delete_widgets(interface.buttons_frame)
        ttk.Label(interface.buttons_frame, text="Windows size", background=constants.TOP_COLOR).grid(row=0, column=0)
        windows_size = Entry(interface.buttons_frame)
        windows_size.grid(row=0, column=1)
        generate_noise = ttk.Button(interface.buttons_frame, text="Apply",
                                    command=lambda: median_filter(interface.current_image, constants.WIDTH,
                                                                  constants.HEIGHT, int(windows_size.get())))
        generate_noise.grid(row=1, column=0)
    else:
        interface.reset_parameters()
        messagebox.showerror(title="Error", message="You must upload an image to apply median filter ")
Пример #4
0
def all_filters(frame,scale_percent = 20, threshVal1 = 120, threshVal2 = 255,thresholdVal1_inv = 70,thresholdVal2_inv = 255,
				thresholdVal3 = 0, thresholdVal4 = 100,median_filter_size = 5,blackign =3):
	# ret, frame = cap.read()
	
	# print (frame.shape)
	width = int(frame.shape[1] * scale_percent / 100)
	height = int(frame.shape[0] * scale_percent / 100)
	dsize = (width, height)
	frame = cv2.resize(frame, dsize)

	H = cv2.cvtColor(frame,cv2.COLOR_RGB2HSV_FULL)
	# H = cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY)
	# print (frame.shape)
	frame2 = threshold(H[:,:,1].copy(),threshVal1,threshVal2)
	frame3 = threshold_inv(frame[:,:,1].copy(),thresholdVal1_inv,thresholdVal2_inv)
	frame4 = threshold(frame[:,:,0].copy(),thresholdVal3,thresholdVal4)
	frame2 = np.array(frame2,np.uint8)
	frame3 = np.array(frame3,np.uint8)
	frame4 = np.array(frame4,np.uint8)
	# print (frame4.shape)
	frame2 = median_filter(frame2,filter_size = median_filter_size,plot=False)
	frame3 = median_filter(frame3,filter_size = median_filter_size,plot=False)
	frame4 = median_filter(frame4,filter_size = median_filter_size,plot=False)
	# print (frame4.shape)
	frame3 = blacker(frame3,blackign)
	# frame3,a = sobel(frame3,True)
	frame3 = gaussian(frame3.copy(),9,plot=False)
	# frame4 = laplacian(frame2)

	a = pixel_count(frame3)
	b = pixel_count(frame4)
	
	if b !=0:
		ratio_full = (a/b+1)*100
	# print ('ammatasiri methnata wenakan enawa')
	return frame2, frame3, frame4, a,b, ratio_full
	
Пример #5
0
  cols = img.shape[1]

  for i in range(0, rows):
    for j in range(0, cols):
      rand_value = random.random()

      if rand_value < p:
        new_value = 0
      elif rand_value > 1 - p:
        new_value = 255
      else:
        new_value = new_image[i][j]

      new_image[i][j] = new_value

  return new_image


noised_image = apply_salt_and_pepper(img, 0.3)
denoised_image = median_filter(noised_image, 5)

cv2.imshow('image',noised_image)
cv2.waitKey(0)
cv2.destroyAllWindows()

cv2.imshow('median', denoised_image)
cv2.waitKey(0)
cv2.destroyAllWindows()


Пример #6
0
    width = int(frame.shape[1] * scale_percent / 100)
    height = int(frame.shape[0] * scale_percent / 100)
    dsize = (width, height)
    frame = cv2.resize(frame, dsize)

    H = cv2.cvtColor(frame, cv2.COLOR_RGB2HSV_FULL)
    # H = cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY)

    frame2 = threshold(H[:, :, 1].copy(), 120, 255)
    frame3 = threshold_inv(frame[:, :, 1].copy(), 70, 255)
    frame4 = threshold(frame[:, :, 0].copy(), 0, 100)
    frame2 = np.array(frame2, np.uint8)
    frame3 = np.array(frame3, np.uint8)
    frame4 = np.array(frame4, np.uint8)

    frame2 = median_filter(frame2, filter_size=3, plot=False)
    frame3 = median_filter(frame3, filter_size=3, plot=False)
    frame4 = median_filter(frame4, filter_size=5, plot=False)

    frame3 = blacker(frame3, 300)
    # frame3,a = sobel(frame3,True)
    frame3 = gaussian(frame3.copy(), 9, plot=False)
    # frame4 = laplacian(frame2)

    a = pixel_count(frame3)
    b = pixel_count(frame4)
    # print('a',a,'\nb',b)

    ratio_full = (a / b) * 100
    if ratio_full >= 80:
        print('ratio_full', ratio_full, '%')
Пример #7
0
                 "Fig0512(b)(ckt-uniform-plus-saltpepr-prob-pt1).tif")
img2 = skimage.img_as_float(img2)

f, axs = plt.subplots(2, 3, figsize=(12, 9))
disable_tick(axs)

axs[0, 0].imshow(img1, cmap="gray")
axs[0, 0].set_title("uniform noise")

axs[0, 1].imshow(img2, cmap="gray")
axs[0, 1].set_title("add salt & pepper noise")

img3 = F.arithmetic_mean_filter(img2, 5, 5)
axs[0, 2].imshow(img3, cmap="gray")
axs[0, 2].set_title("arithmetic mean filter")

img4 = F.geometric_mean_filter(img2, 5, 5)
axs[1, 0].imshow(img4, cmap="gray")
axs[1, 0].set_title("geometric mean filter")

img5 = F.median_filter(img2, 5, 5)
axs[1, 1].imshow(img5, cmap="gray")
axs[1, 1].set_title("median filter")

img6 = F.alpha_trimmed_filter(img2, 5, 5, 5)
axs[1, 2].imshow(img6, cmap="gray")
axs[1, 2].set_title("alpha trimmed filter")

plt.savefig("output/" + sys.argv[0][:-2] + "png")
plt.show()
Пример #8
0
def process(img, controls, camera, debug):
    global rgb_window_active, hsv_window_active

    profile = controls.profile

    FRAME_WIDTH = camera.FRAME_WIDTH
    FRAME_HEIGHT = camera.FRAME_HEIGHT

    img = filters.resize(img, camera.FRAME_WIDTH, camera.FRAME_HEIGHT)

    original_img = img

    rgb_mask = filters.rgb_threshold(img, profile)
    if controls.show_rgb_mask:
        cv2.imshow("rgb mask", rgb_mask)
        rgb_window_active = True
    elif rgb_window_active:
        cv2.destroyWindow('rgb mask')
        rgb_window_active = False

    img = filters.apply_mask(img, rgb_mask)

    img = filters.hsv_threshold(img, profile)
    if controls.show_hsv_mask:
        cv2.imshow("hsv mask", img)
        hsv_window_active = True
    elif hsv_window_active:
        cv2.destroyWindow('hsv mask')
        hsv_window_active = False

    img = filters.median_filter(img)
    if debug:
        cv2.imshow('median filter', img)

    _, contours, hierarchy = cv2.findContours(img, cv2.RETR_EXTERNAL,
                                              cv2.CHAIN_APPROX_SIMPLE)

    contour_list = []
    for (index, contour) in enumerate(contours):

        area = cv2.contourArea(contour)
        # peri = cv2.arcLength(contour, True)
        # approx = cv2.approxPolyDP(contour, 0.04 * peri, True)

        #
        # limit the number of contours to process
        #
        if area > MIN_SQUARE_AREA:
            contour_list.append(contour)

            color = colors.random()

            x, y, w, h = cv2.boundingRect(contour)

            #
            # if it is a cube, then outbound rectangle should be close to a square
            #
            if is_not_square(w, h):
                cv2.rectangle(original_img, (x, y), (x + w, y + h),
                              colors.WHITE, 2)
                continue

            cv2.rectangle(original_img, (x, y), (x + w, y + h), colors.GREEN,
                          2)
            #
            # print 'square: %s,%s' % (w,h)
            # print w/h, h/w

            center_mass_x = x + w / 2
            center_mass_y = y + h / 2

            angle = get_angle(camera, center_mass_x, center_mass_y)
            distance = get_distance(w, CUBE_LENGTH, camera.FOCAL_LENGTH)

            # print 'x:%s, y:%s angle:%s ' % ( center_mass_x, center_mass_y, angle )

            cv2.drawContours(original_img, contours, index, color, 2)
            cv2.circle(original_img, (center_mass_x, center_mass_y), 5, color,
                       -1)
            cv2.line(original_img, (FRAME_WIDTH / 2, FRAME_HEIGHT),
                     (center_mass_x, center_mass_y), color, 2)

            font = cv2.FONT_HERSHEY_DUPLEX

            coordinate_text = 'x:%s y:%s ' % (center_mass_x, center_mass_y)
            area_text = 'area:%s width:%s' % (area, w)
            angle_text = 'angle:%.2f  distance:%s' % (angle, distance)

            cv2.putText(original_img, coordinate_text, (x, y - 35), font, .4,
                        colors.WHITE, 1, cv2.LINE_AA)
            cv2.putText(original_img, area_text, (x, y - 20), font, .4,
                        colors.WHITE, 1, cv2.LINE_AA)
            cv2.putText(original_img, angle_text, (x, y - 5), font, .4,
                        colors.WHITE, 1, cv2.LINE_AA)

    # create a line for the center of frame
    cv2.line(original_img, (FRAME_WIDTH / 2, FRAME_HEIGHT),
             (FRAME_WIDTH / 2, 0), colors.WHITE, 4)

    return original_img
Пример #9
0
def task_2():
    img = Image.open('./task_2.png').convert('L')

    # 高斯噪声实验
    noise_generator.Gaussian_noise(img, 0, 40).save(
        './output/task_2/p1/add_Gaussian_noise.png')
    img1 = Image.open('./output/task_2/p1/add_Gaussian_noise.png').convert('L')
    # 算术均值
    filters.arithmetic_mean_filter(img1, (3, 3)).save(
        './output/task_2/p1/算术平均3x3.png')
    filters.arithmetic_mean_filter(img1, (5, 5)).save(
        './output/task_2/p1/算术平均5x5.png')
    filters.arithmetic_mean_filter(img1, (7, 7)).save(
        './output/task_2/p1/算术平均7x7.png')
    filters.arithmetic_mean_filter(img1, (9, 9)).save(
        './output/task_2/p1/算术平均9x9.png')
    # 几何均值
    filters.geometric_mean_filter(img1, (3, 3)).save(
        './output/task_2/p1/几何平均3x3.png')
    filters.geometric_mean_filter(img1, (5, 5)).save(
        './output/task_2/p1/几何平均5x5.png')
    # 中值滤波
    filters.median_filter(img1, (3, 3)).save(
        './output/task_2/p1/中值滤波3x3.png')
    filters.median_filter(img1, (5, 5)).save(
        './output/task_2/p1/中值滤波5x5.png')

    # 盐噪声实验
    noise_generator.Salt_and_pepper_noise(img, ps=0.2, pp=0).save(
        './output/task_2/p2/add_Salt_noise.png')
    img2 = Image.open('./output/task_2/p2/add_Salt_noise.png')
    # 调和均值处理
    filters.harmonic_mean_filter(img2, (3, 3)).save(
        './output/task_2/p2/调和均值3x3.png')
    filters.harmonic_mean_filter(img2, (5, 5)).save(
        './output/task_2/p2/调和均值5x5.png')

    # 逆谐波均值处理 Q > 0
    filters.contra_harmonic_mean_filter(img2, (3, 3), Q=1.5).save(
        './output/task_2/p2/逆谐波均值3x3q1.5.png')

    # 逆谐波均值处理 Q < 0
    filters.contra_harmonic_mean_filter(img2, (3, 3), Q=-1.5).save(
        './output/task_2/p2/逆谐波均值3x3q-1.5.png')
    filters.contra_harmonic_mean_filter(img2, (3, 3), Q=-2).save(
        './output/task_2/p2/逆谐波均值3x3q-2.0.png')
    filters.contra_harmonic_mean_filter(img2, (3, 3), Q=-2.5).save(
        './output/task_2/p2/逆谐波均值3x3q-2.5.png')

    # 椒盐噪声实验
    noise_generator.Salt_and_pepper_noise(img, ps=0.2, pp=0.2).save(
        './output/task_2/p3/add_Salt_and_pepper_noise.png')
    img3 = Image.open('./output/task_2/p3/add_Salt_and_pepper_noise.png')
    # 算术均值
    filters.arithmetic_mean_filter(img3, (3, 3)).save(
        './output/task_2/p3/算术平均3x3.png')
    filters.arithmetic_mean_filter(img3, (5, 5)).save(
        './output/task_2/p3/算术平均5x5.png')
    # 几何均值
    filters.geometric_mean_filter(img3, (3, 3)).save(
        './output/task_2/p3/几何平均3x3.png')
    filters.geometric_mean_filter(img3, (5, 5)).save(
        './output/task_2/p3/几何平均5x5.png')
    # 最大值滤波
    filters.max_filter(img3, (3, 3)).save(
        './output/task_2/p3/最大值滤波3x3.png')
    filters.max_filter(img3, (5, 5)).save(
        './output/task_2/p3/最大值滤波5x5.png')

    # 最小值滤波
    filters.min_filter(img3, (3, 3)).save(
        './output/task_2/p3/最小值滤波3x3.png')
    filters.min_filter(img3, (5, 5)).save(
        './output/task_2/p3/最小值滤波5x5.png')

    # 中值滤波
    filters.median_filter(img3, (3, 3)).save(
        './output/task_2/p3/中值滤波3x3.png')
    filters.median_filter(img3, (5, 5)).save(
        './output/task_2/p3/中值滤波5x5.png')
def disable_tick(axs):
    for u in range(len(axs)):
        axs[u].axes.get_xaxis().set_ticks([])
        axs[u].axes.get_yaxis().set_ticks([])

img1 = io.imread("input/"+"Fig0514(a)(ckt_saltpep_prob_pt25).tif")
img1 = skimage.img_as_float(img1)


f,axs = plt.subplots(1,3,figsize=(12,9))
disable_tick(axs)

axs[0].imshow(img1,cmap="gray")
axs[0].set_title("salt & pepper noise")

img2 = F.median_filter(img1,7,7)
axs[1].imshow(img2,cmap="gray")
axs[1].set_title("median filter 7x7")


img3 = F.adaptive_median_filter(img1,3)
axs[2].imshow(img3,cmap="gray")
axs[2].set_title("adaptive median filter")



plt.savefig("output/"+sys.argv[0][:-2]+"png")
plt.show()

Пример #11
0
    def setUp(self):
        self.res = []
        transducer = compose(range_filter(START, END), median_filter(N, D))

        self.target = reactive_transduce(transducer=transducer,
                                         target=list_builder(self.res))
Пример #12
0
 def setUp(self):
     self.res = []
     transducer = median_filter(N, D)
     self.target = reactive_transduce(transducer=transducer,
                                      target=list_builder(self.res))
Пример #13
0
    for u in range(len(axs)):
        for v in range(len(axs[0])):
            axs[u, v].axes.get_xaxis().set_ticks([])
            axs[u, v].axes.get_yaxis().set_ticks([])


img1 = io.imread("input/" + "Fig0510(a)(ckt-board-saltpep-prob.pt05).tif")
img1 = skimage.img_as_float(img1)

f, axs = plt.subplots(2, 3, figsize=(12, 9))
disable_tick(axs)

axs[0, 0].imshow(img1, cmap="gray")
axs[0, 0].set_title("salt & pepper noise p=0.1")

img2 = F.median_filter(img1, 3, 3)
axs[0, 1].imshow(img2, cmap="gray")
axs[0, 1].set_title("median filter 1 times")

img3 = F.median_filter(img2, 3, 3)
axs[0, 2].imshow(img3, cmap="gray")
axs[0, 2].set_title("median filter 2 times")

img4 = F.median_filter(img1, 3, 3)
axs[1, 0].imshow(img4, cmap="gray")
axs[1, 0].set_title("median filter 3 times")

img5 = io.imread("input/Fig0508(a)(circuit-board-pepper-prob-pt1).tif")
img5 = F.max_filter(img5, 3, 3)
axs[1, 1].imshow(img5, cmap="gray")
axs[1, 1].set_title("max filter")