如何去除 python 中图像的噪点
How to remove noise from image in python
我正在尝试去除图像中的噪点,我正在尝试在满足特定条件时制作白色像素,但我正在努力实现这一目标。
这是我的图像,我想删除所有灰色线条只需要高强度颜色,如蓝红色和绿色
.
抱歉我的编辑
这是我的代码,我在其中尝试检查成功的条件,然后我会将像素更改为白色
height, width = image.shape[0:2]
for i in range(0, height): # looping at python speed...
for j in range(0, width):
# print(image)
if ((image[i][j][1] * 255 == image[i][j][2] * 255 == image[i][j][3] * 255) or (
(image[i][j][0] * 255 == image[i][j][1] * 255) and (
image[i][j][3] * 255 >= 245))):
# print(image[i][j][2] * 255)
image[i][j] = 0
plt.imshow(image)
plt.savefig("filename.png")
plt.show()
虽然这不是最佳做法,但您可以通过用白色像素值 (255) 替换不需要的强度值来实现此目的。
使用skimage
你可以实现如下。
from skimage import io
import numpy as np
img = io.imread('your_image_file.png')
img[(img > 215) & (img < 235)] = 255
可以更改值范围的阈值(从 215 到 235)以获得所需的结果。
这是这段代码的输出。
我试过不透明度,它对我有用。然后我有使用内核。这个答案的一个问题是它需要更多的时间。如果他们有更好的方法,请告诉我
import matplotlib.pyplot as plt
import cv2
import numpy as np
image = plt.imread('../heatmapwms.png')
height, width = image.shape[0:2]
for i in range(0, height):
for j in range(0, width):
if (image[i][j][3] <= .34 or (
(image[i][j][2] * 255 > 170) and (image[i][j][1] * 255 > 150) and (image[i][j][0] * 255 > 150))):
image[i][j] = 0
kernel = np.ones((3, 3), np.float32) / 9
image = cv2.filter2D(image, -1, kernel)
for i in range(0, height):
for j in range(0, width):
if (image[i][j][3] <= .30 or (
(image[i][j][2] * 255 > 170) and (image[i][j][1] * 255 > 150) and (image[i][j][0] * 255 > 150))):
image[i][j] = 0
kernel = np.ones((3, 3), np.float32) / 9
image = cv2.filter2D(image, -1, kernel)
plt.imshow(image)
plt.savefig("filename.png")
plt.show()
我正在尝试去除图像中的噪点,我正在尝试在满足特定条件时制作白色像素,但我正在努力实现这一目标。
这是我的图像,我想删除所有灰色线条只需要高强度颜色,如蓝红色和绿色 . 抱歉我的编辑
这是我的代码,我在其中尝试检查成功的条件,然后我会将像素更改为白色
height, width = image.shape[0:2]
for i in range(0, height): # looping at python speed...
for j in range(0, width):
# print(image)
if ((image[i][j][1] * 255 == image[i][j][2] * 255 == image[i][j][3] * 255) or (
(image[i][j][0] * 255 == image[i][j][1] * 255) and (
image[i][j][3] * 255 >= 245))):
# print(image[i][j][2] * 255)
image[i][j] = 0
plt.imshow(image)
plt.savefig("filename.png")
plt.show()
虽然这不是最佳做法,但您可以通过用白色像素值 (255) 替换不需要的强度值来实现此目的。
使用skimage
你可以实现如下。
from skimage import io
import numpy as np
img = io.imread('your_image_file.png')
img[(img > 215) & (img < 235)] = 255
可以更改值范围的阈值(从 215 到 235)以获得所需的结果。
这是这段代码的输出。
我试过不透明度,它对我有用。然后我有使用内核。这个答案的一个问题是它需要更多的时间。如果他们有更好的方法,请告诉我
import matplotlib.pyplot as plt
import cv2
import numpy as np
image = plt.imread('../heatmapwms.png')
height, width = image.shape[0:2]
for i in range(0, height):
for j in range(0, width):
if (image[i][j][3] <= .34 or (
(image[i][j][2] * 255 > 170) and (image[i][j][1] * 255 > 150) and (image[i][j][0] * 255 > 150))):
image[i][j] = 0
kernel = np.ones((3, 3), np.float32) / 9
image = cv2.filter2D(image, -1, kernel)
for i in range(0, height):
for j in range(0, width):
if (image[i][j][3] <= .30 or (
(image[i][j][2] * 255 > 170) and (image[i][j][1] * 255 > 150) and (image[i][j][0] * 255 > 150))):
image[i][j] = 0
kernel = np.ones((3, 3), np.float32) / 9
image = cv2.filter2D(image, -1, kernel)
plt.imshow(image)
plt.savefig("filename.png")
plt.show()