Beispiel #1
0
 public MyCompresser(MyPlayer RefPlayer, PictureBox CurViewer)
 {
     this.RefPlayer = RefPlayer;
     CurPlayer      = new MyPlayer(CurViewer);
     compressFile   = new MyCompressTiff();
     CompressKernel = new MyFilter(compressKernelSize);
     CompressKernel.setData(1.0);
 }
Beispiel #2
0
        /// <summary>
        /// val-->
        /// </summary>

        /// <summary>
        /// operate-->
        /// </summary>
        public static MyFilter add(MyFilter left, MyFilter right)
        {
            MyFilter newFilter = new MyFilter(left.size);

            for (int j = 0; j < newFilter.size; j++)
            {
                for (int i = 0; i < newFilter.size; i++)
                {
                    newFilter[i, j] = left[i, j] + right[i, j];
                }
            }
            return(newFilter);
        }
        public static Bitmap drawVector(MyMotionTiff motion)
        {
            if (motion == null)
            {
                return(null);
            }
            MyFilter filter = new MyFilter(MyCompresser.compressKernelSize);

            filter.setData(1);
            Bitmap   newImg         = new Bitmap(motion.Width, motion.Height);
            Graphics grapic         = Graphics.FromImage(newImg);
            int      colorLowBound  = 64;// for random color value lower bound
            int      colorHighBound = 256 - colorLowBound;

            Color[] colors = new Color[motion.Width * motion.Height / MyCompresser.compressKernelSize / MyCompresser.compressKernelSize];
            Random  random = new Random();
            int     i      = 0;//pen sequence

            //draw box
            for (int y = MyCompresser.compressKernelSize / 2; y < motion.Height; y += MyCompresser.compressKernelSize)
            {
                for (int x = MyCompresser.compressKernelSize / 2; x < motion.Width; x += MyCompresser.compressKernelSize)
                {
                    if ((motion[x, y][0] == x) && (motion[x, y][1] == y))
                    {//no motiom
                        colors[i] = Color.Black;
                    }
                    else
                    {
                        colors[i] = Color.FromArgb(colorLowBound + random.Next() % colorHighBound, colorLowBound + random.Next() % colorHighBound, colorLowBound + random.Next() % colorHighBound);
                    }
                    grapic.FillRectangle(new SolidBrush(colors[i]), x - MyCompresser.compressKernelSize / 4, y - MyCompresser.compressKernelSize / 4, MyCompresser.compressKernelSize / 2, MyCompresser.compressKernelSize / 2);
                    //grapic.FillRectangle(new SolidBrush(colors[i]), x - MyCompresser.compressKernelSize / 2, y - MyCompresser.compressKernelSize / 2, MyCompresser.compressKernelSize / 2, MyCompresser.compressKernelSize / 2);
                    //grapic.DrawRectangle(new Pen(colors[i]), x , y, MyCompresser.compressKernelSize, MyCompresser.compressKernelSize);
                    i++;
                }
            }
            i = 0;//pen sequence
            //draw vector line
            for (int y = 0 + MyCompresser.compressKernelSize / 2; y < motion.Height; y += MyCompresser.compressKernelSize)
            {
                for (int x = 0 + MyCompresser.compressKernelSize / 2; x < motion.Width; x += MyCompresser.compressKernelSize)
                {
                    grapic.DrawLine(new Pen(Color.FromArgb(128, colors[i]), 2.0f), x, y, motion[x, y][0], motion[x, y][1]);
                    i++;
                }
            }

            return(newImg);
        }
        public void set(BitmapData src, int x, int y, MyFilter filter)
        {
            int size = filter.size;

            _data = new double[size, size][];
            int startX = x - size / 2;
            int startY = y - size / 2;

            for (int j = 0; j < size; j++)
            {
                for (int i = 0; i < size; i++)
                {
                    MyFilter.setPixel(src, startX + i, startY + j, this[i, j], filter[i, j]);
                }
            }
            return;
        }
        public static Bitmap decode(Bitmap baseImg, MyMotionTiff motion)
        {
            MyFilter filter = new MyFilter(MyCompresser.compressKernelSize);

            filter.setData(1);
            Bitmap       newImg        = new Bitmap(baseImg.Width, baseImg.Height);
            BitmapData   baseData      = baseImg.LockBits(MyDeal.boundB(baseImg), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
            BitmapData   newData       = newImg.LockBits(MyDeal.boundB(newImg), ImageLockMode.WriteOnly, PixelFormat.Format24bppRgb);
            MyFilterData srcFilterData = new MyFilterData();

            for (int y = 0 + MyCompresser.compressKernelSize / 2; y < motion.Height; y += MyCompresser.compressKernelSize)
            {
                for (int x = 0 + MyCompresser.compressKernelSize / 2; x < motion.Width; x += MyCompresser.compressKernelSize)
                {
                    srcFilterData.fill(baseData, motion[x, y][0], motion[x, y][1], MyFilter.BorderMethod.ZERO, filter);
                    Debug.Print("the " + x + " , " + y + " from " + motion[x, y][0] + " , " + motion[x, y][1]);
                    unsafe
                    {
                        byte *dstPtr   = (byte *)newData.Scan0;
                        int   skipByte = newData.Stride - 3 * MyCompresser.compressKernelSize;
                        dstPtr += (y - MyCompresser.compressKernelSize / 2) * newData.Stride + (x - MyCompresser.compressKernelSize / 2) * 3;
                        for (int j = 0; j < MyCompresser.compressKernelSize; j++)
                        {
                            for (int i = 0; i < MyCompresser.compressKernelSize; i++)
                            {
                                byte[] result = MyFilterData.boundPixel(srcFilterData[i, j]);
                                //Debug.Print("Data get " + result[0] + " , " + result[1] + " , " + result[2]);
                                dstPtr[0] = result[0];
                                dstPtr[1] = result[1];
                                dstPtr[2] = result[2];
                                dstPtr   += 3;
                            }
                            dstPtr += skipByte;
                        }
                    }
                }
            }
            baseImg.UnlockBits(baseData);
            newImg.UnlockBits(newData);
            return(newImg);
        }
        public int fill(BitmapData srx, int x, int y, MyFilter.BorderMethod borderMethod, MyFilter filter)
        {
            int size = filter.size;

            _data = new double[size, size][];
            int startX = x - size / 2;
            int startY = y - size / 2;
            int pixels = 0;

            for (int j = 0; j < size; j++)
            {
                for (int i = 0; i < size; i++)
                {
                    _data[i, j] = MyFilter.getPixel(srx, startX + i, startY + j, borderMethod, filter[i, j]);
                    if (_data[i, j] != null)
                    {
                        pixels++;
                    }
                }
            }
            return(pixels);
        }
Beispiel #7
0
        protected void intraSubsample()
        {
            compressFile.type = MyCompressTiffDefine.TYPE.SUBSAMPLE;
            if (RefPlayer != null)
            {
                RefPlayer.OnPlay(new MyPlayer.PlayEventArgs(0, MyPlayer.PlayState.KEEP));
                CurPlayer.Tiff = RefPlayer.Tiff.clone();
                MyFilterData CurKernelGet   = new MyFilterData();// the data copy from cur frame of kernel size
                int          intraSubSize   = 2;
                int          subSizeHalf    = intraSubSize / 2;
                double       subWeight      = 1.0 / (intraSubSize * intraSubSize);
                MyFilter     intraSubFilter = new MyFilter(intraSubSize);
                intraSubFilter.setData(1.0);

                for (int i = 0; i < RefPlayer.Tiff.Size; i++)
                {                                                          //run frames
                 //Debug.Print("in frame " + i);
                    trackBar.Invoke(new threadHandler2(progressTrack), i); // reflash progress view
                    CurPlayer.OnPlay(new MyPlayer.PlayEventArgs(i));       //flash current frame view

                    Bitmap curBitmapCp;                                    // the copy Bitmap for cur frame
                    Bitmap dstBitmap;                                      // viewer in counting out view
                    while (true)
                    {
                        try
                        {
                            curBitmapCp = new Bitmap((Image)CurPlayer.PredictView.Clone());// the copy Bitmap for cur frame
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(33);
                            continue;
                        }
                        break;
                    }
                    dstBitmap = new Bitmap(curBitmapCp.Width, curBitmapCp.Height);
                    while (true)
                    {
                        try
                        {
                            MotionViewer.Image = dstBitmap;
                        }
                        catch (InvalidOperationException)
                        {
                            Thread.Sleep(33);
                            continue;
                        }
                        break;
                    }

                    BitmapData curData = curBitmapCp.LockBits(MyDeal.boundB(curBitmapCp), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                    //Bitmap afterSubView = new Bitmap(intraSubSize, intraSubSize);// view in match blok
                    //while (true)
                    //{
                    //    try
                    //    {
                    //        MatchViewer.Image = afterSubView;
                    //    }
                    //    catch (InvalidOperationException)
                    //    {
                    //        Thread.Sleep(33);
                    //        continue;
                    //    }
                    //    break;
                    //}
                    //Graphics afterSubViewG = Graphics.FromImage(afterSubView);
                    Graphics dstBitmapG = Graphics.FromImage(dstBitmap);
                    int      freq       = 0;
                    for (int y = 0 + subSizeHalf; y < curBitmapCp.Height; y += intraSubSize)
                    {
                        for (int x = 0 + subSizeHalf; x < curBitmapCp.Width; x += intraSubSize)
                        {
                            if (activeFrom != null)
                            {
                                if (activeFrom.IsDisposed)//form be dispose
                                {
                                    return;
                                }
                            }
                            //draw target
                            if (!this.CurrentPlayer.flashIgnore)
                            {
                                if (freq % 2 == 0)
                                { // reduce flash freq
                                    freq = 0;
                                    CurPlayer.OnPlay(new MyPlayer.PlayEventArgs(-1, MyPlayer.PlayState.KEEP, x, y, intraSubSize, intraSubSize));
                                }
                                else
                                {
                                    freq++;
                                }
                            }
                            CurKernelGet.fill(curData, x, y, MyFilter.BorderMethod.ZERO, intraSubFilter);
                            //MyDeal.tryDraw(featureViewer, CurKernelGet.transToBitmap());
                            byte[] subSample = CurKernelGet.count(subWeight);
                            //Debug.Print("in " + x + " , " + y + " : " + subSample[2] + " " + subSample[1] + " " + subSample[0]);
                            Color sampleColor = Color.FromArgb(subSample[2], subSample[1], subSample[0]);
                            Brush sample      = new SolidBrush(sampleColor);
                            dstBitmapG.FillRectangle(sample, x - subSizeHalf, y - subSizeHalf, intraSubSize, intraSubSize);
                            if (!this.CurrentPlayer.flashIgnore)
                            {
                                MotionViewer.Invalidate();
                            }
                            //MatchViewer.Invalidate();
                            Thread.Sleep(sleepTime);
                            //Debug.Print("in frame " + i + " in " + x + " , "+ y + "find target " + targetX + " , " + targetY);
                        }
                    }
                    curBitmapCp.UnlockBits(curData);
                    compressFile.baseImg.Add(dstBitmap);// add dst imge
                    compressFile.motionTiff.Add(null);
                }

                if (activeFrom != null)
                {
                    activeFrom.Invoke(new threadHandler(saveFile));// save the result
                }
            }
        }