/**
         * この関数は、SlidePTileを用いて敷居値を1個求めます。敷居値の範囲は、i_histogram引数の範囲と同じです。
         */
        public int getThreshold(NyARHistogram i_histogram)
        {
            //総ピクセル数を計算
            int n = i_histogram.length;
            int sum_of_pixel = i_histogram.total_of_data;
            int[] hist = i_histogram.data;
            // 閾値ピクセル数確定
            int th_pixcels = sum_of_pixel * this._persentage / 100;
            int th_wk;
            int th_w, th_b;

            // 黒点基準
            th_wk = th_pixcels;
            for (th_b = 0; th_b < n - 2; th_b++)
            {
                th_wk -= hist[th_b];
                if (th_wk <= 0)
                {
                    break;
                }
            }
            // 白点基準
            th_wk = th_pixcels;
            for (th_w = n - 1; th_w > 1; th_w--)
            {
                th_wk -= hist[th_w];
                if (th_wk <= 0)
                {
                    break;
                }
            }
            // 閾値の保存
            return (th_w + th_b) / 2;
        }
Ejemplo n.º 2
0
        /**
         * この関数は、SlidePTileを用いて敷居値を1個求めます。敷居値の範囲は、i_histogram引数の範囲と同じです。
         */
        public int getThreshold(NyARHistogram i_histogram)
        {
            //総ピクセル数を計算
            int n            = i_histogram.length;
            int sum_of_pixel = i_histogram.total_of_data;

            int[] hist = i_histogram.data;
            // 閾値ピクセル数確定
            int th_pixcels = sum_of_pixel * this._persentage / 100;
            int th_wk;
            int th_w, th_b;

            // 黒点基準
            th_wk = th_pixcels;
            for (th_b = 0; th_b < n - 2; th_b++)
            {
                th_wk -= hist[th_b];
                if (th_wk <= 0)
                {
                    break;
                }
            }
            // 白点基準
            th_wk = th_pixcels;
            for (th_w = n - 1; th_w > 1; th_w--)
            {
                th_wk -= hist[th_w];
                if (th_wk <= 0)
                {
                    break;
                }
            }
            // 閾値の保存
            return((th_w + th_b) / 2);
        }
Ejemplo n.º 3
0
 /**
  * 共通初期化関数。
  * @param i_param
  * @param i_drv_factory
  * ラスタドライバのファクトリ。
  * @param i_gs_type
  * @param i_rgb_type
  * @return
  * @
  */
 private void InitInstance(NyARIntSize i_size)
 {
     //リソースの生成
       this.InitResource(i_size);
       this._gs_hist = new NyARHistogram(256);
       this._src_ts = 0;
       this._gs_id_ts = 0;
       this._gs_hist_ts = 0;
 }
Ejemplo n.º 4
0
        // この関数は、kittlerThresholdを用いて敷居値を1個求めます。敷居値の範囲は、i_histogram引数の範囲と同じです。
        public int getThreshold(NyARHistogram i_histogram)
        {
            int    i;
            double min = Double.MaxValue;
            int    th = 0;
            int    da, sa, db, sb, pa, pb;
            double oa, ob;

            int[] hist = i_histogram.data;
            int   n    = i_histogram.length;

            //Low側
            da = pa = 0;
            int h;

            for (i = 0; i < n; i++)
            {
                h   = hist[i];
                da += h * i;     //i*h[i]
                pa += h * i * i; //i*i*h[i]
            }
            sa = i_histogram.total_of_data;
            //High側(i=n-1)
            db = 0;
            sb = 0;
            pb = 0;

            for (i = n - 1; i > 0; i--)
            {
                //次のヒストグラムを計算
                int hist_count = hist[i];        //h[i]
                int hist_val   = hist_count * i; //h[i]*i
                int hist_val2  = hist_val * i;   //h[i]*i*i
                da -= hist_val;
                sa -= hist_count;
                pa -= hist_val2;
                db += hist_val;
                sb += hist_count;
                pb += hist_val2;

                //初期化
                double wa = (double)sa / (sa + sb);
                double wb = (double)sb / (sa + sb);
                if (wa == 0 || wb == 0)
                {
                    continue;
                }

                oa = ob = 0;
                double ma = sa != 0 ? (double)da / sa : 0;
                //Σ(i-ma)^2*h[i]=Σ(i^2*h[i])+Σ(ma^2*h[i])-Σ(2*i*ma*h[i])
                oa = ((double)(pa + ma * ma * sa - 2 * ma * da)) / sa;

                double mb = sb != 0 ? (double)db / sb : 0;
                //Σ(i-mb)^2*h[i]=Σ(i^2*h[i])+Σ(mb^2*h[i])-Σ(2*i*mb*h[i])
                ob = ((double)(pb + mb * mb * sb - 2 * mb * db)) / sb;

                double kai = wa * Math.Log(oa / wa) + wb * Math.Log(ob / wb);
                if (kai > 0 && min > kai)
                {
                    min = kai;
                    th  = i;
                }
                //System.out.println(kai);
            }

            return(th);//129//7.506713872738873
        }