首页 > 代码库 > PS 滤镜——染色玻璃
PS 滤镜——染色玻璃
%%%% 完成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);
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);
原图:
效果图:
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。