本文系《数字图像处理原理与实践(MATLAB版)》一书之代码系列的Part1(P1~42),代码执行结果请参见原书配图,建议下载代码前阅读下文:
关于《数字图像处理原理与实践(MATLAB版)》一书代码发布的说明
http://blog.csdn.net/baimafujinji/article/details/40987807
P20
I = imread(‘lena.jpg‘);
BW1 = im2bw(I);
BW2 = im2bw(I, 0.3);
BW3 = im2bw(I, 0.6);
figure
subplot(2,2,1),imshow(I);
title(‘original‘);
subplot(2,2,2),imshow(BW1);
title(‘\default‘);
subplot(2,2,3),imshow(BW2);
title(‘level = 0.3‘);
subplot(2,2,4),imshow(BW3);
title(‘level = 0.6‘)
P25-1
IMG1 = imread(‘airplane.jpg‘);
IMG2 = imread(‘baboon.jpg‘);
IMG3 = imread(‘lena.jpg‘);
imshow(IMG1)
imshow(IMG2)
imshow(IMG3)
P25-2
% figure
imshow(IMG1)
figure(5)
imshow(IMG2)
P26
figure;
subplot(1,2,1),subimage(IMG1);
title(‘airplane‘);
subplot(1,2,2),subimage(IMG2);
title(‘baboon‘);
P31
imhist(I)
imhist(I, n)
[counts, x]=imhist(...)
P32
i = imread(‘theatre.jpg‘);
g = rgb2gray(i);
figure
subplot(121), imhist(g);
subplot(122), imhist(g, 64);
P33
i = imread(‘baboon.jpg‘);
i = rgb2gray(i);
[m,n]=size(i);
[counts1, x]=imhist(i, 32);
subplot(121), stem(x, counts1);
counts2 = counts1/m/n;
subplot(122), stem(x, counts2);
P35
i=imread(‘theatre.jpg‘);
[x,y,z]=size(i);
figure
subplot(221), imshow(i);
title(‘original image‘)
%提取红色分量
r=i;
%r(:,:,1)=a(:,:,1);
r(:,:,2)=zeros(x,y);
r(:,:,3)=zeros(x,y);
r=uint8(r);
subplot(222),imshow(r);
title(‘R-component-image‘)
%提取绿色分量
g=i;
g(:,:,1)=zeros(x,y);
%g(:,:,2)=a(:,:,2);
g(:,:,3)=zeros(x,y);
g=uint8(g);
subplot(223),imshow(g);
title(‘G-component-image‘)
%提取蓝色分量
b=i;
b(:,:,1)=zeros(x,y);
b(:,:,2)=zeros(x,y);
%b(:,:,3)=a(:,:,3);
b=uint8(b);
subplot(224),imshow(b);
title(‘B-component-image‘)
P38
i=imread(‘theatre.jpg‘);
r=a(:,:,1);
g=a(:,:,2);
b=a(:,:,3);
subplot(1,3,1), imhist(r), title(‘R component‘);
subplot(1,3,2), imhist(g), title(‘G component‘);
subplot(1,3,3), imhist(b), title(‘B component‘);
P41
i = imread(‘theatre.jpg‘);
i = im2double(rgb2gray(i));
[m,n]=size(i);
%增加对比度
Fa = 1.25; Fb = 0;
O = Fa.*i + Fb/255;
figure(1), subplot(221), imshow(O);
title(‘Fa = 1.25, Fb = 0, contrast increasing‘);
figure(2),subplot(221), [H,x]=imhist(O, 64);
stem(x, (H/m/n), ‘.‘);
title(‘Fa = 1.25, Fb = 0, contrast increasing‘);
%减小对比度
Fa =0.5; Fb = 0;
O = Fa.*i + Fb/255;
figure(1), subplot(222),imshow(O);
title(‘Fa = 0.5, Fb = 0, contrast decreasing‘);
figure(2), subplot(222), [H,x] = imhist(O, 64);
stem(x, (H/m/n), ‘.‘);
title(‘Fa = 0.5, Fb = 0, contrast decreasing‘);
%线性亮度增加
Fa = 0.5; Fb = 50;
O = Fa.*i + Fb/255;
figure(1), subplot(223), imshow(O);
title(‘Fa = 0.5, Fb = 50, brightness control‘);
figure(2), subplot(223), [H,x]=imhist(O,64);
stem(x, (H/m/n), ‘.‘);
title(‘Fa = 0.5, Fb = 50, brightness control‘);
%反相显示
Fa = -1; Fb = 255;
O = Fa.*i + Fb/255;
figure(1), subplot(224), imshow(O);
title(‘Fa = -1, Fb = 255, reversal processing‘);
figure(2), subplot(224),[H,x]=imhist(O, 64);
stem(x, (H/m/n), ‘.‘);
title(‘Fa = -1, Fb = 255, reversal processing‘);
(代码发布未完,请待后续...)
《数字图像处理原理与实践(MATLAB版)》一书之代码Part1
原文地址:http://blog.csdn.net/baimafujinji/article/details/41117641