DISK提取网络的鲁棒性分析
原始图像提取特征
均值滤波
1.对少量图片作均值滤波处理
import cv2
import os
data_path = '/home/julia/test_images'
save_path = '/home/julia/images_gauss'
if not os.path.exists(save_path):
os.mkdir(save_path)
img_list = os.listdir(data_path)
for i in range(len(img_list)):
print(i)
img_path = os.path.join(data_path, img_list[i])
image = cv2.imread(img_path, cv2.IMREAD_COLOR)
# gaussian
image = cv2.blur(image, (5, 5))
cv2.imwrite(save_path+'/'+str(i+1)+'.jpg', image)
2.运行detect.py
python detect.py h5_artifacts_destination /home/julia/images_gauss --height=1680 --width=1280
3.运行view.py
python view_h5.py h5_artifacts_destination /home/julia/images_gauss keypoints
4.查看提取结果
5.结论
点的提取没有原图密集,但鲁棒性增强
光照
1.对少量图片作中心光照处理
import cv2
import os
import math
import numpy as np
data_path = '/home/julia/test_images'
save_path = '/home/julia/images_light'
if not os.path.exists(save_path):
os.mkdir(save_path)
img_list = os.listdir(data_path)
for i in range(len(img_list)):
print(i)
img_path = os.path.join(data_path, img_list[i])
image = cv2.imread(img_path, cv2.IMREAD_COLOR)
# light
# 获取图像行和列
rows, cols = image.shape[:2]
# 设置中心点
centerX = rows / 2
centerY = cols / 2
radius = min(centerX, centerY)
# 设置光照强度
strength = 200
# 图像光照特效
for i in range(rows):
for j in range(cols):
# 计算当前点到光照中心距离(平面坐标系中两点之间的距离)
distance = math.pow((centerY - j), 2) + math.pow((centerX - i), 2)
# 获取原始图像
B = image[i, j][0]
G = image[i, j][1]
R = image[i, j][2]
if (distance < radius * radius):
# 按照距离大小计算增强的光照值
result = (int)(strength * (1.0 - math.sqrt(distance) / radius))
B = image[i, j][0] + result
G = image[i, j][1] + result
R = image[i, j][2] + result
# 判断边界 防止越界
B = min(255, max(0, B))
G = min(255, max(0, G))
R = min(255, max(0, R))
image[i, j] = np.uint8((B, G, R))
else:
image[i, j] = np.uint8((B, G, R))
cv2.imwrite(save_path+'/'+str(i+1)+'.jpg', image)
2.运行detect.py
python detect.py h5_artifacts_destination /home/julia/images_light --height=1680 --width=1280
3.运行view.py
python view_h5.py h5_artifacts_destination /home/julia/images_light keypoints
4.查看提取结果
5.结论
过强的光照导致图片失真,也会导致提取网络性能降低
高斯噪声
1.对少量图片作高斯噪声处理
import numpy as np
import cv2
import os
# add gauss_noise to image
def gasuss_noise(image, mean=0, var=0.005):
# change image to array
image = np.array(image/255, dtype=float)
# creat noise
noise = np.random.normal(mean, pow(var, 0.5), image.shape)
# use noise
out = image + noise
if out.min() < 0:
low_clip = -1
else:
low_clip = 0
out = np.clip(out, low_clip, 1.0)
out = np.uint8(out*255)
return out
old_path = '/home/julia/images_test'
new_path = '/home/julia/images_gaussloss'
# if not exist make dir
if not os.path.exists(new_path):
os.mkdir(new_path)
# get the image list
img_list = os.listdir(old_path)
for i in range(len(img_list)):
print(i)
# get the path of every image
old_image_path = os.path.join(old_path, img_list[i])
img = cv2.imread(old_image_path, cv2.IMREAD_UNCHANGED)
rows, cols, dims = img.shape
img = gasuss_noise(img)
# save the new image
new_image_path = os.path.join(new_path, img_list[i])
cv2.imwrite(new_image_path, img, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
2.运行detect.py
python detect.py h5_artifacts_destination /home/julia/images_gaussloss --height=1680 --width=1280
3.运行view.py
python view_h5.py h5_artifacts_destination /home/julia/images_gaussloss keypoints
4.查看提取结果
5.结论
提取网络不能很好地处理带高斯噪声的图片
椒盐噪声
1.对少量图片作椒盐噪声处理
import numpy as np
import cv2
import os
# add sp_noise to image
def sp_noise(img, rows, cols):
# creat white point
for j in range(10000):
x = np.random.randint(0, rows)
y = np.random.randint(0, cols)
img[x, y, :] = 255
# creat black point
for k in range(10000):
x = np.random.randint(0, rows)
y = np.random.randint(0, cols)
img[x, y, :] = 0
return img
old_path = '/home/julia/images_test'
new_path = '/home/julia/images_gaussloss'
# if not exist make dir
if not os.path.exists(new_path):
os.mkdir(new_path)
# get the image list
img_list = os.listdir(old_path)
for i in range(len(img_list)):
print(i)
# get the path of every image
old_image_path = os.path.join(old_path, img_list[i])
img = cv2.imread(old_image_path, cv2.IMREAD_UNCHANGED)
rows, cols, dims = img.shape
img = sp_noise(img, rows, cols)
# save the new image
new_image_path = os.path.join(new_path, img_list[i])
cv2.imwrite(new_image_path, img, [int(cv2.IMWRITE_JPEG_QUALITY), 100])
2.运行detect.py
python detect.py h5_artifacts_destination /home/julia/images_sploss --height=1680 --width=1280
3.运行view.py
python view_h5.py h5_artifacts_destination /home/julia/images_sploss keypoints
4.查看提取结果
5.结论
提取网络不能很好地处理带椒盐噪声的图片