demo08 of Im2mesh package
demo08 - Function plotMeshes
Note
I suggest familiarizing yourself with Im2mesh_GUI before learning Im2mesh package. With graphical user interface, Im2mesh_GUI will help you better understand the workflow and parameters of Im2mesh package.
If you are using Im2mesh package in MATLAB, you need to install MATLAB Image Processing Toolbox and Mapping Toolbox because Im2mesh package use a few functions in these toolboxes.
Setup
Before we start, please set folder "Im2mesh_Matlab" as your current folder of MATLAB.
Set default image size.
x = 250; y = 250; width = 300; height = 300;
set(groot, 'DefaultFigurePosition', [x,y,width,height])
% set(groot, 'DefaultFigurePosition', 'factory')
Function im2mesh use a mesh generator called MESH2D (developed by Darren Engwirda). We can use the following command to add the folder 'mesh2d-master' to the path of MATLAB. addpath(genpath('mesh2d-master'))
Overview
We will demostrate function plotMeshes in this demo.
There are 3 typical usage of function plotMeshes
% plotMeshes( vert, ele, tnum );
% plotMeshes( vert, ele, tnum, color_code );
% plotMeshes( vert,ele,tnum, color_code, opt )
The meanings of the input arguments are as follows:
color_code: Color code for selecting colormap. Interger. Value: 0-10. Default value: 0
0: grayscale, 1: lines, 2: parula, 3: turbo, 4: jet, 5: hot, 6: cool, 7: summer, 8: winter, 9: bone, 10: pink.
opt: a structure array. It is the extra options for plotMeshes. It stores extra parameter settings for plotMeshes.
opt.mode: display mode. Value: 1 or 2.
opt.wid: line width of the plotted edges. Default value: 0.5
opt.alpha: edge line transparency. It's a scalar value in range [0,1]. Default value: 0.5
opt.beta: brightness adjustment of colormap. [-1, 1]. Default value: 0
opt.tf_gs: Boolean value. Whether to use graphics smoothing when plotting. Default value: 1
opt.q_thresh: threshold for mesh quality. Those elements with mesh quality lower than opt.q_thresh will be highlighted. Default value: 0
Import image
Let's start demo. Import image.
if size(im,3) == 3; im = rgb2gray( im ); end
imshow( im,'InitialMagnification','fit' );
Generate mesh
[ vert, tria, tnum, vert2, tria2 ] = im2mesh( im, opt );
Refine triangulation...
-------------------------------------------------------
|ITER.| |CDT1(X)| |CDT2(X)|
-------------------------------------------------------
9 125 108
10 125 218
17 158 433
Refine triangulation...
-------------------------------------------------------
|ITER.| |CDT1(X)| |CDT2(X)|
-------------------------------------------------------
10 271 108
18 297 108
20 302 830
30 310 2114
33 311 2126
Smooth triangulation...
-------------------------------------------------------
|ITER.| |MOVE(X)| |DTRI(X)|
-------------------------------------------------------
10 84 2108
Plot mesh
plotMeshes( vert, tria, tnum )
Select colormap
plotMeshes( vert,tria,tnum, color_code )
Set display mode
When opt.mode=1, plot faces and edges. Slower.
When opt.mode=2, plot edges only. Faster.
Default value: 1
plotMeshes( vert,tria,tnum, color_code, opt )
Other settings
When the mesh data is huge, I usually set 'opt.alpha' to 0.2-0.3.
plotMeshes( vert,tria,tnum, color_code, opt )
Highlight low quality elements
Those elements with mesh quality lower than 'opt.q_thresh' will be highlighted.
You can set color_code to 0 to faciliate the visualization.
plotMeshes( vert,tria,tnum, color_code, opt )
set(groot, 'DefaultFigurePosition', 'factory')