当前位置:文档之家› 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Ž
相关主题