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.core.rasteranalyzer.threshold;
\r
27 import jp.nyatla.nyartoolkit.NyARException;
\r
28 import jp.nyatla.nyartoolkit.core.analyzer.raster.threshold.INyARRasterThresholdAnalyzer;
\r
29 import jp.nyatla.nyartoolkit.core.raster.*;
\r
30 import jp.nyatla.nyartoolkit.core.types.*;
\r
36 public class NyARRasterThresholdAnalyzer_DiffHistgram implements INyARRasterThresholdAnalyzer
\r
38 private int _threshold;
\r
40 public NyARRasterThresholdAnalyzer_DiffHistgram()
\r
44 private int createHistgram(int[] in_buf,NyARIntSize i_size, int[] o_histgram) throws NyARException
\r
52 for (int i = 0; i < 256; i++) {
\r
57 for (int y = 1; y < i_size.h-1; y++) {
\r
58 for (int x = 1; x < i_size.w-1; x++) {
\r
59 int v = in_buf[y* i_size.w+x];
\r
61 for(int yy=0;yy<3;yy++){
\r
62 for(int xx=0;xx<3;xx++){
\r
63 int v2=in_buf[(y+yy-1)* i_size.w+(x+xx-1)];
\r
64 sam1+=v2*fil1[xx][yy];
\r
65 sam2+=v2*fil1[yy][xx];
\r
68 sam=sam1*sam1+sam2*sam2;
\r
73 int max=o_histgram[0];
\r
74 for(int i=1;i<256;i++){
\r
75 if(max<o_histgram[i]){
\r
83 public int analyzeRaster(INyARRaster i_input) throws NyARException
\r
85 assert (i_input.isEqualBufferType(INyARRaster.BUFFERFORMAT_INT1D_GRAY_8));
\r
86 int[] histgram = new int[256];
\r
87 return createHistgram((int[])i_input.getBuffer(),i_input.getSize(), histgram);
\r
91 * デバック用の関数です。 ヒストグラムをラスタに書き出します。
\r
94 * 書き出し先のラスタオブジェクト 256ピクセル以上の幅があること。
\r
96 public void debugDrawHistgramMap(INyARRaster i_input, INyARRaster i_output) throws NyARException
\r
98 assert (i_input.isEqualBufferType(INyARRaster.BUFFERFORMAT_INT1D_GRAY_8));
\r
99 assert (i_output.isEqualBufferType(INyARRaster.BUFFERFORMAT_INT1D_GRAY_8));
\r
100 NyARIntSize size = i_output.getSize();
\r
102 int[] out_buf = (int[]) i_output.getBuffer();
\r
104 for (int y = 0; y < size.h; y++) {
\r
105 for (int x = 0; x < size.w; x++) {
\r
106 out_buf[y* size.w+x] = 0;
\r
110 int[] histgram = new int[256];
\r
111 int threshold = createHistgram((int[])i_input.getBuffer(),i_input.getSize(), histgram);
\r
115 for (int i = 0; i < 255; i++) {
\r
116 if (max_v < histgram[i]) {
\r
117 max_v = histgram[i];
\r
121 for (int i = 0; i < size.h; i++) {
\r
122 out_buf[i* size.w+0] = 128;
\r
123 out_buf[i* size.w+128] = 128;
\r
124 out_buf[i* size.w+255] = 128;
\r
127 for (int i = 0; i < 255; i++) {
\r
128 out_buf[(histgram[i] * (size.h - 1) / max_v)* size.w+i] = 255;
\r
131 for (int i = 0; i < size.h; i++) {
\r
132 out_buf[i* size.w+threshold] = 255;
\r
137 public int getThreshold()
\r
139 return this._threshold;
\r