我一直致力于图像分割和计算灰度图像的方向导数,目的是检测轮廓和边缘。我已经意识到,如果我在计算方向导数之前应用高斯滤波器,边缘会得到更好的增强。所以我的问题是——为什么会这样?
这是原始图像:
这是对图像应用高斯滤波后的导数,sigma = 6:
*******计算导数的Python代码
with rio.open("vein_template.tif", 'r') as ds:
RGB_arr = ds.read(masked=True) # read all raster values
rgb_1 = np.rot90(np.transpose(RGB_arr, [1, 2, 0]))
#the rgb image contains 4 channels, so I'm changing their order, and making the image upright
%matplotlib
plt.imshow(rgb_1)
# Transform to grey-level img
gsi = 0.2989 * rgb_1[:, :, 0] + 0.5870 * rgb_1[:, :, 1] + 0.1140 * rgb_1[:, :, 2]
plt.imshow(gsi, cmap = "gist_gray")
#compute derivatives
dx = np.diff(gsi, axis = 0)
dy = np.diff(gsi, axis = 1)
f = plt.figure()
f.add_subplot(1, 2, 1)
plt.imshow(dx, cmap = "Greys")
plt.title("dx")
f.add_subplot(1, 2, 2)
plt.imshow(dy, cmap = "Greys")
plt.title("dy")