a=imread('D:\MATLAB6p5\toolbox\images\imdemos\pout.tif');
subplot(2,3,1);
imshow(a);title('原图');
a=double(a);
c=255-a;
c=uint8(c);
subplot(2,3,2);
imshow(c);title('反变换');
b=30*log(1+a);
b=uint8(b);
subplot(2,3,3);
imshow(b);title('对数变换');
[M, N] = size(a);
d=[];
for i = 1:M
for j = 1:N
if a(i, j) <= 30
d(i, j) = a(i, j);
elseif a(i, j)<= 150
d(i, j) = (200 - 30)/(150 - 30)*(a(i, j) - 30) + 30;
else
d(i, j) = (255 - 200)/( 255 - 150)*(a(i, j) - 150) + 200;
end
end
end
subplot(2,3,5);imshow(uint8(d));title('分段线性变换');
e=30*(a.^0.4);
subplot(2,3,4);imshow(uint8(e));title('幂次变换 r=0.4');
f=[];
for i = 1:M
for j = 1:N
if a(i, j) <=50
f(i, j) = 40;
elseif a(i, j)<= 110
f(i, j) = 220;
else
f(i, j) = 40;
end
end
end
f= uint8(f);
subplot(2,3,6);imshow(f);title('灰度切割');
g=a;
for i = 1:M
for j = 1:N
if bitand(g(i, j), bitshift(1,7)) >0
g(i,j) = 255;
else g(i,j) = 0;
end
end
end
figure;
subplot(2,3,1);
imshow(g);title('位图切割:第七位图');
h=a;
for i = 1:M
for j = 1:N
if bitand(h(i, j), bitshift(1,6)) >0
h(i,j) = 255;
else h(i,j) = 0;
end
end
end
subplot(2,3,2);imshow(h);title('位图切割:第六位图');
k=a;
for i = 1:M
for j = 1:N
if bitand(k(i, j), bitshift(1,5)) >0
k(i,j) = 255;
else k(i,j) = 0;
end
end
end
subplot(2,3,3);imshow(k);title('位图切割:第五位图');
l=imopen(a,strel('disk',15));
m=imsubtract(a,l);
subplot(2,3,4);imshow(uint8(m));title('减法');
p=imread('D:\MATLAB6p5\toolbox\images\imdemos\pout.tif');
n = zeros(M, N);
figure
q=1;
for i = 1:16
II(:,:,i) = imnoise(p, 'gaussian', 0, 0.01);
n= n + double(II(:,:,i));
if or(or(i == 4, i== 8),or(i == 1, i== 16))
subplot(3,2,q),imshow(uint8(n/i));q=q+1;title('高斯噪声滤波;画面叠加');
end
end
r= imnoise(p,'salt & pepper',0.02);
subplot(3,2,5);imshow(uint8(r)),title('添加椒盐噪声图像');
s= medfilt2(r);
subplot(3,2,6);imshow(uint8(s)),title('3x3 模板中值滤波');
figure;
k1 = filter2(fspecial('average',3), r);
k2 = filter2(fspecial('average',5), r);
k3 = filter2(fspecial('average',7), r);
subplot(2,2,1);imshow(r);title('添加椒盐噪声的图像');
subplot(2,2,2);imshow(k1,[]);title('3*3 模板平均');
subplot(2,2,3);imshow(k2,[]);title('5*5 模板平均');
subplot(2,2,4);imshow(k3,[]);title('7*7 模板平均');