2012年11月29日木曜日

CentOS5.8にgcc-4.7.2をインストールする。

CentOS5.8上でgcc-4.7.2をコンパイルしました。 こちらのサイトを参考にしています。以下覚え書きとして記します。

前準備として、以下のパッケージをupdateします。gccだけでなく、gcc-c++も必要です。
  1. gcc
  2. gcc-c++
  3. binutils
  4. bzip2
  5. gzip
  6. m4
  7. make
  8. unzip
  9. zip
以下のサイトから、各ソースをダウンロードします。
  1. mpc
  2. mpfr
  3. gmp
  4. gcc
これらをgcc-4.7.2というディレクトリの下に置き、解凍します。
最初に、gmpをコンパイルします。 次に、mpfrをコンパイルします。 さらに、mpcをコンパイルします。 これでgccをコンパイルする準備が整いました。 make中にこんなエラーが発生しました。 LD_LIBRARY_PATHに/usr/local/gcc-4.7.2/lib(mpc,gmp,mpfrのライブラリがあるディレクトリ)を追加すれば良いです。 あらためて しばらくすると、また、エラーが発生しました(内容は...記録し忘れました)。 対処方法はこれです。 32ビット版のglibcのヘッダが必要です。configureの時に明示的に64ビットに限定しないと32ビットもコンパイルされるのですね。知りませんでした。 再度 できました。64ビット版のgccは--prefixで指定したディレクトリ、今の場合、/usr/local/gcc-4.7.2/lib64の下にあります。

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

Compilation of Boost by clang with C++11

My procedure is as follows: When using it on the Xcode, we need to add a variable DYLD_LIBRARY to "Product→Edit Scheme→Arguments→Environment Variables" and set the path to dylib to the variable.

2012年11月20日火曜日

Level Set 法

はじめに

ずいぶん昔になりますが、Level Set 法を実装しました。今回はこれを公開します。

デモ

こんな感じです。


 

検証環境(Mac)

  1. Mac OS X 10.8.2
  2. プロセッサ:3.06 GHz Intel Core 2 Duo
  3. メモリ:4GB
  4. Xcode4.5.2 with Apple LLVM 4.1(C++ Language Dialect → C++11, C++ Standard Library → libc++)
  5. boost-1.51.0(上記コンパイラでコンパイルしたもの。こちら

検証環境(Windows)

  1. Windows XP Professional Version 2002 Service Pack 3
  2. プロセッサ:Pentium(R) D CPU 3.20GHz
  3. メモリ:3GB
  4. Visual Studio 2005
  5. boost-1.51.0(VS2005用バイナリ版)

ソース

こちらです。上記2つの検証環境で動作確認しました。

使い方

実行ファイ名は、LevelSetMethod(Windowsの場合はLevelSetMethod.exe)です。引数なしで実行すると以下を出力します。 上記引数を使い分けながら計算を進めます。大まかな計算手順は以下の通りです。
  1. 入力画像の大きさを知る。
  2. 初期閉曲線を設定する。
  3. LevelSet法を実行する。
各項目の詳細を解説していきます。

①入力画像の大きさ


初期閉曲線を設定するには入力画像の大きさを知る必要があります。以下のコマンドを実行します。 入力画像(./input/sample3.jpg)の幅と高さが表示されます。

②初期閉曲線の設定


以下のコマンドで中心座標(X, Y)、半径Rの円を描きます。 ここで、-Cは円の色を表わします。値域は[0,255]です。入力画像に円を追加した画像が出力フォルダ(./output)内に保存されます。名前はinitial_loop.jpgです。 この円が初期閉曲線となります。初期閉曲線をオブジェクトの外側に設定する場合と内側に設定する場合とがあります。前者の場合、LevelSet法は初期閉曲線を内側に向かって収縮させ、後者の場合、外側に向かって膨張させます。試行錯誤により適切な(X, Y, R)の値を見つけます。

③LevelSet法の実行


最初にLevelSet法に渡す各種パラメータの値を設定ファイルに書き込む必要があります。名前は任意です。ここではparamsとします。以下にparamsの例を示します。 各パラメータの意味は以下の通りです。
  1. time_step: 時間発展の刻み幅
  2. time_step_number: 時間発展の繰り返し数
  3. space_step: 空間刻み幅。x軸方向、y軸方向ともに同じです。
  4. constant_speed: 速度関数の定数部分の値(後述)。
  5. epsilon: 速度関数に現れるεの値(後述)。
  6. sigma: 入力画像に施すガウスぼかしの度合い。
当該アプリで使用している速度関数 は以下で定義されます。

ここで、 は曲率です。constant_speed に相当します。閉曲線を内側に向かって収縮させるなら負の値を、その逆なら正の値を設定します。また、epsilon に相当します。
設定ファイルparamsを作成したら、以下を実行します。 -Fの後ろにparamsへのパスを書きます。実行している間、プログレスバーが表示されます。今の場合、時間発展は400ステップ行われ、10(-Tの後ろに記した整数値)ステップごとに画像が保存されます。保存先はディレクトリ./output、ファイル名はfront_xxx.jpgです。ここでxxxは整数値です。標準出力の末尾に計算時間(画像保存時間も含む)が表示されます。上の場合、40枚の画像が保存されます。これらの画像をffmpegで動画にしたものが最初に示したデモです。

理論

理論は こちらにまとめました。当該アプリではNarrow Band法を採用しています。

三次元実時間対応にしたいですね(追記)。

2012年11月19日月曜日

2012年11月11日日曜日

opencv2をclang with C++11でコンパイルする。

以下の通り。 ここからソースをとってくる。 iota関数が定義されていないというエラーが出た。 場所はOpenCV-2.4.3/modules/contrib/src/spinimages.cppの809行目。 このファイルの先頭に#include <numeric>を追加。 あらためてmake 完了。

boostをclang with C++11でコンパイルする。

以下の通り。 Xcodeで動かす時は、Product→Edit Scheme→Arguments→Environment Variablesに変数DYLD_LIBRARY_PATHを追加し、dylibのパスを設定する。