Выполнение задания по обработке изображений с использованием Python и Google Colab [закрыто]Python

Программы на Python
Anonymous
 Выполнение задания по обработке изображений с использованием Python и Google Colab [закрыто]

Сообщение Anonymous »

Первая часть задания — перевернуть изображение моего лица, отредактировать его в оттенках серого, а затем отдельно добавить четкие, остроумные и хитрые края. Я написал код, и он работает, но мне хотелось бы получить любую информацию, которую можно было бы очистить/улучшить, поскольку это моя первая попытка кодирования.
import skimage.io as io
from skimage.io import imread
import skimage.color as color
import skimage.transform as transform
import skimage.util as util
import skimage.filters as filters
import skimage.feature as feature
import numpy as np
import matplotlib.pyplot as plt

# First, load the image and resize it to 512 by 512 pixels, then convert it to grayscale

input_img = io.imread("My_picture.JPG")
img_resized = transform.resize(input_img, (512, 512), anti_aliasing=True)
grayscale_img = color.rgb2gray(img_resized)

# Next, calculate some basic stats: the minimum, maximum, and average pixel values

min_pixel_value = np.min(grayscale_img)
max_pixel_value = np.max(grayscale_img)
mean_pixel_value = np.mean(grayscale_img)
print(f"Min={min_pixel_value:.4f}, Max={max_pixel_value:.4f}, Average={mean_pixel_value:.4f}")

# Now, let's add some Gaussian noise with a variance of 0.04 to the grayscale image

noisy_img = util.random_noise(grayscale_img, mode='gaussian', var=0.04)

# Then apply three different edge detection filters—Sobel, Prewitt, and Canny—to the noisy image

sobel_edges = filters.sobel(noisy_img)
prewitt_edges = filters.prewitt(noisy_img)
canny_edges = feature.canny(noisy_img, sigma=1.5)

# Finally, display the original grayscale and edge-detected images side by side for comparison

fig, axes = plt.subplots(1, 4, figsize=(12, 3))
titles = ['Grayscale Image', 'Sobel Image', 'Prewitt Image', 'Canny Image']
images = [grayscale_img, sobel_edges, prewitt_edges, canny_edges]

for axes, image, title in zip(axes, images, titles):
axes.imshow(image, cmap='gray')
axes.set_title(title)
axes.axis('off')

plt.tight_layout()
plt.show()


Подробнее здесь: https://stackoverflow.com/questions/798 ... ogle-colab

Вернуться в «Python»