%%%% 完成PS 中的染色玻璃滤镜特效
clc;
clear all;
close all;
Image=imread(‘4.jpg‘);
Image=double(Image);
Gray_Image=rgb2gray(Image/255);
[row,col]=size(Gray_Image);
S_filter=fspecial(‘sobel‘);
G=sqrt(imfilter(Gray_Image, S_filter, ‘replicate‘).^2+...
imfilter(Gray_Image, S_filter, ‘replicate‘).^2);
% % % % 利用形态学细化分割图像
%%%% 形态学中的结构算子的大小,决定了分割的块的大小
Block_Size=8;
G2=imclose(imopen(G,ones(Block_Size,Block_Size)), ones(Block_Size,Block_Size));
L=watershed(G2);
wr=L==0;
figure, imshow(wr);
Label_num=bwlabel(1-wr,4);
%%% figure, imshow(Label_num);
length=max(Label_num(:));
Color_array(1:length,1:3)=1000;
for i=1:row
for j=1:col
Num=Label_num(i,j);
if(Num==0)
Image(i,j,1)=255;
Image(i,j,2)=255;
Image(i,j,3)=255;
else
if(Color_array(Num,1)==1000)
Color_array(Num,1)=Image(i,j,1);
Color_array(Num,2)=Image(i,j,2);
Color_array(Num,3)=Image(i,j,3);
else
Image(i,j,1)=Color_array(Num,1);
Image(i,j,2)=Color_array(Num,2);
Image(i,j,3)=Color_array(Num,3);
end
end
end
end
G_filter=fspecial(‘gaussian‘,6,0.5);
G_image=imfilter(Image, G_filter);
L_filter=[-1 -1 -1; -1 9 -1; -1 -1 -1];
Image=imfilter(G_image, L_filter);
figure, imshow(Image/255);
原图:
效果图: