cnblogsnearby
膨胀 = 加长、变粗 
映射并平移后的结构元素至少与原二值图的某些部分重叠。
函数imdialate
构造结构元素strel(shape, parameters)
  1. %% 膨胀的应用
  2. A = imread(\'broken_text.tif\');
  3. B = [0 1 0; 1 1 1; 0 1 0]; % 结构元素
  4. A2 = imdilate(A, B); % imdilate函数
  5. figure;
  6. subplot(1,2,1),imshow(A);
  7. subplot(1,2,2), imshow(A2);


腐蚀 = 收缩、细化
平移的结构元素与原二值图的背景并不叠加。
函数imerode
  1. %% 腐蚀的应用
  2. A = imread(\'wirebond_mask.tif\');
  3. se = strel(\'disk\', 10);
  4. A2 = imerode(A, se);
  5. figure;
  6. subplot(1,2,1), imshow(A);
  7. subplot(1,2,2), imshow(A2);



开运算:
A被B开 = B在A内完全匹配的平移的并集。 A被B腐蚀后再用B来膨胀腐蚀结果。
平滑轮廓,断开狭窄的连接,去掉细小突出部分。
函数imopen(A, B);



闭运算:
A被B闭 = 所有不与A重叠的B的平移的并集。 A被B膨胀后再用B来腐蚀膨胀结果。
将狭窄缺口连接起来形成细长弯口,填充比结构元素小的洞。
函数imclose(A, B);
  1. %% imopen imclose的应用
  2. A = imread(\'shapes.tif\');
  3. se = strel(\'square\', 20);
  4. A2 = imopen(A, se);
  5. figure;
  6. % subplot(1,2,1), imshow(A);
  7. % subplot(1,2,2), imshow(A2);
  8. A3 = imclose(A, se);
  9. imshow(A3);



开闭结合去除噪声
  1. %% 开闭结合
  2. f = imread(\'noisy_fingerprint.tif\');
  3. se = strel(\'square\', 3);
  4. fo = imopen(f, se); % 先做开操作
  5. foc = imclose(fo, se); % 后做闭操作
  6. figure;
  7. subplot(1,3,1), imshow(f);
  8. subplot(1,3,2), imshow(fo);
  9. subplot(1,3,3), imshow(foc);


左原图, 中开运算后的图像(消除了杂散点,但引入了缺口), 右先开后闭结果

函数bwmorph
g = bwmorph(f, operation, n)
f:输入二值图像
operation:指定期望操作的字符串 常用操作:close dialate erode fill open 
n:指定将被重复的操作次数(可选)


由重构做开运算
fe = imerode(f, se);
fr = imreconstruct(fe, f); 
  1. %% 由重构做开运算
  2. % imreconstruct(marker, mask)
  3. % marker标记,变换的开始; mask约束变换过程,markermask的子集。
  4. f = imread(\'book_text.tif\');
  5. fe = imerode(f, ones(51, 1));
  6. fo = imopen(f, ones(51, 1));
  7. fr = imreconstruct(fe, f);
  8. figure;
  9. subplot(2,2,1), imshow(f), title(\'原图\');
  10. subplot(2,2,2), imshow(fe), title(\'腐蚀后图像\');
  11. subplot(2,2,3), imshow(fo), title(\'开运算后图像\');
  12. subplot(2,2,4), imshow(fr), title(\'重构后图像\');



填充孔洞
填充二值图像或者灰度图像的孔洞,对于二值图像,用背景像素填充;对于灰度图像,用较亮像素包围的暗像素填充。
g = imfill(f, \'holes\');
  1. % 填充孔洞
  2. %f = imread(\'gt.tif\');
  3. fh = imfill(f, \'holes\');
  4. figure;
  5. subplot(1,2,1), imshow(f), title(\'原图\');
  6. subplot(1,2,2), imshow(fh), title(\'填充后图像\');



清除边界对象
清除图像中比周围对象更亮且与图像边界相连接的结构。
g = imclearborder(f, conn); conn默认八连接
  1. % 清除边界对象
  2. fc = imclearborder(f); % 默认四连接
  3. figure;
  4. subplot(1,2,1), imshow(f), title(\'原图\');
  5. subplot(1,2,2), imshow(fc), title(\'清除边界后图像\');











分类:

技术点:

相关文章:

  • 2021-04-11
  • 2021-06-18
  • 2021-09-23
  • 2021-12-15
  • 2021-06-17
  • 2022-12-23
猜你喜欢
  • 2021-12-15
  • 2021-07-21
  • 2022-01-20
  • 2021-09-18
  • 2022-12-23
  • 2022-12-23
  • 2021-06-25
相关资源
相似解决方案