demo05 of Im2mesh package
demo05 - Thresholds in polyline smoothing
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. No need to install any MATLAB toolboxes when running this demo. Initialize
Before we start, please set folder "Im2mesh_Matlab" as your current folder of MATLAB.
Set default image size.
x = 250; y = 250; width = 250; height = 250;
set(groot, 'DefaultFigurePosition', [x,y,width,height])
% set(groot, 'DefaultFigurePosition', 'factory')
We use the following command to add the folder 'mesh2d-master' to the path of MATLAB.
addpath(genpath('mesh2d-master'))
Import Image
im = imread('Circle.tif');
if size(im,3) == 3; im = rgb2gray( im ); end
imshow( im,'InitialMagnification','fit' );
Zoom in
imshow( im,'InitialMagnification','fit' );
When thresholds are zeros
% thresholds for polyline smoothing
opt.thresh_vert_smooth = 0;
opt.tolerance = 0.01; % do not simplify polyline
[vert,tria,tnum] = im2mesh( im, opt );
Refine triangulation...
-------------------------------------------------------
|ITER.| |CDT1(X)| |CDT2(X)|
-------------------------------------------------------
6 654 1078
10 688 1711
19 695 2637
Refine triangulation...
-------------------------------------------------------
|ITER.| |CDT1(X)| |CDT2(X)|
-------------------------------------------------------
10 924 1078
10 924 1078
20 991 9028
30 997 9363
38 999 9395
Smooth triangulation...
-------------------------------------------------------
|ITER.| |MOVE(X)| |DTRI(X)|
-------------------------------------------------------
10 289 9291
20 7 9291
30 6 9291
plotMeshes(vert,tria,tnum)
Zoom in
plotMeshes(vert,tria,tnum)
We saw some polygons were disappeared when compared to the input image. This disappearing issue is caused by polyline over-smoothing.
We can set thresholds for polyline smoothing to avoid this issue.
Set thresholds for polyline smoothing
% thresholds for polyline smoothing
opt.thresh_vert_smooth = 20;
opt.tolerance = 0.01; % do not simplify polyline
[vert,tria,tnum] = im2mesh( im, opt );
Refine triangulation...
-------------------------------------------------------
|ITER.| |CDT1(X)| |CDT2(X)|
-------------------------------------------------------
6 672 1172
10 702 1604
19 706 2352
Refine triangulation...
-------------------------------------------------------
|ITER.| |CDT1(X)| |CDT2(X)|
-------------------------------------------------------
10 896 1172
10 896 1172
20 926 7192
25 928 7304
Smooth triangulation...
-------------------------------------------------------
|ITER.| |MOVE(X)| |DTRI(X)|
-------------------------------------------------------
10 103 7246
plotMeshes(vert,tria,tnum)
Zoom in
plotMeshes(vert,tria,tnum)
The new boundaries are better.
set(groot, 'DefaultFigurePosition', 'factory')