Example #1
0
        void LoadFromPath(/*string Path, string FileName*/List<cImageMetaInfo> ListImageMetaInfo)
        {
            if (ListImageMetaInfo == null) return;
            int ChannelStart = 0;

            for (int IdxName = 0; IdxName < ListImageMetaInfo.Count; IdxName++)
            {
                string CurrentName = ListImageMetaInfo[IdxName].FileName;

                if (CurrentName == "") continue;

                if (CurrentName.Contains("http://"))
                {
                    try
                    {
                        using (WebClient Client = new WebClient())
                        {
                            string[] ListForExt = CurrentName.Split('.');
                            Client.DownloadFile(CurrentName, "Tmp." + ListForExt[ListForExt.Length - 1]);
                            CurrentName = "Tmp." + ListForExt[ListForExt.Length - 1];
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }

                }

                if ((File.Exists(CurrentName) == false)) continue;

                string[] ListSplits = CurrentName.Split('.');
                string Extension = ListSplits[ListSplits.Length - 1].ToLower();

                byte[] rgbValues = null;

                int NumBytePerPixel = 0;
                int NumBitsPerPixel = 0;
                int NumChannels = 0;
                object ResMeta = null;             


                switch (Extension)
                {
                    #region Cellomics c01 - BioFormats
                    case "c01":
                        [email protected] MyCellomicsReader = new [email protected]();
                        MyCellomicsReader.setId(CurrentName);

                        int SerieCurr = -1;
                        for (int IdxSerie = 0; IdxSerie < MyCellomicsReader.getSeriesUsedFiles().Count(); IdxSerie++)
                        {

                            if (MyCellomicsReader.getSeriesUsedFiles()[IdxSerie] == CurrentName)
                            {
                                SerieCurr = IdxSerie;
                                break;
                            }
                        }

                        MyCellomicsReader.setSeries(SerieCurr);
                        rgbValues = MyCellomicsReader.openBytes(0);
                        //int ImC = MyCellomicsReader.getImageCount();

                        this.Width = MyCellomicsReader.getSizeX();

                        //                     ImageProcessorReader r = new ImageProcessorReader(
                        //new ChannelSeparator(LociPrefs.makeImageReader()));


                        this.Height = MyCellomicsReader.getSizeY();
                        this.Depth = MyCellomicsReader.getSizeZ();
                        NumChannels = MyCellomicsReader.getSizeC();
                        NumBitsPerPixel = MyCellomicsReader.getBitsPerPixel();
                        MyCellomicsReader.close();
                        break;
                    #endregion
                    #region tiff - BioFormats
                    case "tiff":

                        [email protected] MyTiffReader = new [email protected]();
                        MyTiffReader.setId(CurrentName);
                        rgbValues = MyTiffReader.openBytes(0);
                        this.Width = MyTiffReader.getSizeX();
                        this.Height = MyTiffReader.getSizeY();
                        this.Depth = MyTiffReader.getSizeZ();
                        NumChannels = MyTiffReader.getSizeC();
                        NumBitsPerPixel = MyTiffReader.getBitsPerPixel();
                        MyTiffReader.close();


                        break;
                    #endregion
                    #region LSM - BioFormats
                    case "lsm":
                        [email protected] MyLSMReader = new [email protected]();
                        MyLSMReader.setId(CurrentName);

                        this.Width = MyLSMReader.getSizeX();
                        this.Height = MyLSMReader.getSizeY();

                        NumChannels = MyLSMReader.getSizeC();
                        this.Depth = MyLSMReader.getSizeZ();

                        this.Name = CurrentName;
                        this.SliceSize = this.Width * this.Height;
                        this.ImageSize = SliceSize * Depth;

                        if (IdxName == 0)
                            this.SingleChannelImage = new cListSingleChannelImage();

                        #region GetMetaData
                        ResMeta = MyLSMReader.getSeriesMetadataValue("VoxelSizeX");
                        if (ResMeta == null)
                            this.Resolution.X = 1;
                        else
                            this.Resolution.X = ((java.lang.Double)ResMeta).doubleValue();

                        ResMeta = MyLSMReader.getSeriesMetadataValue("VoxelSizeY");
                        if (ResMeta == null)
                            this.Resolution.X = 1;
                        else
                            this.Resolution.Y = ((java.lang.Double)ResMeta).doubleValue();

                        ResMeta = MyLSMReader.getSeriesMetadataValue("VoxelSizeZ");
                        if (ResMeta == null)
                            this.Resolution.Z = 1;
                        else
                            this.Resolution.Z = ((java.lang.Double)ResMeta).doubleValue();
                        #endregion

                        for (int IdxChannel = 0; IdxChannel < NumChannels; IdxChannel++)
                            this.SingleChannelImage.Add(new cSingleChannelImage(this.Width, this.Height, this.Depth, new cPoint3D(this.Resolution)));


                        float TmpValue = 0;
                        byte[] TmpTable;

                        for (int IdxZ = 0; IdxZ < this.Depth; IdxZ++)
                        {
                            for (int IdxChannel = 0; IdxChannel < NumChannels; IdxChannel++)
                            {
                                TmpTable = MyLSMReader.openBytes(IdxZ * NumChannels + IdxChannel);

                                for (int IdxY = 0; IdxY < this.Height; IdxY++)
                                    for (int IdxX = 0; IdxX < this.Width; IdxX++)
                                    {
                                        TmpValue = TmpTable[IdxX + IdxY * this.Width];

                                        this.SingleChannelImage[IdxChannel + ChannelStart].Data[IdxX + IdxY * this.Width + IdxZ * this.SliceSize] = TmpValue;
                                    }
                            }
                        }
                        NumBitsPerPixel = MyLSMReader.getBitsPerPixel();

                        // if the meta data are ok, take the name
                        for (int IdxChannel = 0; IdxChannel < NumChannels; IdxChannel++)
                        {
                            ResMeta = MyLSMReader.getSeriesMetadataValue("DataChannel #" + (IdxChannel + 1) + " Name");
                            if (ResMeta != null)
                                this.SingleChannelImage[IdxChannel + ChannelStart].Name = (string)ResMeta;
                        }
                        goto NEXTLOOP;
                    #endregion
                    #region tif - FreeImage
                    case "tif":


                        //Image<Gray, Single> myImage = new Image<Gray, Single>(@CurrentName);
                        //var watch = Stopwatch.StartNew();

                        int PageCount = 1;
                        this.Depth = PageCount;
                        NumChannels = 1;
                        
                        Mat myImage = new Mat(CurrentName, Emgu.CV.CvEnum.LoadImageType.AnyDepth);
                        //watch.Stop();
                        //cGlobalInfo.WindowHCSAnalyzer.richTextBoxConsole.AppendText("Opencv = " + watch.ElapsedMilliseconds + "\n");

                        for (int IDxPlane = 0; IDxPlane < PageCount; IDxPlane++)
                        {
                            
                            if (IDxPlane == 0)
                            {
                                this.Width = myImage.Width;
                                this.Height = myImage.Height;
                                this.Resolution.X = 1;
                                this.Resolution.Y = 1;
                                NumBitsPerPixel = 16;

                                for (int IdxChannel = 0; IdxChannel < NumChannels; IdxChannel++)
                                {
                                    cSingleChannelImage TmpChannelImage = new cSingleChannelImage(this.Width, this.Height, this.Depth, new cPoint3D(1, 1, 1));
                                    if (ListImageMetaInfo[IdxName].Name != "") TmpChannelImage.Name = ListImageMetaInfo[IdxName].Name;
                                    if (ListImageMetaInfo[IdxChannel].ResolutionX != -1) this.Resolution.X = ListImageMetaInfo[IdxChannel].ResolutionX;
                                    if (ListImageMetaInfo[IdxChannel].ResolutionY != -1) this.Resolution.Y = ListImageMetaInfo[IdxChannel].ResolutionY;
                                    if (ListImageMetaInfo[IdxChannel].ResolutionZ != -1) this.Resolution.Z = ListImageMetaInfo[IdxChannel].ResolutionZ;
                                    Image<Gray, float> myImage2 = myImage.ToImage<Gray, float>();
                                    //var watch2 = Stopwatch.StartNew();
                                    
                                    TmpChannelImage.SetNewDataFromOpenCV(myImage2);
                                    //watch2.Stop();
                                    //cGlobalInfo.WindowHCSAnalyzer.richTextBoxConsole.AppendText("Convert = " + watch2.ElapsedMilliseconds + "\n");
                                    this.SingleChannelImage.Add(TmpChannelImage);
                                }
                            }
                           
                            

                        }

                        this.Name = CurrentName;
                        this.SliceSize = this.Width * this.Height;
                        this.ImageSize = SliceSize * Depth;

                        //goto NEXTLOOP;                      

                       
                        break;
                       
                }

                #endregion
                #endregion

                NEXTLOOP:;

                ChannelStart += NumChannels;




            }
           


        }
Example #2
0
        void BuildFromListTable(cListExtendedTable ListSources)
        {
            if (ListSources.Count == 0) return;
            if (ListSources[0].Count == 0) return;
            if (ListSources[0][0].Count == 0) return;

            //this.NumChannels = ListSources.Count;
            this.Width = ListSources[0].Count;
            this.Height = ListSources[0][0].Count;
            this.Depth = 1;
            this.SliceSize = this.Height * this.Width;

            this.SingleChannelImage = new cListSingleChannelImage();
            for (int IdxChannel = 0; IdxChannel < ListSources.Count; IdxChannel++)
            {
                this.SingleChannelImage.Add(new cSingleChannelImage(this.Width, this.Height, 1, new cPoint3D(1, 1, 1)));

                for (int i = 0; i < this.Width; i++)
                    for (int j = 0; j < this.Height; j++)
                    {
                        this.SingleChannelImage[IdxChannel].Data[i + j * this.Width] = (float)ListSources[IdxChannel][i][j];
                    }
            }
            this.Name = ListSources.Name;
        }
Example #3
0
        public cImage(cSingleChannelImage Source, bool CopyData)
        {
            // this.NumChannels = 1;
            this.Width = Source.Width;
            this.Height = Source.Height;
            this.Depth = Source.Depth;
            this.Resolution = new cPoint3D(Source.Resolution);

            this.SliceSize = this.Height * this.Width;
            this.ImageSize = SliceSize * Depth;

            if (CopyData == true)
            {
                this.SingleChannelImage = new cListSingleChannelImage();

                this.SingleChannelImage.Add(new cSingleChannelImage(Source.Width, Source.Height, Source.Depth, Source.Resolution));
                this.SingleChannelImage[0].Name = Source.Name;
                this.SingleChannelImage[0].Data = new float[Source.Data.Length];

                Array.Copy(Source.Data, this.SingleChannelImage[0].Data, Source.Data.Length);
            }
            else
            {
                this.SingleChannelImage.Add(Source);
            }

            this.Name = Source.Name;
        }
Example #4
0
        public cImage(cImage Source, bool IsCopyData)
        {
            //Source.GetNumChannels();
            this.Width = Source.Width;
            this.Height = Source.Height;
            this.Depth = Source.Depth;
            this.SliceSize = this.Height * this.Width;
            this.ImageSize = SliceSize * Depth;
            this.Resolution = new cPoint3D(Source.Resolution);

            this.SingleChannelImage = new cListSingleChannelImage();
            for (int IdxChannel = 0; IdxChannel < Source.GetNumChannels(); IdxChannel++)
            {
                this.SingleChannelImage.Add(new cSingleChannelImage(Source.Width, Source.Height, Source.Depth, new cPoint3D(Source.Resolution)));
                this.SingleChannelImage[IdxChannel].Name = Source.SingleChannelImage[IdxChannel].Name;
                this.SingleChannelImage[IdxChannel].Data = new float[Source.SingleChannelImage[IdxChannel].Data.Length];

                if (IsCopyData)
                    Array.Copy(Source.SingleChannelImage[IdxChannel].Data, this.SingleChannelImage[IdxChannel].Data, Source.SingleChannelImage[IdxChannel].Data.Length);
            }
        }
Example #5
0
        public cImage(Image<Gray, byte> CVImage)
        {
            //this.output = new cImage(this.input);
            this.Width = CVImage.Width;
            this.Height = CVImage.Height;
            this.SliceSize = this.Height * this.Width;
            this.ImageSize = SliceSize * Depth;

            this.SingleChannelImage = new cListSingleChannelImage();
            //for (int IdxChannel = 0; IdxChannel < NumChannels; IdxChannel++)
            this.SingleChannelImage.Add(new cSingleChannelImage(Width, Height, 1, new cPoint3D(1, 1, 1)));

            for (int j = 0; j < CVImage.Height; j++)
                for (int i = 0; i < CVImage.Width; i++)
                    this.SingleChannelImage[0].Data[i + j * this.Width] = CVImage.Data[j, i, 0];

            //this.NumChannels = 1;
        }
Example #6
0
        public cImage(int Width, int Height, int Depth, int NumChannels)
        {
            //this.NumChannels = NumChannels;
            this.Width = Width;
            this.Height = Height;
            this.Depth = Depth;
            this.SliceSize = this.Height * this.Width;
            this.ImageSize = SliceSize * Depth;
            this.SingleChannelImage = new cListSingleChannelImage();

            for (int IdxChannel = 0; IdxChannel < NumChannels; IdxChannel++)
            {
                this.SingleChannelImage.Add(new cSingleChannelImage(Width, Height, Depth, new cPoint3D(this.Resolution)));
                this.SingleChannelImage[this.SingleChannelImage.Count - 1].Name = "Channel " + IdxChannel;
            }
        }