当前位置:
文档之家› matlab数字图像处理实验指导
matlab数字图像处理实验指导
2
figure, imshow(J3) help imadjust
% Display the imadjust() function information.
3ˊぎඳᑇ⒥Ⓒ⊶˄㊞ǃএా˅ clear all; close all I = imread('eight.tif'); h1 = ones(3,3) / 9; h2 = ones(5,5) / 25; I1 = imfilter(I,h1); I2 = imfilter(I,h2); figure(1), imshow(I), title('Original Image'); figure(2), imshow(I1), title('Filtered Image With 3*3 ') figure(3), imshow(I2), title('Filtered Image With 5*5 ') % ࡴܹGaussian ాໄ J1 = imnoise(I,'gaussian',0,0.005); % ࡴܹỦⲤాໄ J2 = imnoise(I,'salt & pepper',0.02); % ᇍJ1ǃJ2䖯㸠ᑇഛؐᑇ⒥Ⓒ⊶ K1 = imfilter(J1,fspecial('average',3)); K2 = imfilter(J2,fspecial('average',3)); figure(4); subplot(2,2,1), imshow(J1) , title('gaussian'); subplot(2,2,2), imshow(J2), title('salt & pepper '); subplot(2,2,3), imshow(K1), title('average '); subplot(2,2,4), imshow(K2); % ᇍJ1ǃJ2䖯㸠ЁؐⒸ⊶ K3 = medfilt2(J1,[3 3]); K4 = medfilt2(J2,[3 3]); figure(5); subplot(2,2,1), imshow(J1) , title('gaussian'); subplot(2,2,2), imshow(J2), title('salt & pepper '); subplot(2,2,3), imshow(K3), title(' Median filtering '); subplot(2,2,4), imshow(K4) 4ˊぎඳ䫤࣪Ⓒ clear all; close all I = imread('moon.tif'); w=fspecial('laplacian',0) w8=[1,1,1;1,-8,1;1,1,1] I1= imfilter(I,w, 'replicate'); figure(1); imshow(I), title('Original Image');
⊼ᛣ˖imadjust() ࡳ㛑˖ 䇗ᭈ♄ڣᑺؐ买㡆ڣ㸼ˈгৃᅲ⦄ԑ偀᷵ℷDŽ 䇁⊩˖
J = imadjust(I,[low_in high_in],[low_out high_out],gamma) newmap = imadjust(map,[low_in high_in],[low_out high_out],gamma) RGB2 = imadjust(RGB1,...)
《数字图像处理》
实验指导书
山东农业大学
2010年9月
Ⳃ
ᔩ
ᅲ偠ᅜ߭ĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂ ᅲ偠ϔڣᔎϢᑇ⒥ĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂ ᅲ偠ѠࡆߚڣϢ䖍㓬Ẕ⌟ĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂ ᅲ偠ϝⱘڣԩবᤶĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂ ᅲ偠ಯڣᔶᗕᄺ໘⧚ĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂ ᅲ偠Ѩ乥ඳবᤶĂĂĂĂĂĂቤተ መጻሕፍቲ ባይዱĂĂĂĂĂĂĂĂĂĂĂĂĂĂ ᅲ 偠 ݁ ᭄ ᄫ ڣ໘ ⧚ ᑨ ⫼ Ă Ă Ă Ă Ă Ă Ă Ă Ă Ă Ă Ă Ă Ă Ă 䰘ᔩ 0$7/$% ㅔҟĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂĂ 䰘ᔩ ᅲ偠ਞ㣗՟/2* Ⓒ⊶఼ᦤপ䖍㓬ĂĂĂĂĂĂĂĂĂ
3
figure(2), imshow(I1), title('Laplacian Image'); f = im2double(I); f1= imfilter(f,w, 'replicate'); figure(3), imshow(f1,[]), title('Laplacian Image'); f2= imfilter(f,w8, 'replicate'); f4 = f-f1; f8 = f-f2; figure(4), imshow(f4); figure(5), imshow(f8); 5ˊⱘڣЎᔽ㡆໘⧚—ᆚᑺߚࡆ clear all, close all I = imread('ngc4024m.tif'); X = grayslice(I,16); imshow(I), title('Original Image') figure, imshow(X,jet(16)), title('Index Color Image') ˄Ѡ˅䞛⫼MATLABᑩሖߑ᭄㓪ᅲ⦄ҹϟ♄ᑺ㒓ᗻবᤶ ؛ᅮॳڣf(x, y)ⱘ♄ᑺ㣗ೈЎ˷a, b˹ˈᏠᳯবᤶৢ ڣg(x, y)ⱘ♄ᑺ㣗ೈᠽሩ㟇 ˷c, d˹ˈ߭㒓ᗻবᤶৃ㸼冫Ў˖ d c g ( x, y ) [ f ( x, y ) a ] c ba ⫼MATLABᑩሖߑ᭄㓪ᅲ⦄Ϟ䗄বᤶߑ᭄DŽ㾖ᆳ ‘ڣpout.tif’ⱘ♄ᑺⳈᮍˈ䗝 ᢽড়䗖ⱘখ᭄˷a, b˹ǃ˷c, d˹ᇍڣþpout.tifÿ䖯㸠♄ᑺবᤶˈҹ㦋ᕫ⒵ᛣⱘ㾚㾝ᬜ ᵰDŽ
1
ᅲ偠ϔڣᔎϢᑇ⒥
ϔˊᅲ偠Ⳃⱘঞ㽕∖
1ˊњ㾷MATLABⱘ᪡⦃๗ᴀࡳ㛑DŽ 2ˊᥠᦵMATLABЁڣᔎϢᑇ⒥ⱘߑ᭄ⱘՓ⫼ᮍ⊩DŽ 3ˊࡴ⏅⧚㾷ڣᔎϢᑇ⒥ⱘㅫ⊩ॳ⧚DŽ
Ѡǃᅲ偠ݙᆍ
˄ϔ˅ⷨおҹϟᑣˈߚᵤᑣࡳ㛑˗䕧ܹᠻ㸠ੑҸ㸠ˈ䅸ⳳ㾖ᆳੑҸᠻ㸠ⱘ㒧 ᵰDŽ❳ᙝᑣЁ᠔Փ⫼ߑ᭄ⱘ䇗⫼ᮍ⊩ˈᬍব᳝݇খ᭄ˈ㾖ᆳ䆩偠㒧ᵰDŽ ˄ৃᇚ↣↉ ᑣֱᄬЎϔϾ.m᭛ӊ˅ 1ˊⳈᮍഛ㸵࣪ clear all; close all I = imread('pout.tif'); imshow(I) figure, imhist(I)
% Clear the MATLAB workspace of any variables % and close open figure windows. % Reads the sample images ‘ pout.tif’, and stores it in % an array named I.display the image % Create a histogram of the image and display it in % a new figure window. % Histogram equalization.
ᅲ
偠
ᅜ
߭
Ўњࡴᔎᅲ偠ᅸㅵ⧚ˈᦤ催ᅲ偠ᬭᄺ䋼䞣ˈݏᄺ⫳⧚䆎㘨㋏ᅲ䰙ⱘᄺ亢ˈᦤ催ᅲ 䰙᪡ᡔ㛑ˈ⹂ֱҎ䑿䆒ⱘᅝܼˈ⡍ࠊᅮབϟᅜ߭˖ ˊᅲ偠ࠡ㽕䅸ⳳ乘дˈњ㾷ᅲ偠Ⳃⱘǃᅲ偠ॳ⧚ǃᅲ偠㒓䏃ǃᅲ偠ℹ偸ঞ℆⌟ⱘ ⠽⧚䞣DŽ❳ᙝᅲ偠᳝݇ⱘҾ఼䆒ⱘ⫼䗨ǃՓ⫼ᮍ⊩ঞ⊼ᛣџ乍DŽ㛑ಲㄨᣛᇐᬭᏜⱘ ᦤ䯂DŽ ˊ↣Ͼᅲ偠ᇣ㒘㽕䗝ߎ㒘䭓 ৡˈᅲ偠ᯊ㽕䅸ⳳߚᎹˈ䕂⌕ᔧ䆄ᔩਬ᪡㗙ˈ ҹ֓↣ϾҎ䛑㛑ᕫࠄ䕗ܼ䴶ⱘ䆁㒗DŽᅲ偠㒓䏃དৢˈ㒘ᄺ⫳㽕㞾㸠Ẕᶹˈ✊ৢ䇋ᣛ ᇐᬭᏜẔᶹˈ㒣Ẕᶹ᮴䇃ৢᮍৃ䗮⬉⑤DŽᬍ㒓䏃ᖙ乏ܜᮁᓔ⬉⑤ˈҹܡ㾺⬉ঞᤳണ Ҿ㸼DŽᬍৢⱘ㒓䏃ҡ䳔㒣ᬭᏜẔᶹDŽ ˊᅲ偠ᯊᑨҢᬭᏜᣛᇐˈϹḐᣝᅲ偠ℹ偸䖯㸠ˈབᅲ䆄ᔩᅲ偠᭄ˈ鳥ᵕᗱ㗗 ߚᵤᅲ偠Ёথ⫳ⱘ⦄䈵DŽᅲ偠Ёབ䘛џᬙᑨゟे݇ᮁ⬉⑤ǃֱᣕ⦄എˈਞᣛᇐᬭᏜ ঞᯊ໘⧚DŽབ᳝ᤳണҾ఼఼ӊˈ㽕฿ݭџᬙॳঞᤳऩDŽ ˊᅲ偠ᅠ↩ᑨゟे݇ᮁ⬉⑤ˈᡞᅲ偠䆄ᔩѸᣛᇐᬭᏜẔᶹড়Ḑৢᮍৃᢚ䰸㒓䏃DŽ བথ⦄ᅲ偠䆄ᔩ᳝ϡᔧ䫭䇃Пˈᑨゟे䞡DŽ㽕ᡞ᠔᳝Ҿ఼ǃҾ㸼ǃᎹǃᇐ㒓ᭈ ⧚དDŽ㒣ᣛᇐᬭᏜ⏙⚍ৢᮍৃ行ᓔᅲ偠ᅸDŽ ˊ㽕⠅ᡸ݀⠽DŽᅲ偠ᅸ᠔᳝ⱘҾ㸼ǃᎹǃ఼ӊㄝϔᕟϡᕫ᪙㞾ᏺߎDŽᅲ偠Ёབ 䳔ᤶҾ఼ǃҾ㸼ǃᎹǃ఼ӊㄝˈᖙ乏㒣ᣛᇐᬭᏜৠᛣDŽϡᕫ᪙㞾ᤶхᣓҪ㒘⠽ કDŽ㒣ܕ䆌ˈϡᕫ᪙㞾ᢚौᅲ偠⫼ⱘҾ఼ǃ䆒DŽ ˊᅲ偠ᯊ㽕Ϲ㙗䅸ⳳˈ䆆お᭛ᯢǃ凵䉠ˈ㽕ֱᣕᅝ䴭ᅸݙᭈ⋕ˈϡ䱣ഄ⯄ хᡯᴖ⠽DŽᅲ偠ᅠ↩㽕ᠧᠿᅲ偠ᅸि⫳DŽ ˊкݭᅲ偠ਞᯊˈ䇁㿔㽕∖ㅔ㒗ˈкݭᑨッℷˈᑨℷ㾘DŽᅲ偠ਞϔ㠀 ᑨࣙᣀҹϟݙᆍ˖ ᅲ偠Ⳃⱘ˗᠔⫼Ҿ఼ǃҾ㸼ǃ఼ӊⱘৡ鹵ঞ㾘Ḑൟো˗ᅲ偠⬉䏃ॳ⧚DŽ ᅲ偠乍Ⳃ ᣛᇐкЁⱘ䆺㒚ݙᆍϡᖙᡘᔩ ˗⌟䆩䆄ᔩ㸼˗⊶ᔶঞ⦄䈵䆄ᔩDŽ ᅲ偠᭄ᭈ⧚ˈ䅵ㅫৢⱘ㒧ᵰǃঞḍᅲ偠᭄㒬ࠊⱘ᳆㒓DŽ ᅲ偠ߚᵤˈᑨࣙᣀϢ⧚䆎䅵ㅫؐⱘ↨䕗ǃ⦄䈵ߚᵤDŽ ˊ݇Ѣᅲ偠㗗Ḍ˖ ᄺ⫳ᅲ偠䇒Ёⱘᅲ䰙ᡔ㛑∈ᑇϢᅲ偠ਞⱘ䋼䞣ᰃ䆘ᅮᴀ䇒ᅲ偠៤㒽ⱘᷛޚDŽ 辵ॳ㔎خᅲ偠㔎Ѹᅲ偠ਞ㗙ˈᅲ偠៤㒽㽕ফᕅડDŽ
Ѩǃᅲ偠ਞ㽕∖
1. 2. 3. 4.
4
ㅔ䗄䆩偠ⱘⳂⱘ䆩偠ॳ⧚˗ ভ䗄↉ᑣࡳ㛑ˈᬍব᳝݇ߑ᭄ⱘখ᭄ˈߚᵤ↨䕗ᅲ偠㒧ᵰ˗ ᠧॄߎ᠔㓪ⱘݭᅲ偠ᑣDŽ ߎݭᴀᅲ偠ⱘᖗᕫԧӮঞᛣ㾕DŽ
ᅲ偠Ѡ
ϔˊᅲ偠Ⳃⱘঞ㽕∖
ࡆߚڣϢ䖍㓬Ẕ⌟
1ˊ߽⫼ MATLAB ⷨおࡆߚڣϢ䖍㓬Ẕ⌟ⱘᐌ⫼ㅫ⊩ॳ⧚˗ 2ˊᥠᦵ MATLAB ڣඳؐߚࡆϢ䖍㓬Ẕ⌟ߑ᭄ⱘՓ⫼ᮍ⊩˗ 3ˊњ㾷䖍㓬Ẕ⌟ⱘㅫ⊩⫼䗨ˈ↨䕗 SobelǃPrewittǃCanny ㄝㅫᄤ䖍㓬Ẕ⌟ⱘᏂ ᓖDŽ