Пример #1
0
        private void SaveasHisFile(string hisPath, List <ushort[, ]> dataList, int intergrationTime)
        {
            int       NrOfFrames = dataList.Count;
            int       row        = dataList[0].GetLength(0);
            int       col        = dataList[0].GetLength(1);
            HisHeader h          = new HisHeader();

            h.FileID          = 0x7000;
            h.HeaderSize      = 68;
            h.HeadVerdion     = 100;
            h.FileSize        = (uint)(32 + 68 + NrOfFrames * row * col * sizeof(ushort));
            h.ImageHeaderSize = 32;
            h.ULX             = 1;
            h.BRX             = (short)col;
            h.ULY             = 1;
            h.BRY             = (short)row;
            h.NrOfFrames      = (short)NrOfFrames;
            h.Correction      = 1;
            try
            {
                h.IntegrationTime = (uint)(intergrationTime * 1000);
            }
            catch (System.Exception ex)
            {
                h.IntegrationTime = 1000 * 1000;
            }
            h.TypeOfNumbers = 4;
            h.X             = new byte[34];
            h.ImageHeader   = new byte[32];
            HisObject.SaveDataToHIS(ref h, dataList, hisPath);
        }
        public void SetPixelMapFile(string fn)
        {
            if ((IntPtr)pixel_corr_list_ != IntPtr.Zero)
            {
                Marshal.FreeHGlobal((IntPtr)pixel_corr_list_);
                Kernel32Interface.CloseHandle((IntPtr)pixel_corr_list_);
                pixel_corr_list_ = (int *)IntPtr.Zero;
            }
            if (File.Exists(fn))
            {
                List <ushort[, ]> list = HisObject.OpenFile(fn).dataList;
                int Frames             = list.Count;
                width_  = list[0].GetLength(1);
                height_ = list[0].GetLength(0);
                int     pCorrListSize = 0;
                ushort *pPixelSoure   = ArrayListToBuffer(list);
                PKL_Interface.Acquisition_CreatePixelMap(pPixelSoure, height_, width_, null, ref pCorrListSize);
                pixel_corr_list_ = (int *)Marshal.AllocHGlobal((int)(pCorrListSize * sizeof(int)));
                PKL_Interface.Acquisition_CreatePixelMap(pPixelSoure, height_, width_, pixel_corr_list_, ref pCorrListSize);

                Marshal.FreeHGlobal((IntPtr)pPixelSoure);
                Kernel32Interface.CloseHandle((IntPtr)pPixelSoure);
                pPixelSoure = (ushort *)IntPtr.Zero;
            }
        }
        public void SetGainFile(string fn)
        {
            if ((IntPtr)gain_map_ != IntPtr.Zero)
            {
                Marshal.FreeHGlobal((IntPtr)gain_map_);
                Kernel32Interface.CloseHandle((IntPtr)gain_map_);
                gain_map_ = (ushort *)IntPtr.Zero;
            }

            if ((IntPtr)gain_med_map_ != IntPtr.Zero)
            {
                Marshal.FreeHGlobal((IntPtr)gain_med_map_);
                Kernel32Interface.CloseHandle((IntPtr)gain_med_map_);
                gain_med_map_ = (ushort *)IntPtr.Zero;
            }
            if (File.Exists(fn))
            {
                List <ushort[, ]> list = HisObject.OpenFile(fn).dataList;
                gain_seq_num_ = list.Count;
                int count = list[0].Length;
                width_        = list[0].GetLength(1);
                height_       = list[0].GetLength(0);
                gain_map_     = ArrayListToBuffer(list);
                gain_med_map_ = (ushort *)Marshal.AllocHGlobal((int)(gain_seq_num_ * sizeof(short)));
                PKL_Interface.Acquisition_CreateGainMap(gain_map_, gain_med_map_, count, gain_seq_num_);

                offset_map_ = (ushort *)Marshal.AllocHGlobal((int)(width_ * height_ * sizeof(short)));
                for (int i = 0; i < width_ * height_; i++)
                {
                    offset_map_[i] = 0;
                }
            }
        }
        public void SetOffsetFile(string fn)
        {
            HisObject his = new HisObject();

            his.LoadDataFromFile(fn);
            offset_img_ = his.dataList[0];
            width_      = his.hisHeader.BRX;
            height_     = his.hisHeader.BRY;
        }
Пример #5
0
        public static HisObject OpenFile(string file)
        {
            HisObject his = new HisObject();

            if (his.LoadDataFromFile(file))
            {
                return(his);
            }
            else
            {
                return(null);
            }
        }
        private void ReadFile(string file)
        {
            //TiffReader tiff = new TiffReader();
            //IOD_RI RI = new IOD_RI();
            HisObject His = new HisObject();
            //IOD_RD RD = new IOD_RD();
            ImageObject img = new ImageObject();

            //if (tiff.ReadFile(file))
            //{
            //    imageRows = (uint)tiff.ImageHegiht;
            //    imageColumns = (uint)tiff.ImageWidth;
            //    RefreshScale();

            //    img.pixelSize = pixelSize;
            //    img.centerX = imageCenterX;
            //    img.centerY = imageCenterY;
            //    ushort[,] image = new ushort[tiff.ImageHegiht, tiff.ImageWidth];
            //    int sn = 0;
            //    for (int y = 0; y < tiff.ImageHegiht; y++)
            //    {
            //        for (int x = 0; x < tiff.ImageWidth; x++)
            //        {
            //            image[y, x] = tiff.Value[sn++];
            //        }
            //    }
            //    img.imageData = image;
            //    img.createTime = DateTime.Now;
            //    imgList.Add(img);
            //}
            //if (RI.OpenFromFile(file))
            //{
            //    img.pixelSize = RI.RIImage.ImagePlanePixelSpacing[0];
            //    img.centerX = -RI.RIImage.RTImagePosition[0] / RI.RIImage.ImagePlanePixelSpacing[0];
            //    img.centerY = RI.RIImage.RTImagePosition[1] / RI.RIImage.ImagePlanePixelSpacing[1];
            //    img.level = (int)RI.RIImage.WindowCenter;
            //    img.window = (int)RI.RIImage.WindowWidth;
            //    img.imageHeight = RI.ImagePixel.PixelData.GetLength(0);
            //    img.imageWidth = RI.ImagePixel.PixelData.GetLength(1);
            //    ushort[,] image = new ushort[img.imageHeight, img.imageWidth];
            //    short[,] dv = RI.ImagePixel.PixelData;
            //    for (int y = 0; y < img.imageHeight; y++)
            //    {
            //        for (int x = 0; x < img.imageWidth; x++)
            //        {
            //            image[y,x] = (ushort)dv[y,x];
            //        }
            //    }
            //    img.imageData = image;
            //    imgList.Add(img);
            //    GC.Collect();
            //}
            if (His.LoadDataFromFile(file))
            {
                if (His.dataList != null)
                {
                    for (int i = 0; i < His.dataList.Count; i++)
                    {
                        ImageObject imageObj = new ImageObject();

                        imageObj.ImageData = His.dataList[i];
                        imageRows          = (uint)imageObj.ImageData.GetLength(0);
                        imageColumns       = (uint)imageObj.ImageData.GetLength(1);
                        RefreshScale();
                        imageObj.pixelSize = pixelSize;
                        imageObj.centerX   = imageCenterX;
                        imageObj.centerY   = imageCenterY;
                        imgList.Enqueue(imageObj);
                    }
                    His.dataList = null;
                    GC.Collect();
                }
            }
            //else if (RD.OpenFromFile(file))//增加RD图像,2011.12.15,ml
            //{

            //    //img.level = 4590;
            //    //img.window = 10000;
            //    if (RD.RD.PixelData.Length > 0)
            //    {
            //        img.pixelSize = RD.RD.PixelSpacing;
            //        img.imageWidth = RD.RD.PixelData[0].GetLength(1);
            //        img.imageHeight = RD.RD.PixelData[0].GetLength(0);
            //        img.centerX = img.imageWidth / 2; //-RDF.fra.ImagePosition[0] / PixelSize;
            //        img.centerY = img.imageHeight / 2;//RDF.fra.ImagePosition[1] / PixelSize;
            //        img.SliceDepth = RD.RD.ImagePosition[1];

            //        ushort[,] image = new ushort[img.imageHeight, img.imageWidth];

            //        UInt32[,] rd = RD.RD.PixelData[0];
            //        for (int i = 0; i < img.imageHeight; i++)
            //        {
            //            for (int j = 0; j < img.imageWidth; j++)
            //            {
            //                image[i, j] = Convert.ToUInt16(rd[i, j] * RD.RD.DoseGridScaling * 1000F);
            //            }
            //        }
            //        img.imageData = image;
            //        imgList.Add(img);
            //        GC.Collect();
            //    }
            //}
            //else
            //{
            //    try
            //    {
            //        //Bitmap bm = new Bitmap(file);
            //        //LWList.Add(new Point(-1, -1));
            //        //imgList.Add(BitmapToUShort(bm));
            //        //pixelSize = phySize / imgList[0].GetLength(0);
            //        //imageCenterX = phyCenterX / pixelSize;
            //        //imageCenterY = phyCenterY / pixelSize;
            //    }
            //    catch (System.Exception ex)
            //    {
            //        ;
            //    }
            //}
        }