OSDN Git Service

[TAG]NyARToolkit for Java 2.4.2
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.4.2 / src / jp / nyatla / nyartoolkit / core / analyzer / histgram / NyARHistgramAnalyzer_SlidePTile.java
1 package jp.nyatla.nyartoolkit.core.analyzer.histgram;\r
2 \r
3 import jp.nyatla.nyartoolkit.core.types.NyARHistgram;\r
4 \r
5 \r
6 \r
7 /**\r
8  * 明点と暗点を双方向からPタイル法でカウントして、その中央値を閾値とする。\r
9  * \r
10  * \r
11  */\r
12 public class NyARHistgramAnalyzer_SlidePTile implements INyARHistgramAnalyzer_Threshold\r
13 {\r
14         private int _persentage;\r
15         public NyARHistgramAnalyzer_SlidePTile(int i_persentage)\r
16         {\r
17                 assert (0 <= i_persentage && i_persentage <= 50);\r
18                 //初期化\r
19                 this._persentage=i_persentage;\r
20         }       \r
21         public int getThreshold(NyARHistgram i_histgram)\r
22         {\r
23                 //総ピクセル数を計算\r
24                 int n=i_histgram.length;\r
25                 int sum_of_pixel=i_histgram.total_of_data;\r
26                 int[] hist=i_histgram.data;\r
27                 // 閾値ピクセル数確定\r
28                 final int th_pixcels = sum_of_pixel * this._persentage / 100;\r
29                 int th_wk;\r
30                 int th_w, th_b;\r
31 \r
32                 // 黒点基準\r
33                 th_wk = th_pixcels;\r
34                 for (th_b = 0; th_b < n-2; th_b++) {\r
35                         th_wk -= hist[th_b];\r
36                         if (th_wk <= 0) {\r
37                                 break;\r
38                         }\r
39                 }\r
40                 // 白点基準\r
41                 th_wk = th_pixcels;\r
42                 for (th_w = n-1; th_w > 1; th_w--) {\r
43                         th_wk -= hist[th_w];\r
44                         if (th_wk <= 0) {\r
45                                 break;\r
46                         }\r
47                 }\r
48                 // 閾値の保存\r
49                 return (th_w + th_b) / 2;\r
50         }\r
51 }\r