当前位置:网站首页>[image processing] image skeleton extraction based on central axis transformation with matlab code
[image processing] image skeleton extraction based on central axis transformation with matlab code
2022-07-29 10:59:00 【Matlab scientific research studio】
1 Content introduction
This paper introduces a central axis transformation algorithm . This algorithm corrects the shortcomings of existing algorithms , It can quickly remove redundant information in binary images , Accurately extract the single pixel skeleton of the image , Retain basic features , In particular, slash and circular pad features . A lot of experiments show that , This method reduces the complexity of the image , Only the topology information of the image shape is preserved , Provide an ideal image for subsequent processing , Improve the performance of the whole system .
2 Complete code
% Axis Algorithm Medial Axis Transfrom%% by HPC_ZY 20190802clear; close all; clcload data%% matlab% Find skeletonticskeleton = bwmorph(im,'skeleton',Inf);t1 = toc;% Deburringticskeleton1 = bwmorph(skeleton,'spur',16);t2 = toc;figureshowres(im,skeleton,t1,1,2,1,'matlab library ')showres(im,skeleton1,t2,1,2,2,'matlab library ( Deburring )')%% Iteratively delete% Iterative deletionticskeleton1 = method1(im);t1 = toc;% Iterative deletion ( Lookup table )ticskeleton2 = method2(im);t2 = toc;% Iterative deletion ( simplify )ticskeleton3 = method3(im);t3 = toc;figureshowres(im,skeleton1,t1,1,3,1,' Iterative deletion ')showres(im,skeleton2,t2,1,3,2,' Iterative deletion ( Lookup table )')showres(im,skeleton3,t3,1,3,3,' Iterative deletion ( simplify )')%% ------------function--------------% Iterative deletionfunction skeleton = method1(bw)bw = double(bw); % To non logical type , It is convenient to sum later[M,N] = size(bw);skeleton = bw;deleCount = 1; % Used to record the number of pixels deleted in an iterationwhile deleCount>0% Delete ( Right , Next )deleCount = 0;label = zeros(M,N,'logical');for i = 2:M-1for j = 2:N-1if skeleton(i,j) % If the point is 1, Judge the surrounding pixelsp = [skeleton(i-1,j),skeleton(i-1,j+1),skeleton(i,j+1),skeleton(i+1,j+1),...skeleton(i+1,j),skeleton(i+1,j-1),skeleton(i,j-1),skeleton(i-1,j-1)];Np = sum(p);Tp = length(find(([p(2:end),p(1)]-p) == 1));if Np>1 && Np<7 && Tp==1 && p(1)*p(3)*p(5)==0 && p(7)*p(3)*p(5)==0deleCount = deleCount+1;label(i,j) = 1;endendendendskeleton(label) = 0;% Delete ( Left , On )label = zeros(M,N,'logical');for i = 2:M-1for j = 2:N-1if skeleton(i,j) % If the point is 1, Judge the surrounding pixelsp = [skeleton(i-1,j),skeleton(i-1,j+1),skeleton(i,j+1),skeleton(i+1,j+1),...skeleton(i+1,j),skeleton(i+1,j-1),skeleton(i,j-1),skeleton(i-1,j-1)];Np = sum(p);Tp = length(find(([p(2:end),p(1)]-p) == 1));if Np>1 && Np<7 && Tp==1 && p(1)*p(3)*p(7)==0 && p(1)*p(5)*p(7)==0deleCount = deleCount+1;label(i,j) = 1;endendendendskeleton(label) = 0;endend% Iterative deletion ( Lookup table )function skeleton = method2(bw)bw = double(bw);[M,N] = size(bw);skeleton = bw;% Generate lookup table[List1,List2] = getList1();[x,y] = find(bw);a = min(x);b = max(x);c = min(y);d = max(y);deleCount = 1;mat = [1,2,4,8,16,32,64,128];while deleCount>0deleCount = 0;% Delete ( Right , Next )label1 = zeros(M,N,'logical');for i = a:bfor j = c:dif skeleton(i,j)p = [skeleton(i-1,j),skeleton(i-1,j+1),skeleton(i,j+1),skeleton(i+1,j+1),...skeleton(i+1,j),skeleton(i+1,j-1),skeleton(i,j-1),skeleton(i-1,j-1)];idx = sum(p.*mat)+1;if List1(idx)label1(i,j) = true;deleCount = deleCount+1;endendendendskeleton(label1) = 0;% Delete ( Left , On )label2 = zeros(M,N,'logical');for i = a:bfor j = c:dif skeleton(i,j)p = [skeleton(i-1,j),skeleton(i-1,j+1),skeleton(i,j+1),skeleton(i+1,j+1),...skeleton(i+1,j),skeleton(i+1,j-1),skeleton(i,j-1),skeleton(i-1,j-1)];idx = sum(p.*mat)+1;if List2(idx)label2(i,j) = true;deleCount = deleCount+1;endendendendskeleton(label2) = 0;endend% Iterative deletion ( simplify )function skeleton = method3(bw)bw = double(bw);[M,N] = size(bw);skeleton = bw;% Generate lookup tableList = getList2();% Narrow your search[x,y] = find(bw);a = min(x);b = max(x);c = min(y);d = max(y);% Start the iterationdeleCount = 1;mat = [1,2,4,8,16,32,64,128];while deleCount>0deleCount = 0;label = zeros(M,N,'logical');for i = a:bfor j = c:dif skeleton(i,j)p = [skeleton(i-1,j),skeleton(i-1,j+1),skeleton(i,j+1),skeleton(i+1,j+1),...skeleton(i+1,j),skeleton(i+1,j-1),skeleton(i,j-1),skeleton(i-1,j-1)];idx = sum(p.*mat)+1;if List(idx)label(i,j) = true;deleCount = deleCount+1;endendendendskeleton(label) = 0;endend% Generate lookup tablefunction [List1,List2] = getList1()List1 = zeros(256,1,'logical');List2 = zeros(256,1,'logical');for n = 0:255p = bitget(n,1:8);Np = sum(p);Tp = length(find(([p(2:end),p(1)]-p) == 1));if Np>1 && Np<7 && Tp==1% Right , Nextif p(1)*p(3)*p(5)==0 && p(7)*p(3)*p(5)==0List1(n+1) = true;end% Left , Onif p(1)*p(3)*p(7)==0 && p(1)*p(5)*p(7)==0List2(n+1) = true;endendendend% Generate lookup table ( simplify )function List = getList2()List = zeros(256,1,'logical');for n = 0:255p = bitget(n,1:8);Np = sum(p);Tp = length(find(([p(2:end),p(1)]-p) == 1));if Np>1 && Np<7 && Tp==1if (p(1)*p(3)*p(5)==0 && p(7)*p(3)*p(5)==0)||...(p(1)*p(3)*p(7)==0 && p(1)*p(5)*p(7)==0)List(n+1) = true;endendendend% Show resultsfunction showres(im,skeleton,t,i,j,k,titlename)subplot(i,j,k),imshow(im)hold on[x,y] = find(skeleton);plot(y,x,'r.')title(['\fontsize{16}',titlename])xlabel(['\fontsize{16} Time consuming ( second ):',num2str(t)])end
3 Running results


4 reference
[1] Shi Congwei , Zhao Jieyu , Chang Junsheng . Skeleton feature extraction algorithm based on axis transformation [J]. Computer engineering , 2019, 45(7):9.
About bloggers : Good at intelligent optimization algorithms 、 Neural networks predict 、 signal processing 、 Cellular automata 、 The image processing 、 Path planning 、 UAV and other fields Matlab Simulation , relevant matlab Code problems can be exchanged by private letter .
Some theories cite network literature , If there is infringement, contact the blogger to delete .
边栏推荐
- 2022最新 wifi大师小程序独立版3.0.8
- 如何使用 grep 跨多行查找模式匹配
- Drawing box and ellipse of WPF screenshot control (IV) "imitating wechat"
- SkiaSharp 之 WPF 自绘 弹动小球(案例版)
- Using Riemann sum to calculate approximate integral in R language
- 『面试知识集锦100篇』1.面试技巧篇丨HR的小心思,你真的懂吗?
- Watch the open source summit first | quick view of the sub Forum & Activity agenda on July 29
- 浅谈安科瑞灭弧式智慧用电在养老机构的应用
- 一文搞懂什么是二叉树(二叉树的种类、遍历方式、定义)
- StarRocks 技术内幕:实时更新与极速查询如何兼得
猜你喜欢

Qt 之自定义界面(实现无边框、可移动)

Site data collection -scrapy usage notes

Niuke net brush questions

Peking University open classes are coming! Welcome to the "AI for science" class

ES6 arrow function this points to

北京大学公开课重磅来袭!欢迎走进「AI for Science」课堂

How to use grep to find pattern matching across multiple lines

如何使用“COPY –link”加速 Docker 构建和优化缓存

Alibaba P8 broke out this interview guide for big factories. After reading it, the salary soared by 30K!

How to use grep to display file names and line numbers before matching lines
随机推荐
R language brca MRNA data set analysis
How to realize the function of adding watermark
SkiaSharp 之 WPF 自绘 弹动小球(案例版)
IPV6基础
自采集在线电脑壁纸php源码v2.0自适应端
JS two array objects for merging and de duplication
How to use grep to find pattern matching across multiple lines
大伟 GBase8s游标稳定性读ESQL测试用例
[unity, C #] character keyboard input steering and rotation
If distributed file storage is realized according to integrated Minio
Factoextra: visualization of multivariate statistics
重磅 | 基金会为白金、黄金、白银捐赠人授牌
「PHP基础知识」使用数组保存数据
LeetCode_1049_最后一块石头的重量Ⅱ
Qt 之自定义界面(实现无边框、可移动)
浅谈安科瑞灭弧式智慧用电在养老机构的应用
PyQt5快速开发与实战 6.6 QFormLayout(表单布局) && 6.7 嵌套布局 && 6.8 QSplitter
One click blog building: how to use WordPress plug-in to build a dedicated blog
ES6-箭头函数this指向
QWidget、QDialog、QMainWindow 的异同点