public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)
		    {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
			    int[] in_ptr =(int[])i_input.getBuffer();
			    int[] out_ptr=(int[])i_output.getBuffer();
			    int width=i_size.w;
			    int idx=0;
			    int idx2=width;
			    int fx,fy;
			    int mod_p=(width-2)-(width-2)%4;
			    for(int y=i_size.h-2;y>=0;y--){
				    int p00=in_ptr[idx++];
				    int p10=in_ptr[idx2++];
				    int p01,p11;
				    int x=width-2;
				    for(;x>=mod_p;x--){
					    p01=in_ptr[idx++];p11=in_ptr[idx2++];
					    fx=p11-p00;fy=p10-p01;
    //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
					    fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
					    p00=p01;
					    p10=p11;
				    }
				    for(;x>=0;x-=4){
					    p01=in_ptr[idx++];p11=in_ptr[idx2++];
					    fx=p11-p00;
					    fy=p10-p01;
    //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
					    fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
					    p00=p01;p10=p11;
					    p01=in_ptr[idx++];p11=in_ptr[idx2++];
					    fx=p11-p00;
					    fy=p10-p01;
    //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
					    fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
					    p00=p01;p10=p11;
					    p01=in_ptr[idx++];p11=in_ptr[idx2++];
    					
					    fx=p11-p00;
					    fy=p10-p01;
    //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
					    fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
					    p00=p01;p10=p11;

					    p01=in_ptr[idx++];p11=in_ptr[idx2++];
					    fx=p11-p00;
					    fy=p10-p01;
    //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
					    fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
					    p00=p01;p10=p11;

				    }
				    out_ptr[idx-1]=255;
			    }
			    for(int x=width-1;x>=0;x--){
				    out_ptr[idx++]=255;
			    }
			    return;
		    }
        /**
         * XRGB[width*height]の配列から、パターンデータを構築。
         * @param i_buffer
         */
        public void setRaster(INyARRaster i_raster)
        {
            //i_buffer[XRGB]→差分[BW]変換			
            int i;
            int ave;//<PV/>
            int rgb;//<PV/>
            int[] linput = this._data;//<PV/>
            int[] buf = (int[])i_raster.getBuffer();

            // input配列のサイズとwhも更新// input=new int[height][width][3];
            int number_of_pixels = this._number_of_pixels;

            //<平均値計算(FORの1/8展開)/>
            ave = 0;
            for (i = number_of_pixels - 1; i >= 0; i--)
            {
                rgb = buf[i];
                ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);
            }
            ave = (number_of_pixels * 255 * 3 - ave) / (3 * number_of_pixels);
            //
            int sum = 0, w_sum;

            //<差分値計算/>
            for (i = number_of_pixels - 1; i >= 0; i--)
            {
                rgb = buf[i];
                w_sum = ((255 * 3 - (rgb & 0xff) - ((rgb >> 8) & 0xff) - ((rgb >> 16) & 0xff)) / 3) - ave;
                linput[i] = w_sum;
                sum += w_sum * w_sum;
            }
            double p = Math.Sqrt((double)sum);
            this._pow = p != 0.0 ? p : 0.0000001;
            return;
        }
		    public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)
		    {
			    Debug.Assert (i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
			    Debug.Assert (i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
			    int[] in_ptr =(int[])i_input.getBuffer();
			    int[] out_ptr=(int[])i_output.getBuffer();
			    int width=i_size.w;
			    int height=i_size.h;
			    for(int y=0;y<height-1;y++){
				    int idx=y*width;
				    int p00=in_ptr[idx];
				    int p10=in_ptr[width+idx];
				    int p01,p11;
				    for(int x=0;x<width-1;x++){
					    p01=in_ptr[idx+1];
					    p11=in_ptr[idx+width+1];
					    int fx=p11-p00;
					    int fy=p10-p01;
					    out_ptr[idx]=(int)Math.Sqrt(fx*fx+fy*fy)>>1;
					    p00=p01;
					    p10=p11;
					    idx++;
				    }
			    }
			    return;
		    }
		    public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)
		    {
			    Debug.Assert (i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
			    Debug.Assert (i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
			    int[] in_ptr =(int[])i_input.getBuffer();
			    int[] out_ptr=(int[])i_output.getBuffer();
			    int width=i_size.w;
			    int height=i_size.h;
			    int col0,col1,col2;
			    int bptr=0;
			    //1行目
			    col1=in_ptr[bptr  ]*2+in_ptr[bptr+width  ];
			    col2=in_ptr[bptr+1]*2+in_ptr[bptr+width+1];
			    out_ptr[bptr]=(col1*2+col2)/9;
			    bptr++;
			    for(int x=0;x<width-2;x++){
				    col0=col1;
				    col1=col2;
				    col2=in_ptr[bptr+1]*2+in_ptr[bptr+width+1];
				    out_ptr[bptr]=(col0+col1*2+col2)/12;
				    bptr++;
			    }			
			    out_ptr[bptr]=(col1+col2)/9;
			    bptr++;
			    //2行目-末行-1

			    for(int y=0;y<height-2;y++){
				    //左端
				    col1=in_ptr[bptr  ]*2+in_ptr[bptr-width  ]+in_ptr[bptr+width  ];
				    col2=in_ptr[bptr+1]*2+in_ptr[bptr-width+1]+in_ptr[bptr+width+1];
				    out_ptr[bptr]=(col1+col2)/12;
				    bptr++;
				    for(int x=0;x<width-2;x++){
					    col0=col1;
					    col1=col2;
					    col2=in_ptr[bptr+1]*2+in_ptr[bptr-width+1]+in_ptr[bptr+width+1];
					    out_ptr[bptr]=(col0+col1*2+col2)/16;
					    bptr++;
				    }
				    //右端
				    out_ptr[bptr]=(col1*2+col2)/12;
				    bptr++;
			    }
			    //末行目
			    col1=in_ptr[bptr  ]*2+in_ptr[bptr-width  ];
			    col2=in_ptr[bptr+1]*2+in_ptr[bptr-width+1];
			    out_ptr[bptr]=(col1+col2)/9;
			    bptr++;
			    for(int x=0;x<width-2;x++){
				    col0=col1;
				    col1=col2;
				    col2=in_ptr[bptr+1]*2+in_ptr[bptr-width+1];
				    out_ptr[bptr]=(col0+col1*2+col2)/12;
				    bptr++;
			    }			
			    out_ptr[bptr]=(col1*2+col2)/9;
			    bptr++;
			    return;
		    }
 /**
  * 入力ラスタをHSV形式に変換して、出力ラスタへ書込みます。
  * 画素形式は、コンストラクタに指定した形式に合せてください。
  */
 public void doFilter(INyARRgbRaster i_input, INyARRaster i_output)
 {
     Debug.Assert(i_input.getSize().isEqualSize(i_output.getSize()) == true);
     if (!this._do_filter_impl.isSupport(i_input, i_output))
     {
         this._do_filter_impl = this.createFilter(i_input, i_output);
     }
     this._do_filter_impl.doFilter(i_input, i_output, i_input.getSize());
 }
		    public override void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)
		    {
			   Debug. Assert(		i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
    			
			    int[] out_buf = (int[]) i_output.getBuffer();
			    int[] in_buf = (int[]) i_input.getBuffer();
			    for(int i=i_size.h*i_size.w-1;i>=0;i--)
			    {
				    out_buf[i]=this._table_ref[in_buf[i]];
			    }
			    return;
		    }
 protected IFilter createFilter(INyARRaster i_in, INyARRaster i_out)
 {
     if (i_in.getBufferType() == NyARBufferType.INT1D_GRAY_8)
     {
         switch (i_out.getBufferType())
         {
             case NyARBufferType.BYTE1D_B8G8R8_24:
                 return new Rgb2HsvFilter_BYTE1D_B8G8R8_24();
             default:
                 break;
         }
     }
     throw new NyARException();
 }
            public void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                int[] in_ptr = (int[])i_input.getBuffer();
                int[] out_ptr = (int[])i_output.getBuffer();


                int number_of_pixel = i_size.h * i_size.w;
                for (int i = 0; i < number_of_pixel; i++)
                {
                    out_ptr[i] = 255 - in_ptr[i];
                }
                return;
            }
	    public override void doFilter(INyARRaster i_input, INyARRaster i_output)
	    {
		    //ヒストグラムを得る
		    NyARHistogram hist=this._histogram;
		    this._hist_analyzer.analyzeRaster(i_input,hist);
		    //変換テーブルを作成
		    int hist_total=this._histogram.total_of_data;
		    int min=hist.getMinData();
		    int hist_size=this._histogram.length;
		    int sum=0;
		    for(int i=0;i<hist_size;i++){
			    sum+=hist.data[i];
			    this.table[i]=(int)((sum-min)*(hist_size-1)/((hist_total-min)));
		    }
		    //変換
		    base.doFilter(i_input, i_output);
	    }
		    /**
		     * This function is not optimized.
		     */
		    public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)
		    {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24));
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
    			
			    int[] out_buf = (int[]) i_output.getBuffer();
			    byte[] in_buf = (byte[]) i_input.getBuffer();

			    int bp = 0;
			    for (int y = 0; y < i_size.h; y++){
				    for (int x = 0; x < i_size.w; x++){
					    out_buf[y*i_size.w+x]=(306*(in_buf[bp+2] & 0xff)+601*(in_buf[bp + 1] & 0xff)+117 * (in_buf[bp + 0] & 0xff))>>10;
					    bp += 3;
				    }
			    }
			    return;
		    }
 protected abstract bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out);
 public bool isSupport(INyARRaster i_in, INyARRaster i_out)
 {
     return(i_in.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24) && i_out.isEqualBufferType(NyARBufferType.INT1D_X7H9S8V8_32));
 }
 public NyARRgb2GsFilterRgbAve_INT1D_X8R8G8B8_32(INyARRaster i_ref_raster)
 {
     Debug.Assert(i_ref_raster.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
     this._ref_raster = i_ref_raster;
 }
Example #14
0
        protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out)
        {
            BitmapData in_bmp  = this._ref_raster.lockBitmap();
            int        in_w    = this._ref_raster.getWidth();
            int        in_h    = this._ref_raster.getHeight();
            int        res_pix = i_resolution * i_resolution;

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];
            double cp2 = cpara[2];
            double cp5 = cpara[5];

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();

            if (o_out is NyARBitmapRaster)
            {
                NyARBitmapRaster bmr = ((NyARBitmapRaster)o_out);
                BitmapData       bm  = bmr.lockBitmap();
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        int r, g, b;
                        r = g = b = 0;
                        int    cy = pk_t + iy * i_resolution;
                        int    cx = pk_l + ix * i_resolution;
                        double cp7_cy_1_cp6_cx_b   = cp7 * cy + 1.0 + cp6 * cx;
                        double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                        double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                        for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                        {
                            double cp7_cy_1_cp6_cx   = cp7_cy_1_cp6_cx_b;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                            for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0)
                                {
                                    x = 0;
                                }
                                else if (x >= in_w)
                                {
                                    x = in_w - 1;
                                }
                                if (y < 0)
                                {
                                    y = 0;
                                }
                                else if (y >= in_h)
                                {
                                    y = in_h - 1;
                                }

                                int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                                r += (px >> 16) & 0xff; // R
                                g += (px >> 8) & 0xff;  // G
                                b += (px) & 0xff;       // B
                                cp7_cy_1_cp6_cx   += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b   += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride,
                                           (0x00ff0000 & ((r / res_pix) << 16)) | (0x0000ff00 & ((g / res_pix) << 8)) | (0x0000ff & (b / res_pix)));
                    }
                }
                bmr.unlockBitmap();
                this._ref_raster.unlockBitmap();
                return(true);
            }
            else if (o_out is INyARRgbRaster)
            {
                INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        int r, g, b;
                        r = g = b = 0;
                        int    cy = pk_t + iy * i_resolution;
                        int    cx = pk_l + ix * i_resolution;
                        double cp7_cy_1_cp6_cx_b   = cp7 * cy + 1.0 + cp6 * cx;
                        double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                        double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                        for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                        {
                            double cp7_cy_1_cp6_cx   = cp7_cy_1_cp6_cx_b;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                            for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0)
                                {
                                    x = 0;
                                }
                                else if (x >= in_w)
                                {
                                    x = in_w - 1;
                                }
                                if (y < 0)
                                {
                                    y = 0;
                                }
                                else if (y >= in_h)
                                {
                                    y = in_h - 1;
                                }

                                int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                                r += (px >> 16) & 0xff; // R
                                g += (px >> 8) & 0xff;  // G
                                b += (px) & 0xff;       // B
                                cp7_cy_1_cp6_cx   += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b   += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix);
                    }
                }
                this._ref_raster.unlockBitmap();
                return(true);
            }
            else
            {
                throw new NyARException();
            }
        }
        /**
         * この関数は、画像を処理して、適切なマーカ検出イベントハンドラを呼び出します。
         * イベントハンドラの呼び出しは、この関数を呼び出したスレッドが、この関数が終了するまでに行います。
         * @param i_raster
         * 検出処理をする画像を指定します。
         * @
         */
        public void detectMarker(INyARRgbRaster i_raster)
        {
            // サイズチェック
            Debug.Assert(this._gs_raster.getSize().isEqualSize(i_raster.getSize().w, i_raster.getSize().h));
            if (this._last_input_raster != i_raster)
            {
                this._histmaker = (INyARHistogramFromRaster)this._gs_raster.createInterface(typeof(INyARHistogramFromRaster));
                this._togs_filter = (INyARRgb2GsFilter)i_raster.createInterface(typeof(INyARRgb2GsFilter));
                this._last_input_raster = i_raster;
            }

            //GSイメージへの変換とヒストグラムの生成
            this._togs_filter.convert(this._gs_raster);
            this._histmaker.createHistogram(4, this._hist);

            // スクエアコードを探す
            this._detectmarker.init(i_raster, this._current_arcode_index);
            this._detectmarker.detectMarker(this._gs_raster, this._thdetect.getThreshold(this._hist),this._detectmarker);

            // 認識状態を更新
            this.updateStatus(this._detectmarker.square, this._detectmarker.code_index);
            return;
        }
 public void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
 {
     throw new NyARException();
 }
 public void switchRaster(INyARRaster i_ref_raster)
 {
     if (!(i_ref_raster is INyARRgbRaster))
     {
         throw new NyARException();
     }
     this._rgbd = ((INyARRgbRaster)i_ref_raster).getRgbPixelDriver();
 }
 public PerspectiveCopy_BYTE1D_R8G8B8_24(INyARRaster i_ref_raster)
 {
     this._ref_raster = (INyARRgbRaster)i_ref_raster;
 }
 public PerspectiveCopy_BYTE1D_B8G8R8X8_32(INyARRaster i_ref_raster)
 {
     this._ref_raster = (INyARRgbRaster)i_ref_raster;
 }
        protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out)
        {
            int res_pix = i_resolution * i_resolution;

            int[] rgb_tmp = this.__pickFromRaster_rgb_tmp;
            int   in_w    = this._ref_raster.getWidth();
            int   in_h    = this._ref_raster.getHeight();
            INyARRgbPixelDriver i_in_reader = this._ref_raster.getRgbPixelDriver();

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];
            double cp2 = cpara[2];
            double cp5 = cpara[5];

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();

            switch (o_out.getBufferType())
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
                int[] pat_data = (int[])o_out.getBuffer();
                int   p        = (out_w * out_h - 1);
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        int r, g, b;
                        r = g = b = 0;
                        int    cy = pk_t + iy * i_resolution;
                        int    cx = pk_l + ix * i_resolution;
                        double cp7_cy_1_cp6_cx_b   = cp7 * cy + 1.0 + cp6 * cx;
                        double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                        double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                        for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                        {
                            double cp7_cy_1_cp6_cx   = cp7_cy_1_cp6_cx_b;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                            for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0)
                                {
                                    x = 0;
                                }
                                else if (x >= in_w)
                                {
                                    x = in_w - 1;
                                }
                                if (y < 0)
                                {
                                    y = 0;
                                }
                                else if (y >= in_h)
                                {
                                    y = in_h - 1;
                                }

                                i_in_reader.getPixel(x, y, rgb_tmp);
                                r += rgb_tmp[0];
                                g += rgb_tmp[1];
                                b += rgb_tmp[2];
                                cp7_cy_1_cp6_cx   += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b   += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        r          /= res_pix;
                        g          /= res_pix;
                        b          /= res_pix;
                        pat_data[p] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | ((b & 0xff));
                        p--;
                    }
                }
                return(true);

            default:
                //ANY to RGBx
                if (o_out is INyARRgbRaster)
                {
                    INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                    for (int iy = out_h - 1; iy >= 0; iy--)
                    {
                        //解像度分の点を取る。
                        for (int ix = out_w - 1; ix >= 0; ix--)
                        {
                            int r, g, b;
                            r = g = b = 0;
                            int    cy = pk_t + iy * i_resolution;
                            int    cx = pk_l + ix * i_resolution;
                            double cp7_cy_1_cp6_cx_b   = cp7 * cy + 1.0 + cp6 * cx;
                            double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                            double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                            for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                            {
                                double cp7_cy_1_cp6_cx   = cp7_cy_1_cp6_cx_b;
                                double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                                double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                                for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                                {
                                    //1ピクセルを作成
                                    double d = 1 / (cp7_cy_1_cp6_cx);
                                    int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                    int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                    if (x < 0)
                                    {
                                        x = 0;
                                    }
                                    else if (x >= in_w)
                                    {
                                        x = in_w - 1;
                                    }
                                    if (y < 0)
                                    {
                                        y = 0;
                                    }
                                    else if (y >= in_h)
                                    {
                                        y = in_h - 1;
                                    }

                                    i_in_reader.getPixel(x, y, rgb_tmp);
                                    r += rgb_tmp[0];
                                    g += rgb_tmp[1];
                                    b += rgb_tmp[2];
                                    cp7_cy_1_cp6_cx   += cp6;
                                    cp1_cy_cp2_cp0_cx += cp0;
                                    cp4_cy_cp5_cp3_cx += cp3;
                                }
                                cp7_cy_1_cp6_cx_b   += cp7;
                                cp1_cy_cp2_cp0_cx_b += cp1;
                                cp4_cy_cp5_cp3_cx_b += cp4;
                            }
                            out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix);
                        }
                    }
                    return(true);
                }
                break;
            }
            return(false);
        }
        private int imple_labeling(INyARRaster i_raster, int i_th, int i_top, int i_bottom, RleLabelFragmentInfoStack o_stack)
        {
            // リセット処理
            RleInfoStack rlestack = this._rlestack;

            rlestack.clear();

            //
            RleElement[] rle_prev    = this._rle1;
            RleElement[] rle_current = this._rle2;
            int          len_prev    = 0;
            int          len_current = 0;
            int          width       = i_raster.getWidth();

            int[] in_buf = (int[])i_raster.getBuffer();

            int id_max      = 0;
            int label_count = 0;

            // 初段登録

            len_prev = toRel(in_buf, i_top, width, rle_prev, i_th);
            for (int i = 0; i < len_prev; i++)
            {
                // フラグメントID=フラグメント初期値、POS=Y値、RELインデクス=行
                addFragment(rle_prev[i], id_max, i_top, rlestack);
                id_max++;
                // nofの最大値チェック
                label_count++;
            }
            RleInfoStack.RleInfo[] f_array = rlestack.getArray();
            // 次段結合
            for (int y = i_top + 1; y < i_bottom; y++)
            {
                // カレント行の読込
                len_current = toRel(in_buf, y * width, width, rle_current, i_th);
                int index_prev = 0;

                for (int i = 0; i < len_current; i++)
                {
                    // index_prev,len_prevの位置を調整する
                    int id = -1;
                    // チェックすべきprevがあれば確認
                    while (index_prev < len_prev)
                    {
                        if (rle_current[i].l - rle_prev[index_prev].r > 0)
                        {// 0なら8方位ラベリング
                            // prevがcurの左方にある→次のフラグメントを探索
                            index_prev++;
                            continue;
                        }
                        else if (rle_prev[index_prev].l - rle_current[i].r > 0)
                        {// 0なら8方位ラベリングになる
                            // prevがcur右方にある→独立フラグメント
                            addFragment(rle_current[i], id_max, y, rlestack);
                            id_max++;
                            label_count++;
                            // 次のindexをしらべる
                            goto SCAN_CUR;
                        }
                        id = rle_prev[index_prev].fid;//ルートフラグメントid
                        RleInfoStack.RleInfo id_ptr = f_array[id];
                        //結合対象(初回)->prevのIDをコピーして、ルートフラグメントの情報を更新
                        rle_current[i].fid = id;//フラグメントIDを保存
                        //
                        int l   = rle_current[i].l;
                        int r   = rle_current[i].r;
                        int len = r - l;
                        //結合先フラグメントの情報を更新する。
                        id_ptr.area += len;
                        //tとentry_xは、結合先のを使うので更新しない。
                        id_ptr.clip_l = l < id_ptr.clip_l ? l : id_ptr.clip_l;
                        id_ptr.clip_r = r > id_ptr.clip_r ? r - 1 : id_ptr.clip_r;
                        id_ptr.clip_b = y;
                        id_ptr.pos_x += (len * (2 * l + (len - 1))) / 2;
                        id_ptr.pos_y += y * len;
                        //多重結合の確認(2個目以降)
                        index_prev++;
                        while (index_prev < len_prev)
                        {
                            if (rle_current[i].l - rle_prev[index_prev].r > 0)
                            {// 0なら8方位ラベリング
                                // prevがcurの左方にある→prevはcurに連結していない。
                                goto SCAN_PREV;
                            }
                            else if (rle_prev[index_prev].l - rle_current[i].r > 0)
                            {// 0なら8方位ラベリングになる
                                // prevがcurの右方にある→prevはcurに連結していない。
                                index_prev--;
                                goto SCAN_CUR;
                            }
                            // prevとcurは連結している→ルートフラグメントの統合

                            //結合するルートフラグメントを取得
                            int prev_id = rle_prev[index_prev].fid;
                            RleInfoStack.RleInfo prev_ptr = f_array[prev_id];
                            if (id != prev_id)
                            {
                                label_count--;
                                //prevとcurrentのフラグメントidを書き換える。
                                for (int i2 = index_prev; i2 < len_prev; i2++)
                                {
                                    //prevは現在のidから最後まで
                                    if (rle_prev[i2].fid == prev_id)
                                    {
                                        rle_prev[i2].fid = id;
                                    }
                                }
                                for (int i2 = 0; i2 < i; i2++)
                                {
                                    //currentは0から現在-1まで
                                    if (rle_current[i2].fid == prev_id)
                                    {
                                        rle_current[i2].fid = id;
                                    }
                                }

                                //現在のルートフラグメントに情報を集約
                                id_ptr.area  += prev_ptr.area;
                                id_ptr.pos_x += prev_ptr.pos_x;
                                id_ptr.pos_y += prev_ptr.pos_y;
                                //tとentry_xの決定
                                if (id_ptr.clip_t > prev_ptr.clip_t)
                                {
                                    // 現在の方が下にある。
                                    id_ptr.clip_t  = prev_ptr.clip_t;
                                    id_ptr.entry_x = prev_ptr.entry_x;
                                }
                                else if (id_ptr.clip_t < prev_ptr.clip_t)
                                {
                                    // 現在の方が上にある。prevにフィードバック
                                }
                                else
                                {
                                    // 水平方向で小さい方がエントリポイント。
                                    if (id_ptr.entry_x > prev_ptr.entry_x)
                                    {
                                        id_ptr.entry_x = prev_ptr.entry_x;
                                    }
                                    else
                                    {
                                    }
                                }
                                //lの決定
                                if (id_ptr.clip_l > prev_ptr.clip_l)
                                {
                                    id_ptr.clip_l = prev_ptr.clip_l;
                                }
                                else
                                {
                                }
                                //rの決定
                                if (id_ptr.clip_r < prev_ptr.clip_r)
                                {
                                    id_ptr.clip_r = prev_ptr.clip_r;
                                }
                                else
                                {
                                }
                                //bの決定

                                //結合済のルートフラグメントを無効化する。
                                prev_ptr.area = 0;
                            }


                            index_prev++;
                        }
                        index_prev--;
                        break;
                        SCAN_PREV :;
                    }
                    // curにidが割り当てられたかを確認
                    // 右端独立フラグメントを追加
                    if (id < 0)
                    {
                        addFragment(rle_current[i], id_max, y, rlestack);
                        id_max++;
                        label_count++;
                    }
                    SCAN_CUR :;
                }
                // prevとrelの交換
                RleElement[] tmp = rle_prev;
                rle_prev    = rle_current;
                len_prev    = len_current;
                rle_current = tmp;
            }
            //対象のラベルだけ転写
            o_stack.init(label_count);
            RleLabelFragmentInfoStack.RleLabelFragmentInfo[] o_dest_array = o_stack.getArray();
            int max           = this._max_area;
            int min           = this._min_area;
            int active_labels = 0;

            for (int i = id_max - 1; i >= 0; i--)
            {
                int area = f_array[i].area;
                if (area < min || area > max)
                {//対象外のエリア0のもminではじく
                    continue;
                }
                //
                RleInfoStack.RleInfo src_info = f_array[i];
                RleLabelFragmentInfoStack.RleLabelFragmentInfo dest_info = o_dest_array[active_labels];
                dest_info.area    = area;
                dest_info.clip_b  = src_info.clip_b;
                dest_info.clip_r  = src_info.clip_r;
                dest_info.clip_t  = src_info.clip_t;
                dest_info.clip_l  = src_info.clip_l;
                dest_info.entry_x = src_info.entry_x;
                dest_info.pos_x   = src_info.pos_x / src_info.area;
                dest_info.pos_y   = src_info.pos_y / src_info.area;
                active_labels++;
            }
            //ラベル数を再設定
            o_stack.pops(label_count - active_labels);
            //ラベル数を返却
            return(active_labels);
        }
Example #22
0
        /**
         * 輪郭線抽出関数の実体です。
         * @param i_raster
         * @param i_l
         * @param i_t
         * @param i_r
         * @param i_b
         * @param i_th
         * @param i_entry_x
         * @param i_entry_y
         * @param o_coord
         * @return
         * @throws NyARException
         */
        private bool impl_getContour(INyARRaster i_raster, int i_l, int i_t, int i_r, int i_b, int i_th, int i_entry_x, int i_entry_y, NyARIntCoordinates o_coord)
        {
            Debug.Assert(i_t <= i_entry_x);
            NyARIntPoint2d[] coord = o_coord.items;
            int[]            xdir  = _getContour_xdir; // static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};
            int[]            ydir  = _getContour_ydir; // static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1};

            int[] buf   = (int[])i_raster.getBuffer();
            int   width = i_raster.getWidth();
            //クリップ領域の上端に接しているポイントを得る。


            int max_coord = o_coord.items.Length;
            int coord_num = 1;

            coord[0].x = i_entry_x;
            coord[0].y = i_entry_y;
            int dir = 5;

            int c = i_entry_x;
            int r = i_entry_y;

            for (;;)
            {
                dir = (dir + 5) % 8;            //dirの正規化
                //ここは頑張ればもっと最適化できると思うよ。
                //4隅以外の境界接地の場合に、境界チェックを省略するとかね。
                if (c > i_l && c < i_r && r > i_t && r < i_b)
                {
                    for (;;)                //gotoのエミュレート用のfor文
                                            //境界に接していないとき(暗点判定)
                    {
                        if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }

                        //8方向全て調べたけどラベルが無いよ?
                        throw new NyARException();
                    }
                }
                else
                {
                    //境界に接しているとき
                    int i;
                    for (i = 0; i < 8; i++)
                    {
                        int x = c + xdir[dir];
                        int y = r + ydir[dir];
                        //境界チェック
                        if (x >= i_l && x <= i_r && y >= i_t && y <= i_b)
                        {
                            if (buf[(y) * width + (x)] <= i_th)
                            {
                                break;
                            }
                        }
                        dir++;                    //倍長テーブルを参照するので問題なし
                    }
                    if (i == 8)
                    {
                        //8方向全て調べたけどラベルが無いよ?
                        throw new NyARException();                    // return(-1);
                    }
                }

                // xcoordとycoordをc,rにも保存
                c = c + xdir[dir];
                r = r + ydir[dir];
                coord[coord_num].x = c;
                coord[coord_num].y = r;
                //終了条件判定
                if (c == i_entry_x && r == i_entry_y)
                {
                    //開始点と同じピクセルに到達したら、終点の可能性がある。
                    coord_num++;
                    //末端のチェック
                    if (coord_num == max_coord)
                    {
                        //輪郭bufが末端に達した
                        return(false);
                    }
                    //末端候補の次のピクセルを調べる
                    dir = (dir + 5) % 8;                //dirの正規化
                    int i;
                    for (i = 0; i < 8; i++)
                    {
                        int x = c + xdir[dir];
                        int y = r + ydir[dir];
                        //境界チェック
                        if (x >= i_l && x <= i_r && y >= i_t && y <= i_b)
                        {
                            if (buf[(y) * width + (x)] <= i_th)
                            {
                                break;
                            }
                        }
                        dir++;                    //倍長テーブルを参照するので問題なし
                    }
                    if (i == 8)
                    {
                        //8方向全て調べたけどラベルが無いよ?
                        throw new NyARException();
                    }
                    //得たピクセルが、[1]と同じならば、末端である。
                    c = c + xdir[dir];
                    r = r + ydir[dir];
                    if (coord[1].x == c && coord[1].y == r)
                    {
                        //終点に達している。
                        o_coord.length = coord_num;
                        break;
                    }
                    else
                    {
                        //終点ではない。
                        coord[coord_num].x = c;
                        coord[coord_num].y = r;
                    }
                }
                coord_num++;
                //末端のチェック
                if (coord_num == max_coord)
                {
                    //輪郭が末端に達した
                    return(false);
                }
            }
            return(true);
        }
Example #23
0
 public NyARHistogramFromRaster_INTGS8(INyARRaster i_raster)
 {
     this._gsr = i_raster;
 }
		    public void doThFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size,int i_threshold)
		    {
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_BIN_8));
    			
			    int[] out_buf = (int[]) i_output.getBuffer();
			    short[] in_buf = (short[]) i_input.getBuffer();
    			
			    int th=i_threshold*3;
			    int w;
			    int xy;
			    int pix_count   =i_size.h*i_size.w;
			    int pix_mod_part=pix_count-(pix_count%8);

			    for(xy=pix_count-1;xy>=pix_mod_part;xy--){				
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
			    }
			    //タイリング
			    for (;xy>=0;) {
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
			    }
		    }		
 public void switchRaster(INyARRaster i_ref_raster)
 {
     this._ref_buf = (int[])i_ref_raster.getBuffer();
     this._ref_size = i_ref_raster.getSize();
 }
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            byte[] i_in_buf = (byte[])this._ref_raster.getBuffer();
            int    in_w     = this._ref_raster.getWidth();
            int    in_h     = this._ref_raster.getHeight();
            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

            int    out_w = o_out.getWidth();
            int    out_h = o_out.getHeight();
            double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l;
            double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l;
            double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l;
            int    r, g, b;

            switch (this._ref_raster.getBufferType())
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
                int   p        = 0;
                int[] pat_data = (int[])o_out.getBuffer();
                for (int iy = 0; iy < out_h; iy++)
                {
                    //解像度分の点を取る。
                    double cp7_cy_1_cp6_cx   = cp7_cy_1;
                    double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                    double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                    for (int ix = 0; ix < out_w; ix++)
                    {
                        //1ピクセルを作成
                        double d = 1 / (cp7_cy_1_cp6_cx);
                        int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                        int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                        if (x < 0)
                        {
                            x = 0;
                        }
                        else if (x >= in_w)
                        {
                            x = in_w - 1;
                        }
                        if (y < 0)
                        {
                            y = 0;
                        }
                        else if (y >= in_h)
                        {
                            y = in_h - 1;
                        }

                        int bp = (x + y * in_w) * 3;
                        r = (i_in_buf[bp + 0] & 0xff);
                        g = (i_in_buf[bp + 1] & 0xff);
                        b = (i_in_buf[bp + 2] & 0xff);
                        cp7_cy_1_cp6_cx   += cp6;
                        cp1_cy_cp2_cp0_cx += cp0;
                        cp4_cy_cp5_cp3_cx += cp3;
                        pat_data[p]        = (r << 16) | (g << 8) | ((b & 0xff));
                        p++;
                    }
                    cp7_cy_1   += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                return(true);

            default:
                if (o_out is INyARRgbRaster)
                {
                    INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx   = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            else if (x >= in_w)
                            {
                                x = in_w - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            else if (y >= in_h)
                            {
                                y = in_h - 1;
                            }

                            int bp = (x + y * in_w) * 3;
                            r = (i_in_buf[bp + 0] & 0xff);
                            g = (i_in_buf[bp + 1] & 0xff);
                            b = (i_in_buf[bp + 2] & 0xff);
                            cp7_cy_1_cp6_cx   += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;

                            out_reader.setPixel(ix, iy, r, g, b);
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    return(true);
                }
                break;
            }
            return(false);
        }
	    public virtual void doFilter(INyARRaster i_input, INyARRaster i_output) 
	    {
		    Debug.Assert (i_input.getSize().isEqualSize(i_output.getSize()) == true);
		    this._dofilterimpl.doFilter(i_input,i_output,i_input.getSize());
	    }
 public PerspectiveCopy_ANYRgb(INyARRaster i_ref_raster)
 {
     this._ref_raster = (INyARRgbRaster)i_ref_raster;
 }
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            Color32[] in_pixs = (Color32[])this._ref_raster.getBuffer();
            int in_w = this._ref_raster.getWidth();
            int in_h = this._ref_raster.getHeight();

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();
            double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l;
            double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l;
            double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l;
            int p;
			
			int step,offset;
			//flip Virtical
            switch (o_out.getBufferType())
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
	            int[] pat_data = (int[])o_out.getBuffer();
                p = 0;
				if(this._is_inv_v){
					offset=in_w*(in_h-1);
					step=-in_w;
				}else{
					offset=0;
					step=in_w;
				}				
                for (int iy = 0; iy < out_h; iy++)
                {
                    //解像度分の点を取る。
                    double cp7_cy_1_cp6_cx = cp7_cy_1;
                    double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                    double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                    for (int ix = 0; ix < out_w; ix++)
                    {
                        //1ピクセルを作成
                        double d = 1 / (cp7_cy_1_cp6_cx);
                        int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                        int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                        if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                        if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }
					
						Color32 pix=in_pixs[x + offset+step*y];
                        //
                        pat_data[p] = ((pix.r << 16) & 0xff)|((pix.g << 8) & 0xff)| pix.b;
                        cp7_cy_1_cp6_cx += cp6;
                        cp1_cy_cp2_cp0_cx += cp0;
                        cp4_cy_cp5_cp3_cx += cp3;
                        p++;
                    }
                    cp7_cy_1 += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                return true;		
            case NyARBufferType.OBJECT_CS_Unity:
				Color32[] out_buf = (Color32[])(((INyARRgbRaster)o_out).getBuffer());
				if(this._is_inv_v==((NyARUnityRaster)o_out).isFlipVirtical()){
					offset=in_w*(in_h-1);
					step=-in_w;
				}else{
					offset=0;
					step=in_w;
				}				
                for (int iy = 0; iy < out_h; iy++)
                {
                    //解像度分の点を取る。
                    double cp7_cy_1_cp6_cx = cp7_cy_1;
                    double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                    double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;
					int ys=out_h-1-iy;
                    for (int ix = 0; ix < out_w; ix++)
                    {
                        //1ピクセルを作成
                        double d = 1 / (cp7_cy_1_cp6_cx);
                        int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                        int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                        if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                        if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }
					
						out_buf[ix+ys*out_w]=in_pixs[x + offset+step*y];
                        //
                        cp7_cy_1_cp6_cx += cp6;
                        cp1_cy_cp2_cp0_cx += cp0;
                        cp4_cy_cp5_cp3_cx += cp3;
                    }
                    cp7_cy_1 += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                return true;
            default:
                //ANY to RGBx
                if (o_out is INyARRgbRaster)
                {
                    INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
					if(this._is_inv_v){
						offset=in_w*(in_h-1);
						step=-in_w;
					}else{
						offset=0;
						step=in_w;
					}
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                            if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }
                        	Color32 px = in_pixs[x + offset+step*y];
                            cp7_cy_1_cp6_cx += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            out_reader.setPixel(ix, iy,px.r,px.g,px.b);
                        }
                        cp7_cy_1 += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
	                return true;
				}
				break;
			}
            return false;
        }
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            int[] rgb_tmp = this.__pickFromRaster_rgb_tmp;
            int   in_w    = this._ref_raster.getWidth();
            int   in_h    = this._ref_raster.getHeight();

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

            int    out_w      = o_out.getWidth();
            int    out_h      = o_out.getHeight();
            double cp7_cy_1   = cp7 * pk_t + 1.0 + cp6 * pk_l;
            double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l;
            double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l;

            INyARRgbPixelDriver i_in_reader = this._ref_raster.getRgbPixelDriver();

            switch (o_out.getBufferType())
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
                int[] pat_data = (int[])o_out.getBuffer();
                int   p        = 0;
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    double cp7_cy_1_cp6_cx   = cp7_cy_1;
                    double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                    double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        //1ピクセルを作成
                        double d = 1 / (cp7_cy_1_cp6_cx);
                        int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                        int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                        if (x < 0)
                        {
                            x = 0;
                        }
                        else if (x >= in_w)
                        {
                            x = in_w - 1;
                        }
                        if (y < 0)
                        {
                            y = 0;
                        }
                        else if (y >= in_h)
                        {
                            y = in_h - 1;
                        }

                        i_in_reader.getPixel(x, y, rgb_tmp);
                        cp7_cy_1_cp6_cx   += cp6;
                        cp1_cy_cp2_cp0_cx += cp0;
                        cp4_cy_cp5_cp3_cx += cp3;

                        pat_data[p] = (rgb_tmp[0] << 16) | (rgb_tmp[1] << 8) | ((rgb_tmp[2] & 0xff));
                        p++;
                    }
                    cp7_cy_1   += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                return(true);

            default:
                //ANY to RGBx
                if (o_out is INyARRgbRaster)
                {
                    INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx   = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;
                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            else if (x >= in_w)
                            {
                                x = in_w - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            else if (y >= in_h)
                            {
                                y = in_h - 1;
                            }

                            i_in_reader.getPixel(x, y, rgb_tmp);
                            cp7_cy_1_cp6_cx   += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;

                            out_reader.setPixel(ix, iy, rgb_tmp);
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    return(true);
                }
                break;
            }
            return(false);
        }
Example #31
0
 public NyARRlePixelDriver_BIN_GS8(INyARRaster i_ref_raster)
 {
     this._ref_raster = i_ref_raster;
 }
        protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out)
        {
            int res_pix = i_resolution * i_resolution;

            byte[] i_in_buf = (byte[])this._ref_raster.getBuffer();
            int    in_w     = this._ref_raster.getWidth();
            int    in_h     = this._ref_raster.getHeight();

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];
            double cp2 = cpara[2];
            double cp5 = cpara[5];

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();

            if (o_out is INyARRgbRaster)
            {
                INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        int r, g, b;
                        r = g = b = 0;
                        int    cy = pk_t + iy * i_resolution;
                        int    cx = pk_l + ix * i_resolution;
                        double cp7_cy_1_cp6_cx_b   = cp7 * cy + 1.0 + cp6 * cx;
                        double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                        double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                        for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                        {
                            double cp7_cy_1_cp6_cx   = cp7_cy_1_cp6_cx_b;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                            for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0)
                                {
                                    x = 0;
                                }
                                else if (x >= in_w)
                                {
                                    x = in_w - 1;
                                }
                                if (y < 0)
                                {
                                    y = 0;
                                }
                                else if (y >= in_h)
                                {
                                    y = in_h - 1;
                                }

                                int bp = (x + y * in_w) * 3;
                                r += (i_in_buf[bp + 0] & 0xff);
                                g += (i_in_buf[bp + 1] & 0xff);
                                b += (i_in_buf[bp + 2] & 0xff);
                                cp7_cy_1_cp6_cx   += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b   += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix);
                    }
                }
                return(true);
            }
            return(false);
        }
 public NyARRgb2GsFilterRgbAve_BYTE1D_C8C8C8_24(INyARRaster i_ref_raster)
 {
     Debug.Assert(i_ref_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24) || i_ref_raster.isEqualBufferType(NyARBufferType.BYTE1D_R8G8B8_24));
     this._ref_raster = i_ref_raster;
 }
Example #34
0
        private void imple_labeling(INyARRaster i_raster, int i_th, int i_left, int i_top, int i_width, int i_height)
        {
            //ラスタのサイズを確認
            Debug.Assert(i_raster.getSize().isEqualSize(this._raster_size));

            RleElement[] rle_prev    = this._rle1;
            RleElement[] rle_current = this._rle2;
            // リセット処理
            RleInfoStack rlestack = this._rlestack;

            rlestack.clear();

            //
            int len_prev    = 0;
            int len_current = 0;
            int bottom      = i_top + i_height;
            int row_stride  = this._raster_size.w;

            int[] in_buf = (int[])i_raster.getBuffer();

            int id_max        = 0;
            int label_count   = 0;
            int rle_top_index = i_left + row_stride * i_top;

            // 初段登録

            len_prev = toRel(in_buf, rle_top_index, i_width, rle_prev, i_th);
            for (int i = 0; i < len_prev; i++)
            {
                // フラグメントID=フラグメント初期値、POS=Y値、RELインデクス=行
                if (addFragment(rle_prev[i], id_max, i_top, rlestack))
                {
                    id_max++;
                    // nofの最大値チェック
                    label_count++;
                }
            }
            NyARRleLabelFragmentInfo[] f_array = rlestack.getArray();
            // 次段結合
            for (int y = i_top + 1; y < bottom; y++)
            {
                // カレント行の読込
                rle_top_index += row_stride;
                len_current    = toRel(in_buf, rle_top_index, i_width, rle_current, i_th);
                int index_prev = 0;

                for (int i = 0; i < len_current; i++)
                {
                    // index_prev,len_prevの位置を調整する
                    int id = -1;
                    // チェックすべきprevがあれば確認
                    while (index_prev < len_prev)
                    {
                        if (rle_current[i].l - rle_prev[index_prev].r > 0)                      // 0なら8方位ラベリング
                        // prevがcurの左方にある→次のフラグメントを探索
                        {
                            index_prev++;
                            continue;
                        }
                        else if (rle_prev[index_prev].l - rle_current[i].r > 0)                        // 0なら8方位ラベリングになる
                        // prevがcur右方にある→独立フラグメント
                        {
                            if (addFragment(rle_current[i], id_max, y, rlestack))
                            {
                                id_max++;
                                label_count++;
                            }
                            // 次のindexをしらべる
                            goto SCAN_CUR;
                        }
                        id = rle_prev[index_prev].fid;                  //ルートフラグメントid
                        NyARRleLabelFragmentInfo id_ptr = f_array[id];
                        //結合対象(初回)->prevのIDをコピーして、ルートフラグメントの情報を更新
                        rle_current[i].fid = id;                    //フラグメントIDを保存
                        //
                        int l   = rle_current[i].l;
                        int r   = rle_current[i].r;
                        int len = r - l;
                        //結合先フラグメントの情報を更新する。
                        id_ptr.area += len;
                        //tとentry_xは、結合先のを使うので更新しない。
                        id_ptr.clip_l = l < id_ptr.clip_l?l:id_ptr.clip_l;
                        id_ptr.clip_r = r > id_ptr.clip_r?r - 1:id_ptr.clip_r;
                        id_ptr.clip_b = y;
                        id_ptr.pos_x += (len * (2 * l + (len - 1))) / 2;
                        id_ptr.pos_y += y * len;
                        //多重結合の確認(2個目以降)
                        index_prev++;
                        while (index_prev < len_prev)
                        {
                            if (rle_current[i].l - rle_prev[index_prev].r > 0)                          // 0なら8方位ラベリング
                            // prevがcurの左方にある→prevはcurに連結していない。
                            {
                                goto SCAN_PREV;
                            }
                            else if (rle_prev[index_prev].l - rle_current[i].r > 0)                            // 0なら8方位ラベリングになる
                            // prevがcurの右方にある→prevはcurに連結していない。
                            {
                                index_prev--;
                                goto SCAN_CUR;
                            }
                            // prevとcurは連結している→ルートフラグメントの統合

                            //結合するルートフラグメントを取得
                            int prev_id = rle_prev[index_prev].fid;
                            NyARRleLabelFragmentInfo prev_ptr = f_array[prev_id];
                            if (id != prev_id)
                            {
                                label_count--;
                                //prevとcurrentのフラグメントidを書き換える。
                                for (int i2 = index_prev; i2 < len_prev; i2++)
                                {
                                    //prevは現在のidから最後まで
                                    if (rle_prev[i2].fid == prev_id)
                                    {
                                        rle_prev[i2].fid = id;
                                    }
                                }
                                for (int i2 = 0; i2 < i; i2++)
                                {
                                    //currentは0から現在-1まで
                                    if (rle_current[i2].fid == prev_id)
                                    {
                                        rle_current[i2].fid = id;
                                    }
                                }

                                //現在のルートフラグメントに情報を集約
                                id_ptr.area  += prev_ptr.area;
                                id_ptr.pos_x += prev_ptr.pos_x;
                                id_ptr.pos_y += prev_ptr.pos_y;
                                //tとentry_xの決定
                                if (id_ptr.clip_t > prev_ptr.clip_t)
                                {
                                    // 現在の方が下にある。
                                    id_ptr.clip_t  = prev_ptr.clip_t;
                                    id_ptr.entry_x = prev_ptr.entry_x;
                                }
                                else if (id_ptr.clip_t < prev_ptr.clip_t)
                                {
                                    // 現在の方が上にある。prevにフィードバック
                                }
                                else
                                {
                                    // 水平方向で小さい方がエントリポイント。
                                    if (id_ptr.entry_x > prev_ptr.entry_x)
                                    {
                                        id_ptr.entry_x = prev_ptr.entry_x;
                                    }
                                    else
                                    {
                                    }
                                }
                                //lの決定
                                if (id_ptr.clip_l > prev_ptr.clip_l)
                                {
                                    id_ptr.clip_l = prev_ptr.clip_l;
                                }
                                else
                                {
                                }
                                //rの決定
                                if (id_ptr.clip_r < prev_ptr.clip_r)
                                {
                                    id_ptr.clip_r = prev_ptr.clip_r;
                                }
                                else
                                {
                                }
                                //bの決定

                                //結合済のルートフラグメントを無効化する。
                                prev_ptr.area = 0;
                            }


                            index_prev++;
                        }
                        index_prev--;
                        break;
                        SCAN_PREV :;
                    }
                    // curにidが割り当てられたかを確認
                    // 右端独立フラグメントを追加
                    if (id < 0)
                    {
                        if (addFragment(rle_current[i], id_max, y, rlestack))
                        {
                            id_max++;
                            label_count++;
                        }
                    }
                    SCAN_CUR :;
                }
                // prevとrelの交換
                RleElement[] tmp = rle_prev;
                rle_prev    = rle_current;
                len_prev    = len_current;
                rle_current = tmp;
            }
            //対象のラベルだけを追記
            int max = this._max_area;
            int min = this._min_area;

            for (int i = id_max - 1; i >= 0; i--)
            {
                NyARRleLabelFragmentInfo src_info = f_array[i];
                int area = src_info.area;
                if (area < min || area > max)        //対象外のエリア0のもminではじく
                {
                    continue;
                }
                //値を相対位置に補正
                src_info.clip_l  += i_left;
                src_info.clip_r  += i_left;
                src_info.entry_x += i_left;
                src_info.pos_x   /= area;
                src_info.pos_y   /= area;
                //コールバック関数コール
                this.onLabelFound(src_info);
            }
        }
Example #35
0
 public void switchRaster(INyARRaster i_ref_raster)
 {
     this._ref_buf  = (int[])i_ref_raster.getBuffer();
     this._ref_size = i_ref_raster.getSize();
 }
 public void doFilter(INyARRaster i_input, INyARRaster i_output)
 {
     this._do_filter_impl.doFilter(i_input, i_output, i_input.getSize());
 }
            public void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                int[] in_ptr = (int[])i_input.getBuffer();
                int[] out_ptr = (int[])i_output.getBuffer();
                int   width = i_size.w;
                int   idx = 0;
                int   idx2 = width;
                int   fx, fy;
                int   mod_p = (width - 2) - (width - 2) % 4;

                for (int y = i_size.h - 2; y >= 0; y--)
                {
                    int p00 = in_ptr[idx++];
                    int p10 = in_ptr[idx2++];
                    int p01, p11;
                    int x = width - 2;
                    for (; x >= mod_p; x--)
                    {
                        p01 = in_ptr[idx++]; p11 = in_ptr[idx2++];
                        fx  = p11 - p00; fy = p10 - p01;
                        //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
                        fx  = (fx * fx + fy * fy) >> SH; out_ptr[idx - 2] = (fx > 255?0:255 - fx);
                        p00 = p01;
                        p10 = p11;
                    }
                    for (; x >= 0; x -= 4)
                    {
                        p01 = in_ptr[idx++]; p11 = in_ptr[idx2++];
                        fx  = p11 - p00;
                        fy  = p10 - p01;
                        //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
                        fx  = (fx * fx + fy * fy) >> SH; out_ptr[idx - 2] = (fx > 255?0:255 - fx);
                        p00 = p01; p10 = p11;
                        p01 = in_ptr[idx++]; p11 = in_ptr[idx2++];
                        fx  = p11 - p00;
                        fy  = p10 - p01;
                        //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
                        fx  = (fx * fx + fy * fy) >> SH; out_ptr[idx - 2] = (fx > 255?0:255 - fx);
                        p00 = p01; p10 = p11;
                        p01 = in_ptr[idx++]; p11 = in_ptr[idx2++];

                        fx = p11 - p00;
                        fy = p10 - p01;
                        //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
                        fx  = (fx * fx + fy * fy) >> SH; out_ptr[idx - 2] = (fx > 255?0:255 - fx);
                        p00 = p01; p10 = p11;

                        p01 = in_ptr[idx++]; p11 = in_ptr[idx2++];
                        fx  = p11 - p00;
                        fy  = p10 - p01;
                        //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
                        fx  = (fx * fx + fy * fy) >> SH; out_ptr[idx - 2] = (fx > 255?0:255 - fx);
                        p00 = p01; p10 = p11;
                    }
                    out_ptr[idx - 1] = 255;
                }
                for (int x = width - 1; x >= 0; x--)
                {
                    out_ptr[idx++] = 255;
                }
                return;
            }
 public bool isSupport(INyARRaster i_in, INyARRaster i_out)
 {
     return(false);
 }
		    public void doThFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size,int i_threshold)
		    {
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_BIN_8));
    			
			    int[] out_buf = (int[]) i_output.getBuffer();
			    byte[] in_buf = (byte[]) i_input.getBuffer();
    			
			    int th=i_threshold*3;
			    int bp =(i_size.w*i_size.h-1)*4;
			    int w;
			    int xy;
			    int pix_count   =i_size.h*i_size.w;
			    int pix_mod_part=pix_count-(pix_count%8);
			    for(xy=pix_count-1;xy>=pix_mod_part;xy--){
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
			    }
			    //タイリング
			    for (;xy>=0;) {
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
			    }
			    return;			
		    }
Example #40
0
        /**
         * NyARRasterからパターンデータをセットします。
         * この関数は、データを元に所有するデータ領域を更新します。
         * @param i_buffer
         */
        public void setRaster(INyARRaster i_raster)
        {
            //画素フォーマット、サイズ制限
            Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
            Debug.Assert(i_raster.getSize().isEqualSize(i_raster.getSize()));

            int[] buf = (int[])i_raster.getBuffer();
            //i_buffer[XRGB]→差分[R,G,B]変換
            int i;
            int ave;                   //<PV/>
            int rgb;                   //<PV/>

            int[] linput = this._data; //<PV/>

            // input配列のサイズとwhも更新// input=new int[height][width][3];
            int number_of_pixels = this._number_of_pixels;
            int for_mod          = this._optimize_for_mod;

            //<平均値計算(FORの1/8展開)>
            ave = 0;
            for (i = number_of_pixels - 1; i >= for_mod; i--)
            {
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);
            }
            for (; i >= 0;)
            {
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
            }
            //<平均値計算(FORの1/8展開)/>
            ave = number_of_pixels * 255 * 3 - ave;
            ave = 255 - (ave / (number_of_pixels * 3));//(255-R)-ave を分解するための事前計算

            int sum = 0, w_sum;
            int input_ptr = number_of_pixels * 3 - 1;

            //<差分値計算(FORの1/8展開)>
            for (i = number_of_pixels - 1; i >= for_mod; i--)
            {
                rgb   = buf[i];
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
            }
            for (; i >= 0;)
            {
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
            }
            //<差分値計算(FORの1/8展開)/>
            double p = Math.Sqrt((double)sum);

            this._pow = p != 0.0 ? p : 0.0000001;
            return;
        }
 public bool isCompatibleRaster(INyARRaster i_raster)
 {
     return i_raster.isEqualBufferType(NyARBufferType.INT1D_GRAY_8);
 }
 public bool isCompatibleRaster(INyARRaster i_raster)
 {
     return(i_raster.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
 }
 public bool isCompatibleRaster(INyARRaster i_raster)
 {
     return (i_raster is INyARRgbRaster);
 }
 public bool isCompatibleRaster(INyARRaster i_raster)
 {
     return(i_raster is INyARRgbRaster);
 }
            public void doThFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
            {
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_BIN_8));

                int[] out_buf = (int[])i_output.getBuffer();
                byte[] in_buf = (byte[])i_input.getBuffer();

                byte[] grey = new byte[i_size.w * i_size.h];
                ulong[] integralImg = new ulong[i_size.w * i_size.h];

                ulong sum = 0;
                float T = 0.15f;
                double s = i_size.w / 8;
                int x1, x2, y1, y2;
                int index, s2 = (int)(s / 2);
                int count = 0;

                // greyscale
                for (int i = 0, j = 0; i < in_buf.Length; )
                {
                    grey[j++] = (byte)
                        ((in_buf[i + 1] & 0xff) * 0.11 + // b
                        (in_buf[i + 2] & 0xff) * 0.59 + // g
                        (in_buf[i + 3] & 0xff) * 0.3); // r
                    i += 4; // skip alpha
                }

                // integral image
                for (int i = 0; i < i_size.w; i++)
                {
                    sum = 0; // cumulative row sum
                    for (int j = 0; j < i_size.h; j++)
                    {
                        index = j * i_size.w + i;
                        sum += grey[index];
                        if (i == 0)
                            integralImg[index] = (ulong)sum;
                        else
                            integralImg[index] = integralImg[index - 1] + (ulong)sum;
                    }
                }

                for (int i = 0; i < i_size.w; i++)
                {
                    for (int j = 0; j < i_size.h; j++)
                    {
                        index = j * i_size.w + i;

                        // set the SxS region
                        x1 = i - s2; x2 = i + s2;
                        y1 = j - s2; y2 = j + s2;

                        // check the border
                        if (x1 < 0) x1 = 0;
                        if (x2 >= i_size.w) x2 = i_size.w - 1;
                        if (y1 < 0) y1 = 0;
                        if (y2 >= i_size.h) y2 = i_size.h - 1;

                        count = (x2 - x1) * (y2 - y1);

                        sum = integralImg[y2 * i_size.w + x2] -
                              integralImg[y1 * i_size.w + x2] -
                              integralImg[y2 * i_size.w + x1] +
                              integralImg[y1 * i_size.w + x1];

                        if ((long)(grey[index] * count) < (long)(sum * (1.0 - T)))
                            out_buf[index] = 0;
                        else
                            out_buf[index] = 1;
                    }
                }

                return;
            }
 public NyARContourPickup_BIN_GS8(INyARRaster i_ref_raster)
 {
     this._ref_raster = i_ref_raster;
 }
		    public abstract void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size);
        protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out)
        {
            BitmapData in_bmp = this._ref_raster.lockBitmap();
            int in_w = this._ref_raster.getWidth();
            int in_h = this._ref_raster.getHeight();
            int res_pix = i_resolution * i_resolution;

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];
            double cp2 = cpara[2];
            double cp5 = cpara[5];

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();
            if (o_out is NyARBitmapRaster)
            {
                NyARBitmapRaster bmr=((NyARBitmapRaster)o_out);
                BitmapData bm=bmr.lockBitmap();
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        int r, g, b;
                        r = g = b = 0;
                        int cy = pk_t + iy * i_resolution;
                        int cx = pk_l + ix * i_resolution;
                        double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx;
                        double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                        double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                        for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                        {
                            double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                            for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                                if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }

                                int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                                r += (px >> 16) & 0xff;// R
                                g += (px >> 8) & 0xff; // G
                                b += (px) & 0xff;    // B
                                cp7_cy_1_cp6_cx += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride,
                            (0x00ff0000 & ((r / res_pix) << 16)) | (0x0000ff00 & ((g / res_pix) << 8)) | (0x0000ff & (b / res_pix)));
                    }
                }
                bmr.unlockBitmap();
                this._ref_raster.unlockBitmap();
                return true;
            }
            else if (o_out is INyARRgbRaster)
            {
                INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        int r, g, b;
                        r = g = b = 0;
                        int cy = pk_t + iy * i_resolution;
                        int cx = pk_l + ix * i_resolution;
                        double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx;
                        double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                        double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                        for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                        {
                            double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                            for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                                if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }

                                int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                                r += (px >> 16) & 0xff;// R
                                g += (px >> 8) & 0xff; // G
                                b += (px) & 0xff;    // B
                                cp7_cy_1_cp6_cx += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix);
                    }
                }
                this._ref_raster.unlockBitmap();
                return true;
            }
            else
            {
                throw new NyARException();
            }
        }
 public NyARHistogramFromRaster_INTGS8(INyARRaster i_raster)
 {
     this._gsr = i_raster;
 }
        public void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
        {
            Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_X7H9S8V8_32));

            int[]  out_buf = (int[])i_output.getBuffer();
            byte[] in_buf  = (byte[])i_input.getBuffer();
            int    s;

            for (int i = i_size.h * i_size.w - 1; i >= 0; i--)
            {
                int r = (in_buf[i * 3 + 2] & 0xff);
                int g = (in_buf[i * 3 + 1] & 0xff);
                int b = (in_buf[i * 3 + 0] & 0xff);
                int cmax, cmin;
                //最大値と最小値を計算
                if (r > g)
                {
                    cmax = r;
                    cmin = g;
                }
                else
                {
                    cmax = g;
                    cmin = r;
                }
                if (b > cmax)
                {
                    cmax = b;
                }
                if (b < cmin)
                {
                    cmin = b;
                }
                int h;
                if (cmax == 0)
                {
                    s = 0;
                    h = 0;
                }
                else
                {
                    s = (cmax - cmin) * 255 / cmax;
                    int cdes = cmax - cmin;
                    //H成分を計算
                    if (cdes != 0)
                    {
                        if (cmax == r)
                        {
                            h = (g - b) * 60 / cdes;
                        }
                        else if (cmax == g)
                        {
                            h = (b - r) * 60 / cdes + 2 * 60;
                        }
                        else
                        {
                            h = (r - g) * 60 / cdes + 4 * 60;
                        }
                    }
                    else
                    {
                        h = 0;
                    }
                }
                if (h < 0)
                {
                    h += 360;
                }
                //hsv変換(h9s8v8)
                out_buf[i] = (0x1ff0000 & (h << 16)) | (0x00ff00 & (s << 8)) | (cmax & 0xff);
            }
            return;
        }
        protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out)
        {
            Color32[] in_pixs = (Color32[])this._ref_raster.getBuffer();
            int in_w = this._ref_raster.getWidth();
            int in_h = this._ref_raster.getHeight();
            int res_pix = i_resolution * i_resolution;

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];
            double cp2 = cpara[2];
            double cp5 = cpara[5];

			int step,offset;
            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();
            if (o_out is INyARRgbRaster)
            {
                INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
				if(this._is_inv_v){
					offset=in_w*(in_h-1);
					step=-in_w;
				}else{
					offset=0;
					step=in_w;
				}
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        int r, g, b;
                        r = g = b = 0;
                        int cy = pk_t + iy * i_resolution;
                        int cx = pk_l + ix * i_resolution;
                        double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx;
                        double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                        double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                        for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                        {
                            double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                            for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                                if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }
                            	Color32 px = in_pixs[x + offset+step*y];
                                r+= px.r;// R
                                g+= px.g;// G
                                b+= px.b;// B
                                cp7_cy_1_cp6_cx += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix);
                    }
                }
                return true;
            }
            return false;
        }
Example #52
0
 public NyARContourPickup_BIN_GS8(INyARRaster i_ref_raster)
 {
     this._ref_raster = i_ref_raster;
 }
	    public void doFilter(INyARRaster i_input, INyARRaster i_output)
	    {
		    Debug.Assert (i_input!=i_output);
		    this._do_filter_impl.doFilter(i_input,i_output,i_input.getSize());
	    }
 public NyARRgb2GsFilterRgbAve_BYTE1D_B8G8R8X8_32(INyARRaster i_ref_raster)
 {
     Debug.Assert(i_ref_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8X8_32));
     this._ref_raster = i_ref_raster;
 }
 /**
  * この関数は、ラスタの指定点を基点に、画像の特定の範囲内から輪郭線を抽出します。
  * 開始点は、輪郭の一部である必要があります。
  * 通常は、ラべリングの結果の上辺クリップとX軸エントリポイントを開始点として入力します。
  * @param i_raster
  * 輪郭線を抽出するラスタを指定します。
  * @param i_area
  * 輪郭線の抽出範囲を指定する矩形。i_rasterのサイズ内である必要があります。
  * @param i_th
  * 輪郭とみなす暗点の敷居値を指定します。
  * @param i_entry_x
  * 輪郭抽出の開始点です。
  * @param i_entry_y
  * 輪郭抽出の開始点です。
  * @param o_coord
  * 輪郭点を格納するオブジェクトを指定します。
  * @return
  * 輪郭線がo_coordの長さを超えた場合、falseを返します。
  * @
  */
 public bool getContour(INyARGrayscaleRaster i_raster, NyARIntRect i_area, int i_th, int i_entry_x, int i_entry_y, NyARIntCoordinates o_coord)
 {
     //ラスタドライバの切り替え
     if (i_raster != this._ref_last_input_raster)
     {
         this._imdriver = (IRasterDriver)i_raster.createInterface(typeof(IRasterDriver));
         this._ref_last_input_raster = i_raster;
     }
     return this._imdriver.getContour(i_area.x, i_area.y, i_area.x + i_area.w - 1, i_area.h + i_area.y - 1, i_entry_x, i_entry_y, i_th, o_coord);
 }
Example #56
0
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            BitmapData in_bmp = this._ref_raster.lockBitmap();
            int        in_w   = this._ref_raster.getWidth();
            int        in_h   = this._ref_raster.getHeight();

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

            int    out_w = o_out.getWidth();
            int    out_h = o_out.getHeight();
            double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l;
            double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l;
            double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l;
            int    r, g, b, p;

            switch (o_out.getBufferType())
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
                int[] pat_data = (int[])o_out.getBuffer();
                p = 0;
                for (int iy = 0; iy < out_h; iy++)
                {
                    //解像度分の点を取る。
                    double cp7_cy_1_cp6_cx   = cp7_cy_1;
                    double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                    double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                    for (int ix = 0; ix < out_w; ix++)
                    {
                        //1ピクセルを作成
                        double d = 1 / (cp7_cy_1_cp6_cx);
                        int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                        int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                        if (x < 0)
                        {
                            x = 0;
                        }
                        else if (x >= in_w)
                        {
                            x = in_w - 1;
                        }
                        if (y < 0)
                        {
                            y = 0;
                        }
                        else if (y >= in_h)
                        {
                            y = in_h - 1;
                        }

                        //
                        pat_data[p] = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                        //r = (px >> 16) & 0xff;// R
                        //g = (px >> 8) & 0xff; // G
                        //b = (px) & 0xff;    // B
                        cp7_cy_1_cp6_cx   += cp6;
                        cp1_cy_cp2_cp0_cx += cp0;
                        cp4_cy_cp5_cp3_cx += cp3;
                        //pat_data[p] = (r << 16) | (g << 8) | ((b & 0xff));
                        //pat_data[p] = px;

                        p++;
                    }
                    cp7_cy_1   += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                this._ref_raster.unlockBitmap();
                return(true);

            default:
                if (o_out is NyARBitmapRaster)
                {
                    NyARBitmapRaster bmr = (NyARBitmapRaster)o_out;
                    BitmapData       bm  = bmr.lockBitmap();
                    p = 0;
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx   = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            else if (x >= in_w)
                            {
                                x = in_w - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            else if (y >= in_h)
                            {
                                y = in_h - 1;
                            }
                            int pix = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                            Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride, pix);
                            cp7_cy_1_cp6_cx   += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            p++;
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    bmr.unlockBitmap();
                    this._ref_raster.unlockBitmap();
                    return(true);
                }
                else if (o_out is INyARRgbRaster)
                {
                    //ANY to RGBx
                    INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx   = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            else if (x >= in_w)
                            {
                                x = in_w - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            else if (y >= in_h)
                            {
                                y = in_h - 1;
                            }

                            int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                            r = (px >> 16) & 0xff;  // R
                            g = (px >> 8) & 0xff;   // G
                            b = (px) & 0xff;        // B
                            cp7_cy_1_cp6_cx   += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            out_reader.setPixel(ix, iy, r, g, b);
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    this._ref_raster.unlockBitmap();
                    return(true);
                }
                break;
            }
            this._ref_raster.unlockBitmap();
            return(false);
        }
 /**
  * この関数は、ラスタの指定点を基点に、輪郭線を抽出します。
  * 開始点は、輪郭の一部である必要があります。
  * 通常は、ラべリングの結果の上辺クリップとX軸エントリポイントを開始点として入力します。
  * @param i_raster
  * 輪郭線を抽出するラスタを指定します。
  * @param i_th
  * 輪郭とみなす暗点の敷居値を指定します。
  * @param i_entry_x
  * 輪郭抽出の開始点です。
  * @param i_entry_y
  * 輪郭抽出の開始点です。
  * @param o_coord
  * 輪郭点を格納する配列を指定します。i_array_sizeよりも大きなサイズの配列が必要です。
  * @return
  * 輪郭の抽出に成功するとtrueを返します。輪郭抽出に十分なバッファが無いと、falseになります。
  * @
  */
 public bool getContour(INyARGrayscaleRaster i_raster, int i_th, int i_entry_x, int i_entry_y, NyARIntCoordinates o_coord)
 {
     NyARIntSize s = i_raster.getSize();
     //ラスタドライバの切り替え
     if (i_raster != this._ref_last_input_raster)
     {
         this._imdriver = (IRasterDriver)i_raster.createInterface(typeof(IRasterDriver));
         this._ref_last_input_raster = i_raster;
     }
     return this._imdriver.getContour(0, 0, s.w - 1, s.h - 1, i_entry_x, i_entry_y, i_th, o_coord);
 }
 protected abstract bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out);
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            BitmapData in_bmp = this._ref_raster.lockBitmap();
            int in_w = this._ref_raster.getWidth();
            int in_h = this._ref_raster.getHeight();

             //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();
            double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l;
            double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l;
            double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l;
            int r, g, b, p;
            switch (o_out.getBufferType())
            {
                case NyARBufferType.INT1D_X8R8G8B8_32:
                    int[] pat_data = (int[])o_out.getBuffer();
                    p = 0;
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                            if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }

                            //
                            pat_data[p] = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                            //r = (px >> 16) & 0xff;// R
                            //g = (px >> 8) & 0xff; // G
                            //b = (px) & 0xff;    // B
                            cp7_cy_1_cp6_cx += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            //pat_data[p] = (r << 16) | (g << 8) | ((b & 0xff));
                            //pat_data[p] = px;

                            p++;
                        }
                        cp7_cy_1 += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    this._ref_raster.unlockBitmap();
                    return true;
                default:
                    if (o_out is NyARBitmapRaster)
                    {
                        NyARBitmapRaster bmr = (NyARBitmapRaster)o_out;
                        BitmapData bm = bmr.lockBitmap();
                        p = 0;
                        for (int iy = 0; iy < out_h; iy++)
                        {
                            //解像度分の点を取る。
                            double cp7_cy_1_cp6_cx = cp7_cy_1;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                            for (int ix = 0; ix < out_w; ix++)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                                if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }
                                int pix = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                                Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride, pix);
                                cp7_cy_1_cp6_cx += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                                p++;
                            }
                            cp7_cy_1 += cp7;
                            cp1_cy_cp2 += cp1;
                            cp4_cy_cp5 += cp4;
                        }
                        bmr.unlockBitmap();
                        this._ref_raster.unlockBitmap();
                        return true;
                    }
                    else if (o_out is INyARRgbRaster)
                    {
                        //ANY to RGBx
                        INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                        for (int iy = 0; iy < out_h; iy++)
                        {
                            //解像度分の点を取る。
                            double cp7_cy_1_cp6_cx = cp7_cy_1;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                            for (int ix = 0; ix < out_w; ix++)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                                if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }

                                int px = Marshal.ReadInt32(in_bmp.Scan0, (x*4 + y * in_bmp.Stride));
                                r = (px >> 16) & 0xff;// R
                                g = (px >> 8) & 0xff; // G
                                b = (px) & 0xff;    // B
                                cp7_cy_1_cp6_cx += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                                out_reader.setPixel(ix, iy, r, g, b);
                            }
                            cp7_cy_1 += cp7;
                            cp1_cy_cp2 += cp1;
                            cp4_cy_cp5 += cp4;
                        }
                        this._ref_raster.unlockBitmap();
                        return true;
                    }
                    break;
            }
            this._ref_raster.unlockBitmap();
            return false;
        }
 protected abstract bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out);