import numpy as np # Функция для создания изображения цифры def create_digit_image(digit): image = np.zeros((5, 3)) image[0:5, 0:3] = 1 if digit == 0: image[0:5, 0] = 0 image[0:5, 2] = 0 image[0, 0:3] = 0 image[4, 0:3] = 0 elif digit == 1: image[0:5, 2] = 0 image[1, 1] = 0 elif digit == 2: image[0, 0:3] = 0 image[1, 2] = 0 image[2, 1] = 0 image[3, 0] = 0 image[4, 0:3] = 0 elif digit == 3: image[0, 0:3] = 0 image[0:5, 2] = 0 image[2, 1] = 0 image[4, 0:3] = 0 elif digit == 4: image[0:3, 0] = 0 image[0:5, 2] = 0 image[2, 0:3] = 0 elif digit == 5: image[0, 0:3] = 0 image[2, 0:3] = 0 image[4, 0:3] = 0 image[1, 0] = 0 image[3, 2] = 0 elif digit == 6: image[0, 0:3] = 0 image[2, 0:3] = 0 image[4, 0:3] = 0 image[0:5, 0] = 0 image[3, 2] = 0 elif digit == 7: image[0, 0:3] = 0 image[1, 2] = 0 image[2, 1] = 0 image[3, 0] = 0 image[4, 0] = 0 elif digit == 8: image[0:5, 0] = 0 image[0:5, 2] = 0 image[0, 1] = 0 image[2, 1] = 0 image[4, 1] = 0 elif digit == 9: image[0, 0:3] = 0 image[2, 0:3] = 0 image[4, 0:3] = 0 image[0:5, 2] = 0 image[1, 0] = 0 return image # Функция для добавления повреждений def add_noise(image, noise_level=0.1): noisy_image = image.copy() x = np.random.randint(0, 5) y = np.random.randint(0, 3) noisy_image[x, y] = 1 return noisy_image