MATLAB非线性变换

非线性变换
对图像进行灰度变换
clear all;
R=imread('peppers.png');
G=rgb2gray(R);
J=double(G);
H=(log(J+1)/10);
subplot(121);imshow(G);
title('灰度图像');
subplot(122);imshow(H);
title('非线性变换图像');

利用imadjust函数调整图像的灰度与亮度
clear all;
I=imread('pout.tif');
subplot(221);imshow(I);
title('原始图像');
J=imadjust(I);
subplot(222);imshow(J);
title('原始图像灰度调整');
K=imadjust(I,[0.3,0.7],[]);
subplot(223);imshow(K);
title('图像变亮');
G=imadjust(I,[0.3,0.7],[0,1],4);
subplot(224);imshow(G);
title('图像变暗');

利用imhist函数计算和显示灰度图像的直方图
clear all;
I=imread('pout.tif');
subplot(121);imshow(I);
title('原始图像');
subplot(122);imhist(I);
title('灰度直方图');

利用histeq函数对弧度图像进行直方图均衡化
clear all;
I=imread('tire.tif');
J=histeq(I);
subplot(221);imshow(I);
title('原始图像');
subplot(222);imshow(J);
title('图像均衡化');
subplot(223);imhist(I,64);
title('原图像的直方图');
subplot(224);imhist(J,64);
title('图像均衡化的直方图');

通过histeq对图像进行规定化处理
clear all;
I=imread('tire.tif');
hgram=ones(1,256);
J=histeq(I,hgram);
subplot(121);imshow(uint8(I));
title('原始图像');
subplot(122);imhist(J);

imadd函数实现两幅图像的叠加
clear all;
I=imread('rice.png');
J=imread('cameraman.tif');
K=imadd(I,J,'uint16');
subplot(131);imshow(I);
title('原始图像 rice');
subplot(132);imshow(J);
title('原始图像 cameraman');
subplot(133);imshow(K,[]);
title('两幅图像叠加');

利用imnoise函数为图像添加椒盐噪声
clear all;
I=imread('eight.tif');
J=imnoise(I,'salt & pepper',0.04);
subplot(121);imshow(I);
title('原始图像');
subplot(122);imshow(J);
title('添加椒盐噪声的图像');

利用imadd方法进行噪声抑制
clear all;
I=imread('eight.tif');
J1=imnoise(I,'gaussian',0,0.006);
J2=imnoise(I,'gaussian',0,0.006);
J3=imnoise(I,'gaussian',0,0.006);
J4=imnoise(I,'gaussian',0,0.006);
K=imlincomb(0.3,J1,0.3,J2,0.3,J3,0.3,J4);
figure;
subplot(131);imshow(I);
title('原始图像');
subplot(132);imshow(J1);
title('添加高斯噪声的图像');
subplot(133);imshow(K,[]);
title('抑制高斯噪声的图像');

利用imsubtract函数取出图像的背景
clear all;
I=imread('rice.png');
background=imopen(I,strel('disk',15));
Ip=imsubtract(I,background);
figure;
subplot(131);imshow(I);
title('原始图像');
subplot(132);imshow(background);
title('背景图');
subplot(133);imshow(Ip,[]);
title('去除背景的图像');

利用imabsdiff进行图像减法运算,两幅图像差的绝对值
clear all;
I=imread('cameraman.tif');
J=uint8(filter2(fspecial('gaussian'),I));
K=imabsdiff(I,J);
subplot(131),imshow(I);
title('原始图像');
subplot(132);imshow(J);
title('含噪图像');
subplot(133);imshow(K,[]);
title('两幅图像相减');

对图像进行自乘和与一个常数相乘//flower图片可能不存在
clear all;
I=imread('flower.jpg');
subplot(221);imshow(I);
title('原始图像');
I16=uint16(I);
J=immultiply(I16,I16);
subplot(222);imshow(J);
title('图像自相乘效果');
J2=immultiply(I,0.65);
subplot(2,2,3);imshow(J2);
title('图像与常数相乘');

利用imdivide函数对图像进行除法运算
clear all;
I=imread('office_1.jpg');
J=imread('office_2.jpg');
Ip=imdivide(J,I);
K=imdivide(J,0.45);
subplot(221);imshow(I);
title('office1 图像');
subplot(222);imshow(J);
title('office2 图像');
subplot(223);imshow(Ip);
title('两幅图像相除');
subplot(224);imshow(K);
title('图像与常数相除');

猜你喜欢

转载自blog.csdn.net/weixin_43914278/article/details/89008479