OSDN Git Service

9a9623a7432df9221e838c59cd831e332c2d2f92
[nyartoolkit-and/nyartoolkit-and.git] / lib / src / jp / nyatla / nyartoolkit / core / rasterfilter / NyARRasterFilter_EqualizeHist.java
1 /* \r
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
6  *\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
11  * \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
16  *\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
19  * \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
23  * \r
24  */\r
25 package jp.nyatla.nyartoolkit.core.rasterfilter;\r
26 \r
27 import jp.nyatla.nyartoolkit.NyARException;\r
28 import jp.nyatla.nyartoolkit.core.analyzer.raster.NyARRasterAnalyzer_Histogram;\r
29 import jp.nyatla.nyartoolkit.core.raster.INyARRaster;\r
30 import jp.nyatla.nyartoolkit.core.types.NyARHistogram;\r
31 /**\r
32  * ヒストグラムを平滑化します。\r
33  *\r
34  */\r
35 public class NyARRasterFilter_EqualizeHist extends NyARRasterFilter_CustomToneTable\r
36 {\r
37         private NyARRasterAnalyzer_Histogram _hist_analyzer;\r
38         private NyARHistogram _histogram=new NyARHistogram(256);\r
39         public NyARRasterFilter_EqualizeHist(int i_raster_type,int i_sample_interval) throws NyARException\r
40         {\r
41                 super(i_raster_type);\r
42                 this._hist_analyzer=new NyARRasterAnalyzer_Histogram(i_raster_type,i_sample_interval);\r
43         }\r
44         public void doFilter(INyARRaster i_input, INyARRaster i_output) throws NyARException\r
45         {\r
46                 //ヒストグラムを得る\r
47                 NyARHistogram hist=this._histogram;\r
48                 this._hist_analyzer.analyzeRaster(i_input,hist);\r
49                 //変換テーブルを作成\r
50                 int hist_total=this._histogram.total_of_data;\r
51                 int min=hist.getMinData();\r
52                 int hist_size=this._histogram.length;\r
53                 int sum=0;\r
54                 for(int i=0;i<hist_size;i++){\r
55                         sum+=hist.data[i];\r
56                         this.table[i]=(int)((sum-min)*(hist_size-1)/((hist_total-min)));\r
57                 }\r
58                 //変換\r
59                 super.doFilter(i_input, i_output);\r
60         }\r
61 }