数字图像处理MATLAB版人教版第八章例题

本文详细介绍了使用MATLAB进行数字图像处理的多个例子,包括边界提取、区域边界处理、傅里叶描绘子、角点检测、纹理分析等。通过实例代码展示了函数如bwboundaries、im2minperpoly、cornermetric、regionprops等在图像处理中的应用,以及如何利用主分量分析进行图像调整。
摘要由CSDN通过智能技术生成

例8.1使用函数bwboundaries和bound2im.

代码如下:
f = [
0 0 0 0 0 0 0 0 0 0 0 0 0 0;
0 1 1 1 1 1 1 1 1 1 1 1 1 0;
0 1 1 1 1 1 1 1 1 1 1 1 1 0;
0 1 1 0 0 0 0 0 0 0 0 1 1 0;
0 1 1 0 1 1 1 1 1 1 0 1 1 0;
0 1 1 0 1 1 1 1 1 1 0 1 1 0;
0 1 1 0 1 1 0 0 1 1 0 1 1 0;
0 1 1 0 1 1 0 0 1 1 0 1 1 0;
0 1 1 0 1 1 1 1 1 1 0 1 1 0;
0 1 1 0 1 1 1 1 1 1 0 1 1 0;
0 1 1 0 0 0 0 0 0 0 0 1 1 0;
0 1 1 1 1 1 1 1 1 1 1 1 1 0;
0 1 1 1 1 1 1 1 1 1 1 1 1 0;
0 0 0 0 0 0 0 0 0 0 0 0 0 0
];
B = bwboundaries(f, ‘noholes’);
numel(B)
b = cat(1, B{:});
[M, N] = size(f);
imgae = bound2im(b, M, N)
[B, L, NR, A] = bwboundaries(f);
numel(B)
numel(B) - NR
bR = cat(1, B{1:2}, B{4});
imageBoundaries = bound2im(bR, M, N);
imageNumveredBoundaries = imageBoundaries.*L
bR = cat(1, B{:});
imageBoundaries = bound2im(bR, M, N);
imageNumberedBoundaries = imageBoundaries.*L
find(A(:,1))
find(A(1,:))
A
full(A)
结果图:
在这里插入图片描述

例8.2弗雷曼链码及其某些变化

代码:
f = imread(‘C:\NO.8\DIP3E_CH11_Original_Images\Fig1105(a)(noisy_stroke).tif’);
figure;subplot(2,2,1),imshow(f),title(‘(a)带噪原图’);

h = fspecial(‘average’, 9);
g = imfilter(f, h ,‘replicate’); % 因为感兴趣的是粗边界,所以进行平滑处理可有效抑制噪声
subplot(2,2,2),imshow(g),title(‘(b)均值模板平滑处理结果’);

T = graythresh(g);
gB = imbinarize(g,T); % 使用Ostu方法对图像进行阈值处理
subplot(2,2,3),imshow(gB),title(‘©Ostu方法对平滑图像阈值的结果’);

B =bwboundaries(gB,‘noholes’); % 提取图像边界
d = cellfun(‘length’,B);
[max_d, k] = max(d); % k是最长边界对应的区域数
b = B{k(1)}; % 得到最长边界的坐标

[M,N] = size(g);
g = bound2im(b,M,N); % 构建最长边界对应的二值图像
subplot(2,2,4),imshow(g),title(‘(d)图c的最长外部边界’);

[s,su] = bsubsamp(b,50); % 对最长边界二次取样,节点间距为50像素(约为图像宽度的10%,图像宽度为570)
g2 = bound2im(s,M,N); % 构建取样后的边界对应的二值图像
figure;imshow(g2),title(‘(e)对最长边界取样后的边界图像’);

cn = connectpoly(s(:, 1),s(:, 2)); % 对取样后边界进行连接
g3 = bound2im(cn,M,N); % 将感兴趣的边界显示为二值图像
figure; imshow(g3),title(‘(f)对取样后的点进行连接’);

c = fchcode(su); %产生链码
c.x0y0
c.fcc
c.mm
c.diff
c.diffmm
结果图:
在这里插入图片描述

例8.3得到包围一个区域的边界的细胞组合体

代码:
f=imread(‘C:\NO.8\matlab教材示例图片\1.tif’);
g=bwperim(f,8);
Q=qtdecomp(g,0,2);
R=imfill(gF,‘holes’)&g;
B=bwboundaries(R,4,‘holes’);
b=B{1};%There is only one boundary in this case.
IN=inpolygon(X,Y,xv,yv)
结果图:
在这里插入图片描述

例8.4使用函数 im2minperpoly

代码:
clc,clear,close all;
f = imread(‘C:\NO.8\DIP3E_CH11_Original_Images\Fig1108(a)(mapleleaf).tif’);
figure
subplot(321),imshow(f)
B = bwboundaries(f, 4, ‘noholes’);
b = B{1};
[M, N] = size(f);
bOriginal = bound2im(b, M, N);
subplot(322),imshow(bOriginal)
[X, Y] = im2minperpoly(f, 2);
b2 = connectpoly(X, Y);
bCellsize2 = bound2im(b2, M, N);
subplot(323),imshow(bCellsize2)

[X, Y] = im2minperpoly(f, 3);
b2 = connectpoly(X, Y);
bCellsize2 = bound2im(b2, M, N);
subplot(324),imshow(bCellsize2)

[X, Y] = im2minperpoly(f, 4);
b2 = connectpoly(X, Y);
bCellsize2 = bound2im(b2, M, N);
subplot(325),imshow(bCellsize2)

[X, Y] = im2minperpoly(f, 8);
b2 = connectpoly(X, Y);
bCellsize2 = bound2im(b2, M, N);
subplot(326),

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值