bw_im=imread('Electronic.jpg');
imshow(bw_im);
bw=imread('Electronic.jpg');
se = strel('line',11,90);
BW2 = imdilate(bw,se);
imshow(BW2);
bw=imread('Electronic.jpg');
se = strel('line',11,90);
BW2 = imerode(bw,se);
imshow(BW2);
bw=imread('Electronic.jpg');
se = strel('disk',5);
BW2 = imopen(bw,se);
imshow(BW2);
bw=imread('Electronic.jpg');
se = strel('disk',15);
BW2 = imclose(bw,se);
imshow(BW2);
disk,5;disk,15
bw=imread('Electronic.jpg');
se = strel('disk',5);
se2 = strel('disk',15);
BW1 = imerode(bw,se);
BW2 = imerode(bw,se2);
subplot(1,3,1);imshow(bw);title('Electronic.jpg');
subplot(1,3,2);imshow(BW1);title('disk,5');
subplot(1,3,3);imshow(BW2);title('disk,15');
disk ,1
bw=imread('Text.jpg');
bw2=im2bw(bw,0.3);
se = strel('disk',1);
BW1 = imdilate(bw2,se);
subplot(1,2,1);imshow(bw2);title('Text.jpg');
subplot(1,2,2);imshow(BW1);title('disk,1');
disk,10
bw=imread('Bubble.jpg');
se = strel('disk',10);
BW1 = imopen(bw,se);
subplot(1,2,1);imshow(bw);title('Bubble.jpg');
subplot(1,2,2);imshow(BW1);title('disk,10');
square,3;square,7
bw=imread('stamper.jpg');
bw2=im2bw(bw,0.3);
se = strel('square',3);
se2 = strel('square',7);
BW1 = imclose(bw2,se);
BW2 = imclose(bw2,se2);
subplot(1,3,1);imshow(bw2);title('stamper.jpg');
subplot(1,3,2);imshow(BW1);title('square,3');
subplot(1,3,3);imshow(BW2);title('square,7');
自定义r
bw=imread('circle.jpg');%二值化
bw2=im2bw(bw,0.4);%定义结构元素
se = strel('disk',15,0);%膨胀操作
BW1 = imdilate(bw2,se);%出图
subplot(1,2,1);imshow(bw2);title('circle.jpg');
subplot(1,2,2);imshow(BW1);title('disk,15');
经过半径为r/4的圆形结构元素的膨胀处理后,圆的半径增大
bw=imread('cameraman.jpg');
bw2=imnoise(bw,'salt & pepper',0.05); %定义结构元素
se = strel('disk',1);
se2 = strel('disk',1);
%闭运算
BW1 = imclose(bw2,se);
%腐蚀运算
BW2 = imerode(BW1,se2);
%出图
subplot(1,2,1);imshow(bw2);title('cameraman.jpg');
subplot(1,2,2);imshow(BW2);title('处理后');
bw=imread('cameraman.jpg');
bw2=imnoise(bw,'salt & pepper',0.05); %中值滤波处理
G=med(bw2,3);%出图
subplot(1,2,1);imshow(bw2);title('cameraman.jpg');
subplot(1,2,2);imshow(G);title('中值滤波处理后');
function G=med(F,k)
[m,n]=size(F);
G=uint16(zeros(m,n));Ft=uint16(F);M=uint16(ones(k,k));
h=(k+1)/2;
for i=1:m
for j=1:n
if((im-h+1)||(j>n-h+1))
G(i,j)=Ft(i,j);continue;
end
T=Ft(i-(k-1)/2:i+(k-1)/2,j-(k-1)/2:j+(k-1)/2);
T=T.*M;
T=T(:);
G(i,j)=median(T);
end
end
腐蚀和闭运算因为使用了腐蚀,部分白色像素会过渡腐蚀,因此造成去噪结果会有呈现边缘不清晰的状态。而中值滤波是通过模板内取中值来代替,因而不会呈现这种特点。
代码文件可以从主页发布里面找
万水千山都是情,路过点个赞行不行!
希望看见的都可以帮忙点个赞!拜托了!
觉得还可以的动动手指帮忙点个赞!呜呜~