%{
设置好条纹的宽度和条纹的间隔,建立一个
遮罩层,等间隔的对原图进行等间距的遮罩。
%}
clear,clc;
[filename,pathname] = uigetfile('*.jpg;*.bmp','选择图片','E:\pictures\For_Project\Matlab');
imgaepath = strcat(pathname,filename);
image = imread(imgaepath);
figure,imshow(image);
Image = image;
Image=double(Image);
R=Image(:,:,1);
G=Image(:,:,2);
B=Image(:,:,3);
R_new=R;
G_new=G;
B_new=B;
R_new=(G-B).^3/128;
G_new=(R-B).^3/128;
B_new=(R-G).^3/128;
Image_new(:,:,1)=R_new;
Image_new(:,:,2)=G_new;
Image_new(:,:,3)=B_new;
imshow(Image_new/255);
%{
对图像做高斯滤波,用原图减去高斯滤波后的图,再将差值加上128
%}
clear,clc;
[filename,pathname] = uigetfile('*.jpg;*.bmp','选择图片','E:\pictures\For_Project\Matlab');
imgaepath = strcat(pathname,filename);
image = imread(imgaepath);
figure,imshow(image);
Image = image;
Image=double(Image);
Image1=Image;
% 设置高斯滤波器
Half_size=10;
F_size=2*Half_size+1;
G_Filter=fspecial('gaussian',F_size,F_size/6);
% 做高斯滤波
Image_Filter = imfilter(Image1, G_Filter,'conv');
% 做差值
Image_Diff=Image-Image_Filter;
% 差值加上128
Image_out=Image_Diff+128;
imshow(Image/255);
figure, imshow(Image_out/255);
%{
染色玻璃
%}
clear,clc;
[filename,pathname] = uigetfile('*.jpg;*.bmp','选择图片','E:\pictures\For_Project\Matlab');
imgaepath = strcat(pathname,filename);
image = imread(imgaepath);
figure,imshow(image);
Image = image;
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);
%{
Fragment
对原图做四个方向的平移,然后对平移的结果取平均
碎片效果
%}
clear,clc;
[filename,pathname] = uigetfile('*.jpg;*.bmp','选择图片','E:\pictures\For_Project\Matlab');
imgaepath = strcat(pathname,filename);
image = imread(imgaepath);
figure,imshow(image);
Image = image;
[row,col,k]=size(Image);
Image1=Image;
Image2=Image;
Image3=Image;
Image4=Image;
Offset=5;
%%% 左移
Image1(:,1:col-Offset,:)=Image(:,1+Offset:col,:);
%%% 右移
Image2(:,1+Offset:col,:)=Image(:,1:col-Offset,:);
%%%% 上移
Image3(1+Offset:row,:,:)=Image(1:row-Offset,:,:);
%%% 下移
Image4(1:row-Offset,:,:)=Image(1+Offset:row,:,:);
Image=(Image1+Image2+Image3+Image4)/4;
figure, imshow(Image);