Esempio n. 1
0
        internal async void Refresh(string path)
        {
            if (ImageInfo.dtImgInfo == null)
            {
                return;
            }
            imheight = ImageInfo.dtImgInfo.Rows.Count;
            if (imheight < 1)
            {
                return;
            }
            this.Busy.isBusy = true;
            Bitmap[] bmp = await DataProc.GetBmp3D(path);

            if (bmp[0] == null || bmp[1] == null || bmp[2] == null || bmp[3] == null || bmp[4] == null || bmp[5] == null)
            {
                return;
            }
            bmp[0].RotateFlip(RotateFlipType.Rotate180FlipX);
            bmp[1].RotateFlip(RotateFlipType.Rotate180FlipY);
            bmp[1].RotateFlip(RotateFlipType.Rotate180FlipX);
            bmp[2].RotateFlip(RotateFlipType.Rotate180FlipX);
            bmp[3].RotateFlip(RotateFlipType.Rotate180FlipX);
            bmp[4].RotateFlip(RotateFlipType.Rotate180FlipY);
            bmp[4].RotateFlip(RotateFlipType.Rotate180FlipX);
            bmp[5].RotateFlip(RotateFlipType.Rotate180FlipY);
            bmp[5].RotateFlip(RotateFlipType.Rotate180FlipX);
            RenderBox(imheight, bmp);
            InitializeCameras();
            this.Busy.isBusy = false;
        }
Esempio n. 2
0
        /// <summary>
        /// 读源文件合成伪彩
        /// </summary>
        /// <param name="height">要合成的图像高</param>
        /// <param name="band">所选取的谱段号(0-159)</param>
        /// <param name="right">数据右移几位</param>
        /// <param name="inPath">源文件的全名</param>
        /// <param name="frmSum">源文件的总帧数</param>
        /// <param name="startPosi">合成图像的开始帧号(从0计数)</param>
        /// <returns></returns>
        public static Bitmap MakePseudo(int height, UInt16[] band, int right, string inPath, int frmSum, int startFrm)
        {
            if (band[0] > 159 || band[1] > 159 || band[2] > 159 || height < 1)
            {
                return(null);
            }
            int width = 2048;

            byte[][]   bandBuf = new byte[3][];
            FileStream inFile  = new FileStream(inPath, FileMode.Open, FileAccess.Read, FileShare.Read);

            //取3张图
            for (int b = 0; b < 3; b++)
            {
                bandBuf[b] = new byte[width * height * 2];
                long seek = (band[b] + 1) * (long)frmSum * width * 2 + startFrm * width * 2;
                inFile.Seek(seek, SeekOrigin.Begin);
                inFile.Read(bandBuf[b], 0, height * width * 2);
            }
            inFile.Close();

            double max      = 0;
            int    maxIndex = 0;

            for (int i = 0; i < 3; i++)
            {
                if (DataProc.readU16_PIC(bandBuf[i], height * width) > max)
                {
                    max      = DataProc.readU16_PIC(bandBuf[i], height * width);
                    maxIndex = i;
                }
            }
            double[] ratioBand = new double[3];
            for (int i = 0; i < 3; i++)
            {
                ratioBand[i] =
                    ((double)DataProc.readU16_PIC(bandBuf[maxIndex], height * width / 4) +
                     (double)DataProc.readU16_PIC(bandBuf[maxIndex], height * width * 3 / 4) +
                     (double)DataProc.readU16_PIC(bandBuf[maxIndex], height * width / 2) +
                     (double)DataProc.readU16_PIC(bandBuf[maxIndex], height * width) +
                     (double)DataProc.readU16_PIC(bandBuf[maxIndex], height * width * 5 / 4) +
                     (double)DataProc.readU16_PIC(bandBuf[maxIndex], height * width * 3 / 2) +
                     (double)DataProc.readU16_PIC(bandBuf[maxIndex], height * width * 7 / 4)) /
                    (DataProc.readU16_PIC(bandBuf[i], height * width / 4) +
                     DataProc.readU16_PIC(bandBuf[i], height * width * 3 / 4) +
                     DataProc.readU16_PIC(bandBuf[i], height * width / 2) +
                     DataProc.readU16_PIC(bandBuf[i], height * width) +
                     DataProc.readU16_PIC(bandBuf[i], height * width * 5 / 4) +
                     DataProc.readU16_PIC(bandBuf[i], height * width * 3 / 2) +
                     DataProc.readU16_PIC(bandBuf[i], height * width * 7 / 4)
                    );
            }
            byte[] bufBmp = new byte[3 * width * height * 2];
            Parallel.For(0, width * height, i => {
                for (int j = 0; j < 3; j++)
                {
                    bufBmp[i * 3 + 2 - j] = (byte)Math.Min((bandBuf[j][i * 2] + bandBuf[j][i * 2 + 1] * 256) * ratioBand[j] / Math.Pow(2, right), 255);
                }
            });
            Bitmap     bmp     = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bmp.PixelFormat);

            Marshal.Copy(bufBmp, 0, bmpData.Scan0, width * height * 3);
            bmp.UnlockBits(bmpData);
            return(bmp);
        }
Esempio n. 3
0
        /// <summary>
        /// 通过三个谱段确定图像内容
        /// </summary>
        /// <param name="path">文件存放位置</param>
        /// <param name="band">3个谱段值,相同则为灰度图</param>
        /// <param name="low">亮度等级1-8(4为原始图像)</param>
        /// <returns></returns>
        public static Task <Bitmap> MakePseudoColor(string path, UInt16[] band, UInt16 gain, int height)
        {
            return(Task.Run(() => {
                if (band[0] > 160 || band[1] > 160 || band[2] > 160 || gain > 8)
                {
                    return null;
                }
                int width = 2048;
                if (height < 1)
                {
                    return null;
                }

                int splitHeight = 4096;                                             //图像分割单元
                int splitSum = (int)Math.Ceiling((double)height / splitHeight);     //图像分割总数

                byte[] bufBmp = new byte[width * height * 3];                       //RGB图像缓存
                byte[][] bufBand = new byte[3][];                                   //16bit单谱段图像缓存
                for (int i = 0; i < 3; i++)
                {
                    bufBand[i] = new byte[width * height * 2];
                }

                FileStream[] fBmp = new FileStream[3];
                if (band[0] == band[1] && band[1] == band[2])
                {
                    for (int i = 0; i < splitSum; i++)
                    {
                        if (i != splitSum - 1)
                        {
                            splitHeight = 4096;
                        }
                        else
                        {
                            splitHeight = height % 4096;
                        }
                        try
                        {
                            fBmp[0] = new FileStream($"{path}{i}\\{band[0]}.raw", FileMode.Open, FileAccess.Read, FileShare.Read);
                            byte[] tBuf = new byte[splitHeight * width * 2];
                            fBmp[0].Read(tBuf, 0, width * splitHeight * 2);
                            fBmp[0].Close();
                            Array.Copy(tBuf, 0, bufBand[0], i * 4096 * 2048 * 2, width * splitHeight * 2);
                        }
                        catch { }
                    }
                    bufBand[1] = bufBand[2] = bufBand[0];
                }
                else
                {
                    for (int b = 0; b < 3; b++)
                    {
                        for (int j = 0; j < splitSum; j++)
                        {
                            if (j != splitSum - 1)
                            {
                                splitHeight = 4096;
                            }
                            else
                            {
                                splitHeight = height % 4096;
                            }
                            try
                            {
                                fBmp[b] = new FileStream($"{path}{j}\\{band[b]}.raw", FileMode.Open, FileAccess.Read, FileShare.Read);
                                byte[] tBuf = new byte[splitHeight * width * 2];
                                fBmp[b].Read(tBuf, 0, width * splitHeight * 2);
                                fBmp[b].Close();
                                Array.Copy(tBuf, 0, bufBand[b], j * 4096 * 2048 * 2, width * splitHeight * 2);
                            }
                            catch { }
                        }
                    }
                }

                double max = 0;
                int maxIndex = 0;
                for (int i = 0; i < 3; i++)
                {
                    if (DataProc.readU16_PIC(bufBand[i], height * width) > max)
                    {
                        max = DataProc.readU16_PIC(bufBand[i], height * width);
                        maxIndex = i;
                    }
                }
                double[] ratioBand = new double[3];
                for (int i = 0; i < 3; i++)
                {
                    ratioBand[i] =
                        ((double)DataProc.readU16_PIC(bufBand[maxIndex], height * width / 4) +
                         (double)DataProc.readU16_PIC(bufBand[maxIndex], height * width * 3 / 4) +
                         (double)DataProc.readU16_PIC(bufBand[maxIndex], height * width / 2) +
                         (double)DataProc.readU16_PIC(bufBand[maxIndex], height * width) +
                         (double)DataProc.readU16_PIC(bufBand[maxIndex], height * width * 5 / 4) +
                         (double)DataProc.readU16_PIC(bufBand[maxIndex], height * width * 3 / 2) +
                         (double)DataProc.readU16_PIC(bufBand[maxIndex], height * width * 7 / 4)) /
                        (DataProc.readU16_PIC(bufBand[i], height * width / 4) +
                         DataProc.readU16_PIC(bufBand[i], height * width * 3 / 4) +
                         DataProc.readU16_PIC(bufBand[i], height * width / 2) +
                         DataProc.readU16_PIC(bufBand[i], height * width) +
                         DataProc.readU16_PIC(bufBand[i], height * width * 5 / 4) +
                         DataProc.readU16_PIC(bufBand[i], height * width * 3 / 2) +
                         DataProc.readU16_PIC(bufBand[i], height * width * 7 / 4)
                        );
                }

                Parallel.For(0, width * height, i => {
                    for (int j = 0; j < 3; j++)
                    {
                        bufBmp[i * 3 + 2 - j] = (byte)Math.Min(((int)(DataProc.readU16_PIC(bufBand[j], i * 2) * ratioBand[j]) * 4 * gain >> 6), 255);
                    }
                });

                Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
                BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bmp.PixelFormat);
                Marshal.Copy(bufBmp, 0, bmpData.Scan0, width * height * 3);
                bmp.UnlockBits(bmpData);
                return bmp;
            }));
        }
Esempio n. 4
0
        /// <summary>
        /// 按片生成伪彩图像
        /// </summary>
        /// <param name="path">文件存放位置</param>
        /// <param name="band">3个谱段值,相同则为灰度图</param>
        /// <param name="height">像高</param>
        /// <returns></returns>
        public static Bitmap MakePseudoColor(string path, UInt16[] band, int height)
        {
            if (band[0] > 160 || band[1] > 160 || band[2] > 160)
            {
                return(null);
            }
            if (height < 1)
            {
                return(null);
            }
            int width = 2048;

            byte[]   bufBmp  = new byte[width * height * 3];                    //RGB图像缓存
            byte[][] bufBand = new byte[3][];                                   //16bit单谱段图像缓存
            for (int i = 0; i < 3; i++)
            {
                bufBand[i] = new byte[width * height * 2];
            }

            FileStream[] fBmp = new FileStream[3];
            if (band[0] == band[1] && band[1] == band[2])
            {
                try
                {
                    fBmp[0] = new FileStream($"{path}{band[0]}.raw", FileMode.Open, FileAccess.Read, FileShare.Read);
                    byte[] tBuf = new byte[height * width * 2];
                    fBmp[0].Read(tBuf, 0, width * height * 2);
                    fBmp[0].Close();
                    Array.Copy(tBuf, 0, bufBand[0], 0, width * height * 2);
                }
                catch { }
                bufBand[1] = bufBand[2] = bufBand[0];
            }
            else
            {
                for (int b = 0; b < 3; b++)
                {
                    try
                    {
                        fBmp[b] = new FileStream($"{path}{band[b]}.raw", FileMode.Open, FileAccess.Read, FileShare.Read);
                        byte[] tBuf = new byte[height * width * 2];
                        fBmp[b].Read(tBuf, 0, width * height * 2);
                        fBmp[b].Close();
                        Array.Copy(tBuf, 0, bufBand[b], 0, width * height * 2);
                    }
                    catch { }
                }
            }

            double max      = 0;
            int    maxIndex = 0;

            for (int i = 0; i < 3; i++)
            {
                if (DataProc.readU16_PIC(bufBand[i], height * width) > max)
                {
                    max      = DataProc.readU16_PIC(bufBand[i], height * width);
                    maxIndex = i;
                }
            }
            double[] ratioBand = new double[3];
            for (int i = 0; i < 3; i++)
            {
                ratioBand[i] =
                    ((double)DataProc.readU16_PIC(bufBand[maxIndex], height * width / 4) +
                     (double)DataProc.readU16_PIC(bufBand[maxIndex], height * width * 3 / 4) +
                     (double)DataProc.readU16_PIC(bufBand[maxIndex], height * width / 2) +
                     (double)DataProc.readU16_PIC(bufBand[maxIndex], height * width) +
                     (double)DataProc.readU16_PIC(bufBand[maxIndex], height * width * 5 / 4) +
                     (double)DataProc.readU16_PIC(bufBand[maxIndex], height * width * 3 / 2) +
                     (double)DataProc.readU16_PIC(bufBand[maxIndex], height * width * 7 / 4)) /
                    (DataProc.readU16_PIC(bufBand[i], height * width / 4) +
                     DataProc.readU16_PIC(bufBand[i], height * width * 3 / 4) +
                     DataProc.readU16_PIC(bufBand[i], height * width / 2) +
                     DataProc.readU16_PIC(bufBand[i], height * width) +
                     DataProc.readU16_PIC(bufBand[i], height * width * 5 / 4) +
                     DataProc.readU16_PIC(bufBand[i], height * width * 3 / 2) +
                     DataProc.readU16_PIC(bufBand[i], height * width * 7 / 4)
                    );
            }

            int gain = 4;

            Parallel.For(0, width * height, i => {
                for (int j = 0; j < 3; j++)
                {
                    bufBmp[i * 3 + 2 - j] = (byte)Math.Min(((int)(DataProc.readU16_PIC(bufBand[j], i * 2) * ratioBand[j]) * 4 * gain >> 6), 255);
                }
            });

            Bitmap     bmp     = new Bitmap(width, height, PixelFormat.Format24bppRgb);
            BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.WriteOnly, bmp.PixelFormat);

            Marshal.Copy(bufBmp, 0, bmpData.Scan0, width * height * 3);
            bmp.UnlockBits(bmpData);
            return(bmp);
        }
Esempio n. 5
0
        internal void Update(byte[] buf_Dynamic, ushort frameCount, byte chanel)
        {
            byte[] buffer_temp = new byte[1536];
            Parallel.For(0, 512, i =>
            {
                //buffer_img[(frameCount - 34152) * 2048 * 3 + (chanel - 1) * 3 * 512 + i * 3 + 2] = buffer_img[(frameCount - 34152) * 2048 * 3 + (chanel - 1) * 3 * 512 + i * 3 + 1] = buffer_img[(frameCount - 34152) * 2048 * 3 + (chanel - 1) * 3 * 512 + i * 3 + 0] = (byte)(Math.Floor(((double)DataProc.readU16_PIC(buf_Dynamic, i * 2) / 4096 * 256)));
                buffer_temp[i * 3 + 2] = buffer_temp[i * 3 + 1] = buffer_temp[i * 3 + 0] = (byte)(Math.Floor(((double)DataProc.readU16_PIC(buf_Dynamic, i * 2) / 4096 * 256)));
            });
            Marshal.Copy(buffer_temp, 0, test_data.Scan0 + (frameCount % 1000) * 2048 * 3 + 512 * (chanel - 1) * 3, 1536);
            if (frameCount % 1000 == 999)
            {
                Parallel.For(0, 1536, a => {
                    buffer_temp[a] = 0;
                });

                Parallel.For(0, 1000, r =>
                {
                    Marshal.Copy(buffer_temp, 0, test_data.Scan0 + r * 2048 * 3 + ((chanel - 1) * 512 * 3), 3 * 512);
                });
            }
        }