1
f = imread("C:\Users\madster\Downloads\DIP3E_Original_Images_CH10\QQ截图20221118163534.png");
B = bwboundaries(f,'noholes');
numel(B) %用于找出默认8连接的边界
b = cat(1,B{:});
[M,N] = size(f);
image = 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);
imageNumberedBoundaries = imageBoundaries.*L; %显示有限的边界
f = imread("C:\Users\madster\Downloads\DIP3E_Original_Images_CH10\QQ截图20221118163534.png");
B = bwboundaries(f,'noholes');
numel(B) %用于找出默认8连接的边界
b = cat(1,B{:});
[M,N] = size(f);
image = 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);
imageNumberedBoundaries = imageBoundaries.*L; %显示有限的边界
bR = cat(1,B{:}); %显示所有的边界
imageBoundaries = bound2im(bR,M,N);
imageNumberedBoundaries = imageBoundaries.*L %显示所有的有限的边界
find(A(:,1)) %由B{1}得到的闭合边界数
find(A(1,:)) %由B{1}得到的边界数
A %A中的元素
full(A) %整个矩阵
2
f = imread("C:\Users\madster\Downloads\DIP3E_CH11_Original_Images\Fig1105(a)(noisy_stroke).tif");
subplot(231),imshow(f),title('原始图像');
h = fspecial('average', 9);
g = imfilter(f, h ,'replicate');
subplot(232),imshow(g),title('9×9平均模板处理结果');
gB = im2bw(g,0.5);
subplot(233),imshow(gB),title('阈值处理后结果');
B = bwboundaries(gB,'noholes');
d = cellfun('length',B);
[max_d, k] = max(d);
b = B{1};
[M N] = size(g);
g = bound2im(b,M,N,min(b(:,1)),min(b(:,2)));
subplot(234),imshow(g),title('二值图像的边界图像');
[s,su] = bsubsamp(b,50);
g2 = bound2im(s,M,N);
subplot(235),imshow(g2),title('自取样的边界图像');
cn = connectpoly(s(:, 1),s(:, 2));
g3 = bound2im(cn,M,N,min(cn(:,1)),min(cn(:,2)));
subplot(236),imshow(g3),title('对上图的点进行连接');
3
f = imread("C:\Users\madster\Downloads\DIP3E_Original_Images_CH10\20221118170801.png");
subplot(321),imshow(f),title('原始图像');
B = bwboundaries(f,4,'noholes');
b = B{1};
[M,N] = size(f);
bim = bound2im(b,M,N);
subplot(322),imshow(bim),title('4连接边界的图像')
[X,Y] = im2minperpoly(f,2);
b2 = connectpoly(X,Y);
bCcellsize2 = bound2im(b2,M,N);
subplot(323),imshow(bCcellsize2),title('使用方形且大小为2的单元得到的MPP');
[X,Y] = im2minperpoly(f,3);
b3 = connectpoly(X,Y);
bCcellsize3 = bound2im(b3,M,N);
subplot(324),imshow(bCcellsize3),title('使用方形且大小为3的单元得到的MPP');
[X,Y] = im2minperpoly(f,16);
b16 = connectpoly(X,Y);
bCcellsize16 = bound2im(b16,M,N);
subplot(325),imshow(bCcellsize16),title('使用方形且大小为16的单元得到的MPP');
[X,Y] = im2minperpoly(f,32);
b32 = connectpoly(X,Y);
bCcellsize32 = bound2im(b32,M,N);
subplot(326),imshow(bCcellsize32),title('使用方形且大小为32的单元得到的MPP');
4
f = imread("C:\Users\madster\Downloads\DIP3E_CH11_Original_Images\Fig1108(a)(mapleleaf).tif");
subplot(321),imshow(f),title('原始图像');
B = bwboundaries(f,4,'noholes');
b = B{1};
[M,N] = size(f);
bim = bound2im(b,M,N);
subplot(322),imshow(bim),title('4连接边界的图像')
[X,Y] = im2minperpoly(f,2);
b2 = connectpoly(X,Y);
bCcellsize2 = bound2im(b2,M,N);
subplot(323),imshow(bCcellsize2),title('使用方形且大小为2的单元得到的MPP');
[X,Y] = im2minperpoly(f,3);
b3 = connectpoly(X,Y);
bCcellsize3 = bound2im(b3,M,N);
subplot(324),imshow(bCcellsize3),title('使用方形且大小为3的单元得到的MPP');
[X,Y] = im2minperpoly(f,16);
b16 = connectpoly(X,Y);
bCcellsize16 = bound2im(b16,M,N);
subplot(325),imshow(bCcellsize16),title('使用方形且大小为16的单元得到的MPP');
[X,Y] = im2minperpoly(f,32);
b32 = connectpoly(X,Y);
bCcellsize32 = bound2im(b32,M,N);
subplot(326),imshow(bCcellsize32),title('使用方形且大小为32的单元得到的MPP');
5
f1 = imread("C:\Users\madster\Downloads\DIP3E_CH11_Original_Images\Fig1111(b)(square).tif");
subplot(221),imshow(f1),title('非规则正方形');
[srad1,sang1,S1] = specxture(f1);
subplot(223),plot(sang1),title('S(θ)图像');
figure(2)
f2 = imread("C:\Users\madster\Downloads\DIP3E_CH11_Original_Images\Fig1111(a)(triangle).tif");
subplot(221),imshow(f2),title('非规则三角形');
[srad2,sang2,S2] = specxture(f2);
subplot(223),plot(sang2),title('S(θ)图像');
6
f = imread("C:\Users\madster\Downloads\DIP3E_Original_Images_CH10\20221118194856.png");
subplot(231),imshow(f),title('原始的图像');
f=im2double(f); %不是二值图像
h = fspecial('gaussian',25,15); %加入高斯噪声
g = imfilter(f,h,'replicate'); %用高斯空域模板平滑后的图像
subplot(232),imshow(g),title('用高斯空域模板平滑后的图像');
g = im2bw(g,1.5*graythresh(g)); %对平滑后图像进行阈值处理
subplot(233),imshow(g),title('平滑后图像进行阈值处理');
s = bwmorph(g,'skel',Inf);
subplot(234),imshow(s),title('骨骼处理后得到的图像');
s1 = bwmorph(s,'spur',8);
subplot(235),imshow(s1),title('刺状突起去除8次后骨骼化得到的图像');
s2 = bwmorph(s,'spur',7);
subplot(236),imshow(s2),title('刺状突起去除7次后骨骼化得到的图像');
7
f = imread("C:\Users\madster\Downloads\DIP3E_Original_Images_CH10\Fig1001(f)(region_split_merge_image).tif");
subplot(331),imshow(f),title('原始图像');
f=im2double(f);
h=fspecial('gaussian',15,9);
g=imfilter(f,h,'replicate');
g=im2bw(g,0.7); %变成二值图像
subplot(332),imshow(g),title('阈值处理后');
b=boundaries(g);
b=b{1};
bim=bound2im(b,688,540); %688×540是图像的尺寸
subplot(333),imshow(bim),title('提取的边界图');
z=frdescp(b);%对边界坐标b进行傅里叶变换系数(有多少个点就有多少个系数),将b的坐标点看成是复平面中的某个复数
z546=ifrdescp(z,546);%用50%的描述子进行逆变换
z546im=bound2im(z546,688,540);
subplot(334),imshow(z546im),title('546个描述子恢复后');
z110=ifrdescp(z,110);%用10%的描述子进行逆变换
z110im=bound2im(z110,688,540);
subplot(335),imshow(z110im),title('110个描述子恢复后');
z56=ifrdescp(z,56);%用5%的描述子进行逆变换
z56im=bound2im(z56,688,540);
subplot(336),imshow(z56im),title('56个描述子恢复后');
z28=ifrdescp(z,28);%用2.5%的描述子进行逆变换
z28im=bound2im(z28,688,540);
subplot(337),imshow(z28im),title('28个描述子恢复后');
z14=ifrdescp(z,14);%用1.25%的描述子进行逆变换
z14im=bound2im(z14,688,540);
subplot(338),imshow(z14im),title('14个描述子恢复后');
z8=ifrdescp(z,8);%用0.70%的描述子进行逆变换
z8im=bound2im(z8,688,540);
subplot(339),imshow(z8im),title('8个描述子恢复后');
8
f = imread("C:\Users\madster\Downloads\DIP3E_Original_Images_CH04\Fig0438(a)(bld_600by600).tif");
subplot(331),imshow(f),title('原始图像');
CH = cornermetric(f,'Harris');
CH(CH < 0) = 0;
CH = mat2gray(CH);
subplot(332),imshow(imcomplement(CH),[]),title('Harris的原始输出结果');
CM = cornermetric(f,'MinimumEigenvalue');
CM = mat2gray(CM);
subplot(333),imshow(imcomplement(CH)),title('最小特征值检测器的输出结果');
hH = imhist(CH);
subplot(334),imhist(CH),title('Harris的原始输出直方图');
hM = imhist(CM);
subplot(335),imhist(CM),title('最小特征值检测器的输出直方图');
TH = percentile2i(hH,0.9945);
TM = percentile2i(hM,0.9970);
cpH = cornerprocess(CH,TH,1);
subplot(336),imshow(cpH),title('Harris的原始输出使用函数后的输出');
cpM = cornerprocess(CM,TM,1);
subplot(337),imshow(cpM),title('最小特征值原始输出使用函数后的输出');
[xH yH] = find(cpH);
subplot(338),imshow(f),title('Harris:包含在原始图像上的拐角点');
hold on
plot(yH(:)',xH(:)','wo')
[xM yM] = find(cpM);
subplot(339),imshow(f),title('最小特征值:包含在原始图像上的拐角点');
hold on
plot(yM(:)',xM(:)','wo')
9
f1 = imread("C:\Users\madster\Downloads\DIP3E_CH11_Original_Images\Fig1128(a)(superconductor-smooth-texture)-DO NOT SEND.tif");
f2 = imread("C:\Users\madster\Downloads\DIP3E_CH11_Original_Images\Fig1128(b)(cholesterol-rough-texture)-DO NOT SEND.tif");
f3 = imread("C:\Users\madster\Downloads\DIP3E_CH11_Original_Images\Fig1128(c)(microporcessor-regular texture)-DO NOT SEND.tif");
subplot(131),imshow(f1),title('原始图像一');
subplot(132),imshow(f2),title('原始图像二');
subplot(133),imshow(f3),title('原始图像三');
t1 = statxture(f1,6); %统计纹理的度量
t2 = statxture(f2,6); %统计纹理的度量
t3= statxture(f3,6); %统计纹理的度量
figure(2)
subplot(131),imhist(f1),title('原始图像一直方图');
subplot(132),imhist(f2),title('原始图像二直方图');
subplot(133),imhist(f3),title('原始图像三直方图');
10
f1 = imread("C:\Users\madster\Downloads\DIP3E_CH11_Original_Images\Fig1130(a)(uniform_noise).tif");
f2 = imread("C:\Users\madster\Downloads\DIP3E_CH11_Original_Images\Fig1130(b)(sinusoidal).tif");
f3 = imread("C:\Users\madster\Downloads\DIP3E_CH11_Original_Images\Fig1130(c)(cktboard_section).tif");
subplot(311),imshow(f1),title('第一幅图像');
subplot(312),imshow(f2),title('第二幅图像');
subplot(313),imshow(f3),title('第三幅图像');
G2 = graycomatrix(f2,'NumLevels',256); %对第二幅图进行计算其描述子
G2n = G2/sum(G2(:));
stats2 = graycoprops(G2,'all');
maxProbability2 = max(G2n(:)) %最大概率
contrast2 = stats2.Contrast %相邻像素间灰度对比度的度量
corr2 = stats2.Correlation %相关性
energy2 = stats2.Energy % 能量
hom2 = stats2.Homogeneity %同质
for I = 1:size(G2n,1);
sumcols(I) = sum(-G2n(I,1:end).*log2(G2n(I,1:end)+eps));
end
figure(2)
entropy2 = sum(sumcols) %熵
offsets = [zeros(50,1) (1:50)'];
G1 = graycomatrix(f1,'Offset',offsets);
stats1 = graycoprops(G1,'Correlation');
subplot(131),plot([stats1.Correlation]);
xlabel('Horizontal Offset'),ylabel('Correlation')
G2 = graycomatrix(f2,'Offset',offsets);
stats2 = graycoprops(G2,'Correlation');
subplot(132),plot([stats2.Correlation]);
xlabel('Horizontal Offset'),ylabel('Correlation')
G3 = graycomatrix(f3,'Offset',offsets);
stats3 = graycoprops(G3,'Correlation');
subplot(133),plot([stats3.Correlation]);
xlabel('Horizontal Offset'),ylabel('Correlation')
11 12
f1 = imread("C:\Users\madster\Downloads\DIP3E_CH11_Original_Images\Fig1135(a)(random_matches).tif");
subplot(221),imshow(f1),title('随机火柴的图像');
[srad1,sang1,S1] = specxture(f1);
subplot(222),plot(srad1),title('S(r)图像');
subplot(223),plot(sang1),title('S(θ)图像');
subplot(224),imshow(S1),title('随机火柴的频谱图像');
figure(2)
f2 = imread("C:\Users\madster\Downloads\DIP3E_CH11_Original_Images\Fig1135(b)(ordered_matches).tif");
subplot(221),imshow(f2),title('整齐排列的火柴图像');
[srad2,sang2,S2] = specxture(f2);
subplot(222),plot(srad2),title('S(r)图像');
subplot(223),plot(sang2),title('S(θ)图像');
subplot(224),imshow(S2),title('整齐火柴的频谱图像');