<<< CornerDetector >>> RANDOMANSWER = np.array([[1, 2], [3, 4], [6, 9]]) COEFFSKERNEL =…
- User
<<< CornerDetector >>>
RANDOM_ANSWER = np.array([[1, 2], [3, 4], [6, 9]]) COEFFS_KERNEL = np.array( [[1, 1, 1, 1, 1], [1, 5, 5, 5, 1], [1, 5, 0, 5, 1], [1, 5, 5, 5, 1], [1, 1, 1, 1, 1]] )
noise 0.0-0.2
POTENTIAL_POINTS_NUM_0_2 = 200 ITERATIONS_NUM_0_2 = 1000 IMAGE_THRESHOLD_0_2 = 0 THRESHOLD_DISTANCE_0_2 = 1 THRESHOLD_K_0_2 = 0.5 THRESHOLD_B_0_2 = 20 NOISE_LESS_0_2 = 100 KERNEL_SIZE_0_2 = 3
noise 0.3-0.5
POTENTIAL_POINTS_NUM_3_5 = 200 ITERATIONS_NUM_3_5 = 1000 IMAGE_THRESHOLD_3_5 = 100 THRESHOLD_DISTANCE_3_5 = 1 THRESHOLD_K_3_5 = 0.5 THRESHOLD_B_3_5 = 20 NOISE_LESS_3_5 = 75 KERNEL_SIZE_3_5 = 3
<<< TimerService >>>
TIME_MAX = 1.95
class TimeService: """Service for time management.""" def init(self, time_max: float): self.time_max = time_max self.start_time = None
codedef start_timer(self) -> None: """Start time point. Sets 'self.start_time'.""" self.start_time = time.time() def check_timer(self): """Checks if time more than 'self.time_max'.""" end_time = time.time() delta_time = end_time - self.start_time if delta_time > self.time_max: return False return delta_timeclass CornerDetector(object): """Class for corner detection on image.""" def init( self, ): self.__potential_points_num = None self.__iterations_num = None self.__image_threshold = None self.__threshold_k = None self.__threshold_b = None self.__threshold_distance = None self.__need_coeffs_kernel = None self.__image = None self.__kernel_size = 3 self.__time_service = TimeService(TIME_MAX) self.__need_time_check = False self.random_answer = RANDOM_ANSWER
code - Assistant
import matplotlib.pyplot as plt
image = cv2.imread("0.6/00.pgm", cv2.COLOR_BGR2GRAY) detector = CornerDetector() detector.set_potential_points_num(POTENTIAL_POINTS_NUM_6) detector.set_iterations_num(ITERATIONS_NUM_6) detector.set_image_threshold(IMAGE_THRESHOLD_6) detector.set_threshold_distance(THRESHOLD_DISTANCE_6) detector.set_threshold_k(THRESHOLD_K_6) detector.set_threshold_b(THRESHOLD_B_6) detector.set_need_time_check(False) detector.set_need_coeffs_kernel(False) detector.set_kernel_size(KERNEL_SIZE_6)
corners = detector.find_corners(image)
potential_points = detector.get_potential_points_coords() best_lines = detector.get_best_lines()
plt.imshow(image, cmap='gray') plt.scatter(potential_points[:, 1], potential_points[:, 0], c='red') for line in best_lines: x = np.arange(image.shape[1]) y = line[0] * x + line[1] plt.plot(x, y, c='blue') plt.show()
- User
numpy алгоритм убирающий шум с изображния
- Assistant
Для удаления шума с изображения можно использовать различные алгоритмы фильтрации изображений в библиотеке NumPy. Один из таких алгоритмов - это медианный фильтр.
Медианный фильтр заменяет каждый пиксель в изображении на медианное значение яркости пикселей в его окрестности. Это позволяет убрать шум, сохраняя при этом края и детали изображения.
Вот пример кода на NumPy, который показывает, как можно применить медианный фильтр для удаления шума с изображения:
python