小白一枚,有错误之处还请指出,谢谢~
1、双重曝光
clc;clear;
picname='xinyi.tif';
picname1='xiaolan.tif';
x=double(imread(picname))/255;
%实现归一化,读入的类型是无符号的8位整型,
%相当于0-255的所有整数,为了计算准确,必须先化为double型。
%再除以255,这样图像矩阵的值全部都在0-1之间。
x1=double(imread(picname1))/255;
subplot(2,2,1);
imshow(x);
title('原图1');
subplot(2,2,2);
imshow(x1);
title('原图2');
alpha=0.3;
picinfo=imfinfo(picname);
for i=1:picinfo.Height
for j=1:picinfo.Width
for k=1:3
Y(i,j,k)=alpha*x(i,j,k)+(1-alpha)*x1(i,j,k);
%a,b是两幅图像,k是系数。由于两幅彩色图像都是三维的,
%所以循环要跑三个方向,进行图片的叠加
end
end
end
subplot(2,2,3);
pause(2)
imshow(Y)
title('双重曝光后的图');
效果图
2、直方图均衡化
clc ;clear
%% 直方图均衡
A = imread('autumn.tif');%读取图像
A=rgb2gray(A);%将图片灰度化
[J,T] = histeq(A);%直方图均衡化,T为直方图的值
%% Image display
figure(1);%建立空白图像
subplot(3, 2, 1);
imshow(A);
title('原图');
subplot(3, 2, [3 4]);
imhist(A);%显示原图的直方图
title('原图的直方图');
subplot(3, 2, 2);%画出均衡化后的图及直方图
imshow(J);
title('均衡化的图');
subplot(3,2, [5 6]);
imhist(J);
title('均衡化后的直方图');
效果图
3、平滑滤波(中值滤波,均值滤波,梯度倒数):加噪声
1)椒盐噪声
clear; close all; clc
%% 图像读取、灰度化与加椒盐噪音
I = imread('xinyi.tif');%读取图像
I=rgb2gray(I);%调用函数,处理图像使之灰度化
J = imnoise(I,'salt & pepper');%椒盐噪声
%% 中值滤波
z_J=medfilt2(J);%中值滤波函数
%% 均值滤波
h0=1/9.*[1 1 1 1 1 1 1 1 1];%定义平滑模板
p_J=filter2(h0,J);
p_J=uint8(p_J);
%% 梯度倒数
t_J=double(J);%转化图像为double型
[GX,GY]=gradient(t_J);%求图像梯度
G=sqrt(GX.*GX+GY.*GY);
%% Image display
figure
subplot(3,2,1),imshow(I);%输出图像
title('原图像')%给原图像加标题
subplot(3,2,2),imshow(J);%输出图像
title('加椒盐噪声后图像')%给原图像加标题
subplot(3,2,3),imshow(z_J);%输出图像
title('中值滤波后图像')%给图像加标题
subplot(3,2,4),imshow(p_J);%输出图像
title('均值滤波后图像')%给图像加标题
subplot(3,2,5),imshow(G/255,[]);%把double类型换回unit8类型输出
title('梯度倒数后图像')
效果图
2)高斯噪声
clear; close all; clc
%% 图像读取、灰度化与高斯噪声
I = imread('xinyi.tif');%读取图像
I=rgb2gray(I);%调用函数,处理图像使之灰度化
J = imnoise(I,'gaussian');%高斯噪声
%% 中值滤波
z_J=medfilt2(J);%中值滤波函数
%% 均值滤波
h0=1/9.*[1 1 1 1 1 1 1 1 1];%定义平滑模板
p_J=filter2(h0,J);
p_J=uint8(p_J);
%% 梯度倒数
t_J=double(J);%转化图像为double型
[GX,GY]=gradient(t_J);%求图像梯度
G=sqrt(GX.*GX+GY.*GY);
%% Image display
figure
subplot(3,2,1),imshow(I);%输出图像
title('原图像')%给原图像加标题
subplot(3,2,2),imshow(J);%输出图像
title('加高斯噪声后图像')%给原图像加标题
subplot(3,2,3),imshow(z_J);%输出图像
title('中值滤波后图像')%给图像加标题
subplot(3,2,4),imshow(p_J);%输出图像
title('均值滤波后图像')%给图像加标题
subplot(3,2,5),imshow(G/255,[]);%把double类型换回unit8类型输出
title('梯度倒数后图像')
效果图