我正在尝试消除图像中的噪点,如果满足某些条件,我会尝试制作白色像素,但是我正在努力做到这一点。
这是我的图像,我想删除所有灰色线条,只希望使用高强度颜色,例如蓝红色和绿色 。 抱歉,我的编辑
这是我尝试检查成功条件的代码,然后将像素更改为白色
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()
答案 0 :(得分:2)
我尝试过不透明,它对我有用。然后我有使用内核。这个答案的一个问题是,它花费了更多时间。请让我知道他们是否有更好的方法
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()
答案 1 :(得分:0)