2012年11月25日日曜日

Level Set Method

Introduction

Several years ago I implemented a command line application of the Level Set Method. In this page, I would like to introduce it.

Demo

I start with showing three demonstrations:
demo-1

demo-2

demo-3

 

Verification Environment(Mac)

  1. Mac OS X 10.8.2
  2. Processor:3.06 GHz Intel Core 2 Duo
  3. Memory:4GB
  4. Xcode4.5.2 with Apple LLVM 4.1(C++ Language Dialect → C++11, C++ Standard Library → libc++)
  5. boost-1.51.0 compiled by the above compiler (See also here)

Verification Environment(Windows)

  1. Windows XP Professional Version 2002 Service Pack 3
  2. Processor:Pentium(R) D CPU 3.20GHz
  3. Memory:3GB
  4. Visual Studio 2005
  5. boost-1.51.0 (binaries for the VS2005)

Source Code

Here is my source code. I verified it on the above two machines.

Usage

An execution file name is LevelSetMethod. In the case of Windows, it's named LevelSetMethod.exe. Running it without any arguments, it writes the following usage statements on the standard output: The Level Set Method is carried out by using some of these parameters. The procedure is as follows:
  1. see the size of an input image.
  2. set an initial closed curve.
  3. run the Level Set Method.
I will explain the detail of each process.

①Size of Image


In order to give the application an initial closed curve, we have to know the size of an input image. To do so, the following command is used. The output indicates the size of the input image(./input/sample3.jpg).

②Setting Initial Closed Curve


We can draw an circle with a center (X, Y) and a radius R by the following command. In this command, -C indicates color of the circle, whose range is [0,255]. The circle is drawn on the input image. It is saved in the directory(./output) with the name "initial_loop.jpg" (see the below image). The circle corresponds to the initial closed curve. We can put it either outside an object or inside one. If it is placed outside the object, the Level Set Method shrinks it. On the other hand, if it is placed inside the object, the Level Set Method expands it. We have to decide appropriate values (X, Y, R) through a trial and error process.

③Running Level Set Method


We have to make a setting file in which six parameters are described. The file name is arbitrary. In this page, we name it "params" to make the explanation easy. The sample of "params" is as follows: The meanings of the parameters are
  1. time_step: time step
  2. time_step_number: iteration of time evolution
  3. space_step: space step. the same value for both x-axis and y-axis
  4. constant_speed: a constant part of a speed function as we will discuss later
  5. epsilon: a value of ε which appears in the definition of a speed function
  6. sigma: a degree of the Gaussian blur
The speed function which the application uses is defined as,

where, is the curvature.
The parameter epsilon indicates and the parameter constant_speed corresponds to . If we shrink(expand) the curve, we set it to negative(positive) value. After making the setting file, we run the following command: After the argument -F, we type the path to "params." During execution, the progress bar is displayed. Under the above parameters, the time evolution is repeated up to 400 steps, and one image is saved per 10, which is a value after -T, time steps. The output directory is ./output and the file name is front_xxx.jpg, where xxx represents integer. The calculation time is displayed in the last line of the standard output. In the current parameters, 40 images are saved. I converted these images into a movie by use of ffmpeg to show the demonstration at the beginning of this page.

P.S. See also this page. 2013/01/25

0 件のコメント:

コメントを投稿