Matlab是一种图像视频处理实现的好工具,因为matlab是基于数组操作的,而一副图像就是一个数组。因此搞DIP或者CV的是一种必需掌握的工具。
为了学会使用matlab在图像处理的基本应用。按照瓦萨雷斯数字图像处理Matlab版中的第三章,按照书本输了一遍。代码中用到的图片(网上可以下载)放在本目录的images中。没写什么注释,因为自己输入过程中看help命令和试验结果基本都可以弄懂,代码最后有一些小笔记。代码如下:
clc
clear
f=imread('.\images\dipum_images_ch03\Fig0303(a)(breast).tif');
subplot(2,3,1);
imshow(f)
g2=(imadjust(f,[0 1],[1 0]));
subplot(2,3,2);
imshow(g2)
g3=imcomplement(f);
subplot(2,3,3);
imshow(g3)
g4=imadjust(f,[0.5,0.75],[0 1]);
subplot(2,3,4);
imshow(g4)
g5=imadjust(f,[],[],2);
subplot(2,3,5);
imshow(g5)
g5=imadjust(f,[],[],0.8);
subplot(2,3,6);
imshow(g5)
clc
clear
f=imread('.\images\dipum_images_ch03\Fig0305(a)(spectrum).tif');
subplot(121),imshow(f),subplot(122),imhist(f),axis tight
g=im2uint8(mat2gray(log(1+double(f))));
figure,subplot(121),imshow(g),subplot(122),imhist(g),axis tight
title('ʹÓöÔÊý±ä»»¼õС¶¯Ì¬·¶Î§')
m=5;
E=10;
h=im2uint8(mat2gray(1./(1+(m./(double(f)+eps)).^E)));%ΪʲôÊÇÕâ¸ö¹«Ê½
figure,subplot(121),imshow(h),subplot(122),imhist(h),axis tight
clc
clear
f=imread('.\images\dipum_images_ch03\Fig0306(a)(bone-scan-GE).tif');
imshow(f)
g=intrans(f,'stretch',mean2(im2double(f)),0.9);
figure ,imshow(g)
clc
clear
f=[125.3 69.8 5.3 2.3];
g=uint8(f)
hf=gscale(f)
h1=gscale(g)
h2=gscale(g,'minmax',0.1,0.6)
class(h2)
clc
clear
f=imread('.\images\dipum_images_ch03\Fig0308(a)(pollen).tif');
subplot(121),imshow(f),subplot(122),imhist(f)
ylim('auto')
g1=histeq(f);
figure,subplot(121),imshow(g1),subplot(122),imhist(g1)
ylim('auto')
g2=histeq(f,8);
figure,subplot(121),imshow(g2),subplot(122),imhist(g2)
ylim('auto')
clc
clear
f = imread('.\images\dipum_images_ch03\Fig0310(a)(Moon Phobos).tif');
p = manualhist;
plot(p)
figure,subplot(121),imshow(f),subplot(122),imhist(f),ylim('auto')
g = histeq(f,p);
figure,subplot(121),imshow(g),subplot(122),imhist(g),ylim('auto')
clc
clear
f = imread('.\images\dipum_images_ch03\Fig0315(a)(original_test_pattern).tif');
f = im2double(f);
imshow(f)
w = ones(31)
gd = imfilter(f, w)
figure,imshow(gd,[])
%figure,imshow(gd)
gr = imfilter(f, w, 'replicate');
figure,imshow(gr,[])
gc = imfilter(f, w, 'circular');
f8 = im2uint8(f);
gr8 = imfilter(f8, w, 'replicate');
figure,imshow(gr8,[])
clc
clear
f = [1 2 3 4]
frb = padarray(f,[3 2],'replicate','both'); % ĬÈÏboth
g = colfilt(frb,[3 2],'sliding',@gmean);
size_g = size(g)
clc
clear
f = imread('.\images\dipum_images_ch03\Fig0316(a)(moon).tif');
imshow(f)
w = fspecial('laplacian',0);
g1 = imfilter(f,w,'replicate');
figure,imshow(g1,[])
f2 = im2double(f);
g2 = imfilter(f2,w,'replicate');
figure,imshow(g2,[])
g=f2-g2;
figure,imshow(g,[])
clc
clear
f = imread('.\images\dipum_images_ch03\Fig0316(a)(moon).tif');
imshow(f)
w4 = fspecial('laplacian',0);
w8 = [1 1 1; 1 -8 1; 1 1 1];
f = im2double(f);
g4 = f - imfilter(f,w4,'replicate');
g8 = f - imfilter(f,w8,'replicate');
figure,subplot(221)
imshow(imfilter(f,w4,'replicate'))
subplot(223)
imshow(imfilter(f,w8,'replicate'))
subplot(222)
imshow(imfilter(f,w4,'replicate'),[])
subplot(224)
imshow(imfilter(f,w8,'replicate'),[])
figure,subplot(221)
imshow(g4)
subplot(222),imshow(g4,[])
subplot(223),imshow(g4)
subplot(224),imshow(g8,[])
clc
clear
f = imread('.\images\dipum_images_ch03\Fig0318(a)(ckt-board-orig).tif');
subplot(121),imshow(f)
fn=imnoise(f,'salt & pepper',0.2);
subplot(122),imshow(fn)
gm=medfilt2(fn);
figure,subplot(121),imshow(gm)
gms=medfilt2(fn,'symmetric');
subplot(122),imshow(gms)
clc
clear
median(1:10)
median(1:11)
median(-2:-1:-10)
median(11:-1:1)
median(-20:-10)
小总结见下面一篇
文章评论(0条评论)
登录后参与讨论