Пример #1
0
        /// <summary>
        /// Returns dictionary that contains all directories for input and output files
        /// </summary>
        /// <param name="dir">Input directory</param>
        /// <param name="output">Output directory</param>
        /// <returns></returns>
        public static Dictionary <string, FileDirData> StartDigging(string dir, string output)
        {
            Dictionary <string, FileDirData> LinkedFiles = new Dictionary <string, FileDirData>();

            List <string> files = DigForFiles(dir);
            List <string> normFiles = NormalizeFileNames(files).ToList();
            FileDirData   curData = null;
            string        name, normName;
            int           ind = 0;

            //foreach (var name in files)
            for (int i = 0; i < files.Count; i++)
            {
                name     = files[i];
                normName = normFiles[i];

                if (!name.EndsWith(".RoiSet"))
                {
                    if (name.EndsWith("_Q2.tif"))
                    {
                        curData = new FileDirData(name);
                    }
                    else if (normFiles.Contains(normName.Replace(".tif", ".RoiSet")))
                    {
                        ind = normFiles.IndexOf(normName.Replace(".tif", ".RoiSet"));

                        curData = new FileDirData(name, files[ind]);
                    }
                    else if (normFiles.Contains(normName.Replace(".tif", "_G.RoiSet")))
                    {
                        ind = normFiles.IndexOf(normName.Replace(".tif", "_G.RoiSet"));

                        curData = new FileDirData(name, files[ind]);
                    }
                    else if (normFiles.Contains(normName.Replace(".tif", "_R.RoiSet")))
                    {
                        // ind = normFiles.IndexOf(normName.Replace(".tif", "_R.RoiSet"));

                        // curData = new FileDirData(name, files[ind]);
                        curData = null;
                    }
                    else
                    {
                        curData = null;
                    }

                    if (curData != null)
                    {
                        curData.ChangeOutputPath(dir, output);
                        LinkedFiles.Add(name, curData);
                    }
                }
            }

            return(LinkedFiles);
        }
Пример #2
0
        /// <summary>
        /// Copy the current file directory data
        /// </summary>
        /// <returns>New File directory data</returns>
        public FileDirData Duplicate()
        {
            FileDirData output = new FileDirData(InputDir, InputRoi);

            output.OutputDir           = this._OutputDir;
            output.OutputDir_CTResults = this._OutputDir_CTResults;
            output.OutputDir_NormExp   = this._OutputDir_NormExp;
            output.OutputDir_Results   = this._OutputDir_Results;
            output.OutputDir_CTResults = this._OutputDir_CTResults;
            output.OutputDir_Soble     = this._OutputDir_Sobel;
            return(output);
        }
Пример #3
0
        /// <summary>
        /// Analyse image file - crop with tracking, copy Polygonal ROI, apply Sobel operator and save the results
        /// </summary>
        /// <param name="DirData">Output and input directories </param>
        /// <returns>True if file successfully processed</returns>
        public static bool Analyse(FileDirData DirData, double[] background)
        {
            TifFileInfo fi = new TifFileInfo();
            // try
            {
                //read celltool 3 image
                var console = Console.Out;
                Console.SetOut(TextWriter.Null);
                Console.SetError(TextWriter.Null);

                fi = Cell_Tool_3.FileDecoder.ReadImage(DirData.InputDir); //read the image
                Cell_Tool_3.FileDecoder.LoadRoiSet(DirData.InputRoi, fi); //read roi file

                Console.SetOut(console);
                Console.SetError(console);
                int curInd = 1;
                if (fi.roiList != null && fi.roiList[0] != null)
                {
                    foreach (ROI roi in fi.roiList[0])
                    {
                        if (roi.Checked && roi.Type == 1 && roi.Shape > 1)
                        {
                            FileDirData curDirData = DirData.Duplicate();

                            if (!curDirData.InputDir.EndsWith("_CompositeRegistred.tif") &&
                                !curDirData.InputDir.EndsWith("_Q2.tif") &&
                                !curDirData.InputDir.EndsWith("_1.tif"))
                            {
                                curDirData.ExtractClipNumber();
                                curDirData.AddCellIndex(curInd.ToString());
                            }


                            ProcessSingleRoi(fi, roi, curDirData, background);
                        }


                        curInd++;
                    }
                }

                //clear and report
                fi.Delete();
                return(true);
            }
            //catch
            {
                //clear and report
                fi.Delete();
                return(false);
            }
        }
Пример #4
0
        private static void ProcessSingleRoi(TifFileInfo fi, ROI roi, FileDirData dirData, double[] background)
        {
            if (!dirData.InputDir.EndsWith("_CompositeRegistred.tif") &&
                !dirData.InputDir.EndsWith("_Q2.tif") &&
                !dirData.InputDir.EndsWith("_1.tif"))
            {
                fi = MultiCropper.ProcessROI(dirData.OutputDir, roi, fi);
            }
            else
            {
                MultiCropper.RecalculateOriginalROI(roi, null, fi);
            }

            if (fi == null)
            {
                return;
            }

            fi.yAxisTB         = 1;
            fi.xAxisTB         = 1;
            fi.autoDetectBandC = true;

            //Save the original image
            fi.Dir = dirData.OutputDir;
            if (!dirData.InputDir.EndsWith("_CompositeRegistred.tif") &&
                !dirData.InputDir.EndsWith("_Q2.tif") &&
                !dirData.InputDir.EndsWith("_1.tif"))
            {
                MultiCrop.FileEncoder.SaveTif(fi, dirData.OutputDir);
            }

            //Apply expression normalizer and save the image
            fi.Dir = dirData.OutputDir_NormExp;
            for (int c = 0; c < fi.sizeC; c++)
            {
                fi.cValue = c;

                if (c < background.Length)
                {
                    ExpressionNormalizer.Process(background[c], fi);
                }
                else
                {
                    ExpressionNormalizer.Process(background[0], fi);
                }
            }
            MultiCrop.FileEncoder.SaveTif(fi, dirData.OutputDir_NormExp);
            //apply sobel operator
            fi.Dir = dirData.OutputDir_Soble;
            for (int c = 0; c < fi.sizeC; c++)
            {
                fi.cValue = c;
                SobelOperator.applySobel(fi);
            }

            switch (fi.bitsPerPixel)
            {
            case 8:
                fi.image8bit = fi.image8bitFilter;
                break;

            case 16:
                fi.image16bit = fi.image16bitFilter;
                break;
            }
            MultiCrop.FileEncoder.SaveTif(fi, dirData.OutputDir_Soble);
            //measure results
            CalculateAllRois(fi);
            Cell_Tool_3.ExportTxtResults.ExportAllResults(fi);
            //delete info
            fi.Delete();
        }