demo12 of Im2mesh package
demo12 - Function pixelMesh (pixel-based quadrilateral mesh)
Dependencies
No need to install any MATLAB toolboxes for demo12.
Setup
Before we start, please set folder "Im2mesh_Matlab" as your current folder of MATLAB.
Set default image size (optional).
x = 250; y = 250; width = 250; height = 250;
set(groot, 'DefaultFigurePosition', [x,y,width,height])
% set(groot, 'DefaultFigurePosition', 'factory')
pixelMesh
pixelMesh is a function used to generate pixel-based quadrilateral mesh. It’s written by me many years ago. It’s for some special applications.
Let's start demo. First, we'll use function pixelMesh to generate mesh. In the next step, we'll export the mesh.
Import image Circle.tif.
im = imread('Circle.tif');
if size(im,3) == 3; im = rgb2gray( im ); end
imshow( im,'InitialMagnification','fit' );
Generate mesh.
[ vert, ele, tnum, vert2, ele2 ] = pixelMesh( im );
plotMeshes( vert, ele, tnum )
Zoom in.
plotMeshes( vert, ele, tnum )
Outputs of pixelMesh
vert is mesh nodes (for linear element)
ele is mesh elements (for linear element)
tnum is label of phase
vert2 is mesh nodes (for quadratic element)
ele2 is mesh elements (for quadratic element)
Export mesh
We have demonstrated how to do this in demo03
Scale node coordinates
Setup scale.
% physical dimensions of a pixel in the image
Scale node coordinates according to dx.
% scale node coordinates of linear elements
% scale node coordinates of quadratic elements
Export mesh as bdf file (Nastran bulk data)
file_name = 'test_2d.bdf';
printBdf2d( vert, ele, tnum, [], precision, file_name );
printBdf2d Done! Check the bdf file!
Export mesh as inp file (Abaqus)
Linear element
file_name = 'test_linear.inp';
printInp2d( vert, ele, tnum, ele_type, precision, file_name );
printInp2d Done! Check the inp file!
Quadratic element
file_name = 'test_quadratic.inp';
printInp2d( vert2, ele2, tnum, ele_type, precision, file_name );
printInp2d Done! Check the inp file!
Phase selection before meshing
We can specify phase selection before meshing. See demo09 for example.
opt.select_phase = [2 3 4];
[ vert, ele, tnum, vert2, ele2 ] = pixelMesh( im, opt );
plotMeshes( vert, ele, tnum )
Zoom in.
plotMeshes( vert, ele, tnum )
set(groot, 'DefaultFigurePosition', 'factory')