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
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
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
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
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
25 package jp.nyatla.nyartoolkit.rpf.tracker.nyartk;
\r
27 import jp.nyatla.nyartoolkit.NyARException;
\r
28 import jp.nyatla.nyartoolkit.core.raster.*;
\r
29 import jp.nyatla.nyartoolkit.core.rasterfilter.INyARRasterFilter;
\r
30 import jp.nyatla.nyartoolkit.core.types.NyARBufferType;
\r
31 import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
\r
34 * NyARReality用のエッジ検出フィルタ。
\r
35 * Roberts勾配の2乗値16倍に最大値制限をかけ、反転した値です。
\r
36 * 右端と左端の1ピクセルは、常に0が入ります。
\r
37 * X=|-1, 0| Y=|0,-1|
\r
41 public class NegativeSqRoberts implements INyARRasterFilter
\r
43 private IdoFilterImpl _do_filter_impl;
\r
44 public NegativeSqRoberts(int i_raster_type) throws NyARException
\r
46 this.initInstance(i_raster_type);
\r
48 public void initInstance(int i_raster_type)throws NyARException
\r
50 switch (i_raster_type) {
\r
51 case NyARBufferType.INT1D_GRAY_8:
\r
52 this._do_filter_impl=new IdoFilterImpl_GRAY_8();
\r
55 throw new NyARException();
\r
58 public void doFilter(INyARRaster i_input, INyARRaster i_output) throws NyARException
\r
60 this._do_filter_impl.doFilter(i_input,i_output,i_input.getSize());
\r
63 interface IdoFilterImpl
\r
65 public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size) throws NyARException;
\r
67 private final static int SH=4;
\r
68 class IdoFilterImpl_GRAY_8 implements IdoFilterImpl
\r
70 public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size) throws NyARException
\r
72 assert (i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
\r
73 assert (i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
\r
74 int[] in_ptr =(int[])i_input.getBuffer();
\r
75 int[] out_ptr=(int[])i_output.getBuffer();
\r
80 int mod_p=(width-2)-(width-2)%4;
\r
81 for(int y=i_size.h-2;y>=0;y--){
\r
82 int p00=in_ptr[idx++];
\r
83 int p10=in_ptr[idx2++];
\r
87 p01=in_ptr[idx++];p11=in_ptr[idx2++];
\r
88 fx=p11-p00;fy=p10-p01;
\r
89 // out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
\r
90 fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
\r
95 p01=in_ptr[idx++];p11=in_ptr[idx2++];
\r
98 // out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
\r
99 fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
\r
101 p01=in_ptr[idx++];p11=in_ptr[idx2++];
\r
104 // out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
\r
105 fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
\r
107 p01=in_ptr[idx++];p11=in_ptr[idx2++];
\r
111 // out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
\r
112 fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
\r
115 p01=in_ptr[idx++];p11=in_ptr[idx2++];
\r
118 // out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
\r
119 fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
\r
123 out_ptr[idx-1]=255;
\r
125 for(int x=width-1;x>=0;x--){
\r
126 out_ptr[idx++]=255;
\r