1、查找表操作
函数:makelut
例1:通过查找表修改图中包含的文本
lut = makelut('sum(x(:)) == 4',2);
BW = imread('text.png');
BW2 = applylut(BW,lut);
subplot(121),imshow(BW),title('原始图像');
subplot(122),imshow(BW2),title('查找表修改图像');
效果图如下:
2、形态重构
函数:imreconstruct
3、距离变换
函数:bwdist
例2:求图像的距离矩阵
bw = zeros(5,5); bw(2,2) = 1; bw(4,4) = 1
[D,L] = bwdist(bw)
结果如下:
bw = 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
D = 1.4142 1.0000 1.4142 2.2361 3.1623 1.0000 0 1.0000 2.0000 2.2361 1.4142 1.0000 1.4142 1.0000 1.4142 2.2361 2.0000 1.0000 0 1.0000 3.1623 2.2361 1.4142 1.0000 1.4142 L = 7 7 7 7 7 7 7 7 7 19 7 7 7 19 19 7 7 19 19 19 7 19 19 19 19例3:对图像的各种类型的距离矩阵进行比较
bw = zeros(200,200); bw(50,50) = 1; bw(50,150) = 1;
bw(150,100) = 1;
D1 = bwdist(bw,'euclidean');
D2 = bwdist(bw,'cityblock');
D3 = bwdist(bw,'chessboard');
D4 = bwdist(bw,'quasi-euclidean');
figure
subplot(2,2,1), subimage(mat2gray(D1)), title('Euclidean')
hold on, imcontour(D1)
subplot(2,2,2), subimage(mat2gray(D2)), title('City block')
hold on, imcontour(D2)
subplot(2,2,3), subimage(mat2gray(D3)), title('Chessboard')
hold on, imcontour(D3)
subplot(2,2,4), subimage(mat2gray(D4)), title('Quasi-Euclidean')
hold on, imcontour(D4)
效果图如下:
4、图像的极值处理方法
例4:对简单图像的矩阵求解局部极大值和极小值
A = 10*ones(10,10);
A(2:4,2:4) = 22;
A(6:8,6:8) = 33;
A(2,7) = 44;
A(3,8) = 45;
A(4,9) = 44;
regmax = imregionalmax(A)
结果如下:
regmax =
0 0 0 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0 0 0
0 1 1 1 0 0 0 1 0 0
0 1 1 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 0 0
0 0 0 0 0 1 1 1 0 0
0 0 0 0 0 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
例5:找到矩阵中数值大于其邻域像素值2个单位的局部最大值
B=imextendedmax(A,2)
结果如下:
B =
0 0 0 0 0 0 0 0 0 0
0 1 1 1 0 0 1 0 0 0
0 1 1 1 0 0 0 1 0 0
0 1 1 1 0 0 0 0 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 1 1 0 0
0 0 0 0 0 1 1 1 0 0
0 0 0 0 0 1 1 1 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
例6:寻找图像中灰度变化大于15的极大值
原始图像:
A =
10 10 10 10 10 10 10 10 10 10
10 22 22 22 10 10 44 10 10 10
10 22 22 22 10 10 10 45 10 10
10 22 22 22 10 10 10 10 44 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 33 33 33 10 10
10 10 10 10 10 33 33 33 10 10
10 10 10 10 10 33 33 33 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
B=imhmax(A,15)
结果如下:
B =
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 30 10 10 10
10 10 10 10 10 10 10 30 10 10
10 10 10 10 10 10 10 10 30 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 18 18 18 10 10
10 10 10 10 10 18 18 18 10 10
10 10 10 10 10 18 18 18 10 10
10 10 10 10 10 10 10 10 10 10
10 10 10 10 10 10 10 10 10 10
例7:imimposemin函数