我正在尝试从最小像素之间的均匀分布中添加随机噪声原始图像每个通道的每个像素的最大像素值的最大值和0.1倍。
我的图片
[到目前为止是我的代码:
[[in]:
import numpy as np
import matplotlib.pyplot as plt
import imageio
# Read image
image = imageio.imread("cat.jpg")
# Display image
imshow(image)
# Slice an image into red, green and blue channels
# Red
image_R = image.copy() # Duplicate image
image_R[:, :, 1] = 0 # Zero out contribution from green
image_R[:, :, 2] = 0 # Zero out contribution from blue
# turn image into numpy array
image_R = np.asarray(image_R)
# Blue
image_B = image.copy() # Duplicate image
image_B[:, :, 1] = 0 # Zero out contribution from green
image_B[:, :, 0] = 0 # Zero out contribution from red
# turn image into numpy array
image_B = np.asarray(image_B)
# Green
image_G = image.copy() # Duplicate image
image_G[:, :, 2] = 0 # Zero out contribution from blue
image_G[:, :, 0] = 0 # Zero out contribution from red
# turn image into numpy array
image_G = np.asarray(image_G)
# Get maximum and minimum pixel values in the image
# Red
R_min = image_R.min()
R_max = image_R.max()
# Blue
B_min = image_B.min()
B_max = image_B.max()
# Green
G_min = image_G.min()
G_max = image_G.max()
# create random noise
noise_R = np.random.uniform(R_min,R_max*0.3, image_G.size)
# reshape noise_R
noise_R.shape = (256,256,3)
noise_G = np.random.uniform(B_min,B_max*0.1, image_B.size)
# reshape G
noise_G.shape = (256,256,3)
noise_B = np.random.uniform(G_min, G_max*0.1, image_R.size)
# reshape B
noise_B.shape = (256,256,3)
# Add noise to image
noisy_image = (image + noise_R + noise_G + noise_B).astype(np.uint8)
imshow(noisy_image)
<<这是我在图像处理中的第一次尝试,代码和输出看起来正确吗?我应该更改什么或做错什么吗?[out]:
我正在尝试为原始图像的每个通道的每个像素,从最小像素值和最大像素值的0.1倍之间的均匀分布中添加随机噪声。我的图片这是我的代码,所以...