OSDN Git Service

5fbd88056cd72da9791860ffa360a3313a8e3120
[nyartoolkit-and/nyartoolkit-and.git] / lib / src / jp / nyatla / nyartoolkit / core / analyzer / histogram / NyARHistogramAnalyzer_SlidePTile.java
1 /* \r
2  * PROJECT: NyARToolkit(Extension)\r
3  * --------------------------------------------------------------------------------\r
4  * The NyARToolkit is Java edition ARToolKit class library.\r
5  * Copyright (C)2008-2009 Ryo Iizuka\r
6  *\r
7  * This program is free software: you can redistribute it and/or modify\r
8  * it under the terms of the GNU General Public License as published by\r
9  * the Free Software Foundation, either version 3 of the License, or\r
10  * (at your option) any later version.\r
11  * \r
12  * This program is distributed in the hope that it will be useful,\r
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15  * GNU General Public License for more details.\r
16  *\r
17  * You should have received a copy of the GNU General Public License\r
18  * along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
19  * \r
20  * For further information please contact.\r
21  *      http://nyatla.jp/nyatoolkit/\r
22  *      <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>\r
23  * \r
24  */\r
25 package jp.nyatla.nyartoolkit.core.analyzer.histogram;\r
26 \r
27 import jp.nyatla.nyartoolkit.core.types.NyARHistogram;\r
28 \r
29 \r
30 /**\r
31  * このクラスは、明点・暗点のPTail法で求めた敷居値を合算して、敷居値を計算します。\r
32  * <p>敷居値決定のアルゴリズム - 明点・暗点両側からPTail法を用いて一定割合の画素を取り除き、その中間値を求めます。</p>\r
33  */\r
34 public class NyARHistogramAnalyzer_SlidePTile implements INyARHistogramAnalyzer_Threshold\r
35 {\r
36         private int _persentage;\r
37         /**\r
38          * コンストラクタです。\r
39          * @param i_persentage\r
40          * 明点、暗点の両側から取り除く、画素の割合を指定します。0&lt;n&lt;50の範囲で指定します。\r
41          */\r
42         public NyARHistogramAnalyzer_SlidePTile(int i_persentage)\r
43         {\r
44                 assert (0 <= i_persentage && i_persentage <= 50);\r
45                 //初期化\r
46                 this._persentage=i_persentage;\r
47         }\r
48         /**\r
49          * この関数は、SlidePTileを用いて敷居値を1個求めます。敷居値の範囲は、i_histogram引数の範囲と同じです。\r
50          */     \r
51         public int getThreshold(NyARHistogram i_histogram)\r
52         {\r
53                 //総ピクセル数を計算\r
54                 int n=i_histogram.length;\r
55                 int sum_of_pixel=i_histogram.total_of_data;\r
56                 int[] hist=i_histogram.data;\r
57                 // 閾値ピクセル数確定\r
58                 final int th_pixcels = sum_of_pixel * this._persentage / 100;\r
59                 int th_wk;\r
60                 int th_w, th_b;\r
61 \r
62                 // 黒点基準\r
63                 th_wk = th_pixcels;\r
64                 for (th_b = 0; th_b < n-2; th_b++) {\r
65                         th_wk -= hist[th_b];\r
66                         if (th_wk <= 0) {\r
67                                 break;\r
68                         }\r
69                 }\r
70                 // 白点基準\r
71                 th_wk = th_pixcels;\r
72                 for (th_w = n-1; th_w > 1; th_w--) {\r
73                         th_wk -= hist[th_w];\r
74                         if (th_wk <= 0) {\r
75                                 break;\r
76                         }\r
77                 }\r
78                 // 閾値の保存\r
79                 return (th_w + th_b) / 2;\r
80         }\r
81 }\r