--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core2;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.*;\r
+import jp.nyatla.nyartoolkit.core.rasterfilter.INyARRasterFilter;\r
+import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;\r
+import jp.nyatla.nyartoolkit.core.types.NyARIntSize;\r
+\r
+/**\r
+ * エッジ検出フィルタ 入力 BUFFERFORMAT_INT2D 出力 BUFFERFORMAT_INT2D\r
+ */\r
+public class NyARRasterFilter_Edge implements INyARRasterFilter\r
+{\r
+ public void doFilter(INyARRaster i_input, INyARRaster i_output) throws NyARException\r
+ {\r
+ INyARBufferReader in_buffer_reader=i_input.getBufferReader(); \r
+ INyARBufferReader out_buffer_reader=i_output.getBufferReader(); \r
+ assert (in_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));\r
+ assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8));\r
+ assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
+\r
+ int[][] out_buf = (int[][]) out_buffer_reader.getBuffer();\r
+ int[][] in_buf = (int[][]) in_buffer_reader.getBuffer();\r
+\r
+ int bp = 0;\r
+ NyARIntSize size = i_output.getSize();\r
+ for (int y = 1; y < size.h; y++) {\r
+ int prev = 128;\r
+ for (int x = 1; x < size.w; x++) {\r
+ int w = in_buf[y][x];\r
+ out_buf[y][x] = (Math.abs(w - prev) + Math.abs(w - in_buf[y - 1][x])) / 2;\r
+ prev = w;\r
+ bp += 3;\r
+ }\r
+ }\r
+ return;\r
+ }\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.*;\r
+import jp.nyatla.nyartoolkit.core.rasterfilter.INyARRasterFilter_GsToBin;\r
+import jp.nyatla.nyartoolkit.core.types.*;\r
+\r
+/**\r
+ * 平均移動法を使った2値化フィルタ\r
+ * \r
+ */\r
+public class NyARRasterFilter_AreaAverage implements INyARRasterFilter_GsToBin\r
+{\r
+ private int _area = 8;\r
+\r
+ public void doFilter(NyARGlayscaleRaster i_input, NyARBinRaster i_output) throws NyARException\r
+ {\r
+ final NyARIntSize size = i_output.getSize();\r
+ final int[][] out_buf = (int[][]) i_output.getBufferReader().getBuffer();\r
+ final int[][] in_buf = (int[][]) i_input.getBufferReader().getBuffer();\r
+ assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
+ assert (size.h % 8 == 0 && size.w % 8 == 0);//暫定実装なので。\r
+\r
+ final int area = this._area;\r
+ int y1 = area;\r
+ int x1 = area;\r
+ int y2 = size.h - area;\r
+ int x2 = size.w - area;\r
+\r
+ for (int y = y1; y < y2; y++) {\r
+ int sum, nn;\r
+ sum = nn = 0;\r
+ for (int yy = y - area; yy < y + area + 1; yy++) {\r
+ for (int xx = x1 - area; xx < x1 + area; xx++) {\r
+ sum += in_buf[yy][xx];\r
+ nn++;\r
+ }\r
+ }\r
+ boolean first = true;\r
+ for (int x = area; x < x2; x++) {\r
+ if (!first) {\r
+ for (int yy = y - area; yy < y + area; yy++) {\r
+ sum += in_buf[yy][x + area];\r
+ sum -= in_buf[yy][x - area];\r
+ }\r
+ }\r
+ first = false;\r
+ int th = (sum / nn);\r
+\r
+ int g = in_buf[y][x];\r
+ out_buf[y][x] = th < g ? 1 : 0;\r
+ }\r
+ }\r
+ return;\r
+ }\r
+\r
+}\r
--- /dev/null
+/* \r
+ * PROJECT: NyARToolkit\r
+ * --------------------------------------------------------------------------------\r
+ * This work is based on the original ARToolKit developed by\r
+ * Hirokazu Kato\r
+ * Mark Billinghurst\r
+ * HITLab, University of Washington, Seattle\r
+ * http://www.hitl.washington.edu/artoolkit/\r
+ *\r
+ * The NyARToolkit is Java version ARToolkit class library.\r
+ * Copyright (C)2008 R.Iizuka\r
+ *\r
+ * This program is free software; you can redistribute it and/or\r
+ * modify it under the terms of the GNU General Public License\r
+ * as published by the Free Software Foundation; either version 2\r
+ * of the License, or (at your option) any later version.\r
+ * \r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
+ * GNU General Public License for more details.\r
+ * \r
+ * You should have received a copy of the GNU General Public License\r
+ * along with this framework; if not, write to the Free Software\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ * \r
+ * For further information please contact.\r
+ * http://nyatla.jp/nyatoolkit/\r
+ * <airmail(at)ebony.plala.or.jp>\r
+ * \r
+ */\r
+package jp.nyatla.nyartoolkit.core2.rasterfilter.gs2bin;\r
+\r
+import jp.nyatla.nyartoolkit.NyARException;\r
+import jp.nyatla.nyartoolkit.core.raster.*;\r
+import jp.nyatla.nyartoolkit.core.rasterfilter.INyARRasterFilter_GsToBin;\r
+import jp.nyatla.nyartoolkit.core.types.*;\r
+\r
+/**\r
+ * 定数閾値による2値化をする。\r
+ * \r
+ */\r
+public class NyARRasterFilter_Threshold implements INyARRasterFilter_GsToBin\r
+{\r
+ private int _threshold;\r
+\r
+ public NyARRasterFilter_Threshold(int i_threshold)\r
+ {\r
+ this._threshold = i_threshold;\r
+ }\r
+\r
+ public void doFilter(NyARGlayscaleRaster i_input, NyARBinRaster i_output) throws NyARException\r
+ {\r
+ assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);\r
+\r
+ final int[][] out_buf = (int[][]) i_output.getBufferReader().getBuffer();\r
+ final int[][] in_buf = (int[][]) i_input.getBufferReader().getBuffer();\r
+\r
+ int bp = 0;\r
+ NyARIntSize size = i_output.getSize();\r
+ for (int y = 0; y < size.h - 1; y++) {\r
+ for (int x = 0; x < size.w; x++) {\r
+ out_buf[y][x] = in_buf[y][x] >= this._threshold ? 1 : 0;\r
+ bp += 3;\r
+ }\r
+ }\r
+ return;\r
+ }\r
+}\r