2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java edition ARToolKit class library.
\r
11 * Copyright (C)2008-2009 Ryo Iizuka
\r
13 * This program is free software: you can redistribute it and/or modify
\r
14 * it under the terms of the GNU General Public License as published by
\r
15 * the Free Software Foundation, either version 3 of the License, or
\r
16 * (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
26 * For further information please contact.
\r
27 * http://nyatla.jp/nyatoolkit/
\r
28 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
31 package jp.nyatla.nyartoolkit.core.match;
\r
34 import jp.nyatla.nyartoolkit.core.raster.*;
\r
35 import jp.nyatla.nyartoolkit.core.types.*;
\r
39 * このクラスは、グレースケールの差分画像を格納します。
\r
40 * 差分画像は、p[i]=((255-画素[i])-画像全体の平均値)のピクセルで構成されている、平均値との差分値です。
\r
41 * {@link NyARMatchPatt_BlackWhite}の入力値と使います。
\r
43 * {@link #setRaster}関数で、差分画像を作成し、プロパティ取得関数でその情報を得ます。
\r
46 public class NyARMatchPattDeviationBlackWhiteData
\r
48 private int[] _data;
\r
49 private double _pow;
\r
51 private int _number_of_pixels;
\r
53 * この関数は、画素データを格納した配列を返します。
\r
54 * {@link NyARMatchPatt_BlackWhite#evaluate}関数から使います。
\r
56 public int[] refData()
\r
61 * この関数は、差分画像の強度値を返します。
\r
62 * 強度値は、差分画像の画素を二乗した値の合計です。
\r
66 public double getPow()
\r
72 * 差分画像のサイズを指定して、インスタンスを生成します。
\r
78 public NyARMatchPattDeviationBlackWhiteData(int i_width,int i_height)
\r
80 this._number_of_pixels=i_height*i_width;
\r
81 this._data=new int[this._number_of_pixels];
\r
85 * この関数は、ラスタから差分画像を生成して、格納します。
\r
86 * 制限事項として、{@link NyARBufferType#INT1D_X8R8G8B8_32}形式のラスタのみ、入力できます。
\r
88 * 差分画像の元画像。サイズは、このインスタンスと同じである必要があります。
\r
90 public void setRaster(INyARRaster i_raster)
\r
92 //i_buffer[XRGB]→差分[BW]変換
\r
96 final int[] linput=this._data;//<PV/>
\r
97 final int[] buf=(int[])i_raster.getBuffer();
\r
99 // input配列のサイズとwhも更新// input=new int[height][width][3];
\r
100 final int number_of_pixels=this._number_of_pixels;
\r
102 //<平均値計算(FORの1/8展開)/>
\r
104 for(i=number_of_pixels-1;i>=0;i--){
\r
106 ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);
\r
108 ave=(number_of_pixels*255*3-ave)/(3*number_of_pixels);
\r
113 for (i = number_of_pixels-1; i >= 0;i--) {
\r
115 w_sum =((255*3-(rgb & 0xff)-((rgb >> 8) & 0xff)-((rgb >> 16) & 0xff))/3)-ave;
\r
117 sum += w_sum * w_sum;
\r
119 final double p=Math.sqrt((double) sum);
\r
120 this._pow=p!=0.0?p:0.0000001;
\r