如果你的代码莫问题的话应该是图片对比度太低的原因。换一些高对比度的图片就行。下面是我查到的解释:
模糊
滤镜会模糊图像,如果原始图像的对比度较低,则会导致颜色均匀(白色或黑色)。浮雕
滤镜会产生浮雕效果,这也会导致颜色均匀(高光和阴影)。运动
滤镜模拟运动模糊,进一步降低对比度并创建均匀的区域。- 锐化 滤镜增强了边缘,但如果原始图像的边缘对比度较低,则可能不会显示明显变化。
如果原始图像具有均匀的区域或低对比度,则过滤后的结果可能显示为纯色(白色或黑色)。为了提高可视化效果,请考虑使用内容更多样化、对比度更高的图像。
指定的边界处理方法(“复制”)将用于检测水平边缘的 Sobel 过滤器应用于输入灰度图像 p
。生成的过滤图像存储在 imgx
中。
Just changed the pictures!
这里随手附上代码:
clear,clc,close all;
% path1='D:\pictures\image\112.jpg';
% path2='D:\pictures\image\111.jpg';
path1='D:\pictures\image\99.png';
path2='D:\pictures\image\98.png';
p1=imread(path1);
p2=imread(path2);
% pp1=sobelp(p1);
% pp2=sobelp(p2);
% figure;
% subplot(2,3,1);imshow(p1);title('原图');
% subplot(2,3,2);imshow(p2);title('原图');
% subplot(2,3,4);imshow(pp1);title('处理图');
% subplot(2,3,5);imshow(pp2);title('处理图');
mp1=mohu(p1);
mp2=mohu(p2);
fp1=fudiao(p1);
fp2=fudiao(p2);
yp1=yundong(p1);
yp2=yundong(p2);
rp1=ruihua(p1);
rp2=ruihua(p2);
figure;
subplot(2,4,1);imshow(mp1);title('模糊');
subplot(2,4,2);imshow(fp1);title('浮雕');
subplot(2,4,3);imshow(yp1);title('运动');
subplot(2,4,4);imshow(rp1);title('锐化');
subplot(2,4,5);imshow(mp2);title('模糊');
subplot(2,4,6);imshow(fp2);title('浮雕');
subplot(2,4,7);imshow(yp2);title('运动');
subplot(2,4,8);imshow(rp2);title('锐化');
% function img=sobelp(p)
% sobel_x = [-1 0 1; -2 0 2; -1 0 1]; % 水平方向
% sobel_y = [-1 -2 -1; 0 0 0; 1 2 1]; % 垂直方向
% sobel_yx = [0 -1 1; -2 0 2; -1 1 0]; % y=x方向
% sobel_xy = [-1 -2 0; -1 0 1; 0 2 1]; % y=-x方向
% imgx = imfilter(p, sobel_x, 'replicate');
% imgy = imfilter(p, sobel_y, 'replicate');
% imgxy = imfilter(p, sobel_xy, 'replicate');
% imgyx = imfilter(p, sobel_yx, 'replicate');
% % 合并四个方向的结果
% img = imgx + imgy+imgxy+imgyx;
% end
function img=mohu(p)
sob=[0 0 1 0 0;
0 1 1 1 0 ;
1 1 1 1 1 ;
0 1 1 1 0;
0 0 1 0 0];
img=imfilter(p,sob,'replicate');
end
function img=fudiao(p)
sob=[-1 -1 0;
-1 0 -1;
0 -1 -1];
img=imfilter(p,sob,'replicate');
end
function img=yundong(p)
sob=[1 0 0 0 0 0 0 0 ;
0 1 0 0 0 0 0 0 ;
0 0 1 0 0 0 0 0 ;
0 0 0 1 0 0 0 0 ;
0 0 0 0 1 0 0 0 ;
0 0 0 0 0 1 0 0 ;
0 0 0 0 0 0 1 0 ;
0 0 0 0 0 0 0 1
];
img=imfilter(p,sob,'replicate');
end
function img=ruihua(p)
sob=[-1 -1 -1 ;
-1 9 -1 ;
-1 -1 -1];
img=imfilter(p,sob,'replicate');
end