demo06 of Im2mesh package
demo06 - 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.
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 = 250; height = 250;
set(groot, 'DefaultFigurePosition', [x,y,width,height])
% set(groot, 'DefaultFigurePosition', 'factory')
Circle
Let's start demo. Import image Circle.tif.
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.threshold_num_turning = 0;
opt.threshold_num_vert_Smo = 0;
opt.tolerance = 0.01; % do not simplify polyline
[vert,tria,tnum] = im2mesh( im, opt );
Refine triangulation...
-------------------------------------------------------
|ITER.| |CDT1(X)| |CDT2(X)|
-------------------------------------------------------
6 683 1094
10 715 1737
20 723 2772
20 723 2772
Refine triangulation...
-------------------------------------------------------
|ITER.| |CDT1(X)| |CDT2(X)|
-------------------------------------------------------
10 945 1094
10 945 1094
20 1011 9263
25 1016 9544
Smooth triangulation...
-------------------------------------------------------
|ITER.| |MOVE(X)| |DTRI(X)|
-------------------------------------------------------
10 153 9422
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.threshold_num_turning = 10;
opt.threshold_num_vert_Smo = 20;
opt.tolerance = 0.01; % do not simplify polyline
[vert,tria,tnum] = im2mesh( im, opt );
Refine triangulation...
-------------------------------------------------------
|ITER.| |CDT1(X)| |CDT2(X)|
-------------------------------------------------------
6 678 1186
10 708 1596
20 713 2369
20 713 2369
Refine triangulation...
-------------------------------------------------------
|ITER.| |CDT1(X)| |CDT2(X)|
-------------------------------------------------------
10 891 1186
10 891 1186
20 919 7026
25 922 7161
Smooth triangulation...
-------------------------------------------------------
|ITER.| |MOVE(X)| |DTRI(X)|
-------------------------------------------------------
10 101 7089
plotMeshes(vert,tria,tnum)
Zoom in
plotMeshes(vert,tria,tnum)
The new boundaries are better.
set(groot, 'DefaultFigurePosition', 'factory')