《數位影像處理原理與實踐(MATLAB版)》一書之代碼Part4,matlab數位影像處理

來源:互聯網
上載者:User

《數位影像處理原理與實踐(MATLAB版)》一書之代碼Part4,matlab數位影像處理
本文系《數位影像處理原理與實踐(MATLAB版)》一書之代碼系列的Part4,輯錄該書第135至第183頁之代碼,供有需要讀者下載研究使用。代碼執行結果請參見原書配圖,建議下載代碼前閱讀下文:

關於《數位影像處理原理與實踐(MATLAB版)》一書代碼發布的說明

http://blog.csdn.net/baimafujinji/article/details/40987807

P139

original = imread('snowflakes.png');
figure, imshow(original);
se = strel('disk',5);
afterOpening = imopen(original,se);
figure, imshow(afterOpening,[]);

P140

originalBW = imread('circles.png');
imshow(originalBW);
se = strel('disk',10);
closeBW = imclose(originalBW,se);
figure, imshow(closeBW)

P144

bw = imread('bw.bmp');
shape1 = [0 0 0 0 1
            0 0 0 1 1
            0 0 1 1 1
            0 1 1 1 1
            1 1 1 1 1];
shape2 = [1 1 0 0 0
            1 0 0 0 0
            0 0 0 0 0
            0 0 0 0 0
            0 0 0 0 0];
bw2 = bwhitmiss(bw, shape1, shape2);
imshow(bw2)

P146-1

I = imread('letter2.jpg');
I = im2bw(I);
I1 = bwmorph(I, 'thin',inf);
figure(1), imshow(I1);

P146-2

I = imread('letter2.jpg');
I = im2bw(I);
I2 = bwmorph(I, 'skel',inf);
figure(2), imshow(I2);

P153

I = imread('lena.jpg');
I = rgb2gray(I);
BW1 = edge(I, 'roberts');
BW2 = edge(I, 'sobel');
BW3 = edge(I, 'prewitt');
figure
subplot(2,2,1),imshow(I),title('original')
subplot(2,2,2),imshow(BW1),title('roberts')
subplot(2,2,3),imshow(BW2),title('sobel')
subplot(2,2,4),imshow(BW3),title('prewitt')

P157

I = imread('einstein.bmp');
I = rgb2gray(I);
N = [1, 2, 1
     0, 0, 0
     -1,-2,-1];
edge_n = imfilter(I,N,'symmetric','conv');
imwrite(edge_n, 'edge_n.jpg');

P160

I = rgb2gray(imread('lena.jpg'));
M = [1,1,1
        1,-8,1
        1,1,1];
img=imfilter(I,M);
[x,y]=size(I);
img2 = img;
for i = 2:x-1
        for j = 2:y-1
            a = [img(i,j+1),img(i,j-1),img(i+1,j+1),img(i+1,j-1), ...
                 img(i-1,j+1),img(i-1,j-1),img(i+1,j),img(i-1,j)];
            if ( (max(a)-min(a))>64 && max(a)>img(i,j) && min(a)<img(i,j))
                img2(i,j)=255;
            else
                img2(i,j)=0;
            end
        end
end

P165

I = imread('lena.jpg');
IMG = rgb2gray(I);
Edge_LoG = edge(IMG, 'log');
imshow(Edge_LoG);
figure
subplot(1,2,1), imshow(IMG);
subplot(1,2,2), imshow(Edge_LoG);

P167

I = double(rgb2gray(imread('lena.jpg')));
figure, imshow(uint8(I))
DoG=fspecial('gaussian',5,0.8)-fspecial('gaussian',5,0.6);
ImageDoG=imfilter(I,DoG,'symmetric','conv');
figure, imshow(ImageDoG)
% threshold = 2
proc_Img1 = ImageDoG;
proc_Img1(find(proc_Img1 < 2))=0;
figure, imshow(proc_Img1)
% threshold = 3
proc_Img2 = ImageDoG;
proc_Img2(find(proc_Img2 < 3))=0;
figure, imshow(proc_Img2)

P172

img = edge(I, 'canny',[0.032,0.08], 3);

P183

RGB= imread('building.jpg');
I = rgb2gray(RGB);
BW = edge(I, 'canny');

[H, T, R]=hough(BW, 'RhoResolution',0.5,'ThetaResolution',0.5);
figure, imshow(imadjust(mat2gray(H)), 'XData', T, ...
'YData', R, 'InitialMagnification', 'fit');
xlabel('\theta'), ylabel('\rho');
axis on; axis normal; hold on;
colormap(hot);
peaks = houghpeaks(H, 15);
figure, imshow(BW);
hold on;
lines = houghlines(BW, T, R, peaks, 'FillGap',25, 'MinLength',15);

max_len = 0;
for k=1:length(lines)
xy = [lines(k).point1; lines(k).point2];
   plot(xy(:,1),xy(:,2),'LineWidth',3,'Color','b');
   plot(xy(1,1),xy(1,2),'x','LineWidth',3,'Color','yellow');
   plot(xy(2,1),xy(2,2),'x','LineWidth',3,'Color','red');

   len = norm(lines(k).point1 - lines(k).point2);
   if ( len > max_len)
      max_len = len;
      xy_long = xy;
   end
end



(代碼發布未完,請待後續...)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.