利用圖像識(shí)別技術(shù)進(jìn)行全自動(dòng)非結(jié)構(gòu)化網(wǎng)格劃分
瀏覽:4282 收藏:5
今天給大家分享一個(gè)很有意思的劃分網(wǎng)格工具:可以根據(jù)圖像進(jìn)行非結(jié)構(gòu)化劃分網(wǎng)格。
代碼來源:https://github.com/otvam/mesh_from_bitmap_matlab
若Github訪問速度較慢,也可以在公眾號(hào)后臺(tái)回復(fù):圖像識(shí)別劃分網(wǎng)格,便可自動(dòng)獲取壓縮包。
示例效果
先看看一些效果圖吧:
代碼介紹
主函數(shù)文件
用戶可通過調(diào)節(jié)結(jié)構(gòu)體里面的參數(shù)進(jìn)行圖像的拾取及單元尺寸的控制,需要注意有以下幾點(diǎn):
-
在進(jìn)行選擇圖像時(shí),只能選擇黑、白兩種顏色的圖像,即黑色區(qū)域?yàn)閯澐志W(wǎng)格的區(qū)域; -
圖像通過 imread函數(shù)進(jìn)行讀取,支持 bmp、 png、 jpg格式; -
h_min與h_max分別控制單元的最小尺寸與最大尺寸; -
h_growth表示單元尺寸的增長(zhǎng)率,具體含義我解釋不清楚,反正,h_growth越大,網(wǎng)格越稀疏,h_growth越小,網(wǎng)格越密集; -
scale與simplify_tol也是控制網(wǎng)格局部加密的函數(shù),會(huì)根據(jù)內(nèi)外輪廓進(jìn)行適當(dāng)局部加密。scale越大網(wǎng)格越密集,simplify_tol越小越密集,用戶可自己慢慢調(diào)節(jié),知道調(diào)整至自己想要的效果,具體含義還需自己多玩玩。
%% data_img
% scale 越大越密集
% simplify_tol 越小越密集
img_data = struct(...
'img', imread('model.bmp'),...
'scale', 0.6,...
'simplify_tol',0.1,...
'h_growth', 1.2,...
'h_min', 0.1,...
'h_max', 20.0...
);
%% run
mesh = get_mesh(img_data);
%% plot
fig = figure()
set(fig,'Color','white')
pdemesh(mesh)
axis('tight')
axis('off')
end
getmesh函數(shù)
function mesh = get_mesh(img_data)
% extract
img = img_data.img;
scale = img_data.scale;
simplify_tol = img_data.simplify_tol;
h_growth = img_data.h_growth;
h_min = img_data.h_min;
h_max = img_data.h_max;
% transform the image into binary
img = rgb2gray(img);
img = imbinarize(img);
img = img==false;
% rotate coordinate
img = fliplr(img.');
% get the contours of the image
c_cell = contour_create(img, scale);
c_cell = contour_simplify(c_cell, simplify_tol);
% create the 2d triangulation
mesh = triangulation_create(c_cell, h_growth, h_min, h_max);
導(dǎo)入Abaqus
既然木木長(zhǎng)期玩轉(zhuǎn)Abaqus,那肯定是要導(dǎo)入到Abaqus中滴!
需要在原有數(shù)據(jù)結(jié)構(gòu)中做一些改變,并輸出至txt文件中,方便inp引用,具體代碼如下:
clear;
mesh = run_example();
Node = mesh.Nodes;
Node = Node';
Element = mesh.Elements;
Element = Element';
elementIDs = (1:size(Element, 1))';
elementDataWithIDs = [elementIDs, Element];
nodeIDs = (1:size(Node, 1))';
nodeDataWithIDs = [nodeIDs, Node];
fileName = 'Element.txt';
dlmwrite(fileName, elementDataWithIDs, 'delimiter', ',');
fileName = 'Node.txt';
dlmwrite(fileName, nodeDataWithIDs, 'delimiter', ',');
inp文件做如下修改,節(jié)點(diǎn)、單元數(shù)據(jù)修改為:*include,input = .\Node.txt和*include,input = .\Element.txt,記得將文本文件放在Abaqus工作目錄下。
*Node
*include,input = .\Node.txt
*Element, type=CPS3
*include,input = .\Element.txt
然后就可以導(dǎo)入進(jìn)Abaqus,進(jìn)行有限元的一些操作了,效果如下:
令我感到驚奇的是,我怕生成的網(wǎng)格看上去好看,質(zhì)量有的不太行,于是我又進(jìn)行了網(wǎng)格質(zhì)量檢查,發(fā)現(xiàn)0警告,0錯(cuò)誤!!!,只能說:牛批!!!
運(yùn)行了兩個(gè)案例,效果如下,供大家娛樂~
技術(shù)鄰APP
工程師必備
工程師必備
- 項(xiàng)目客服
- 培訓(xùn)客服
- 平臺(tái)客服
TOP
2
5




















