Exemplo n.º 1
0
        public static TVEResults Calculate(SliceData sliceData, double factor = 0.3, CalcMode mode = CalcMode.BySum)
        {
            var data  = mode == CalcMode.BySum ? sliceData.DataBySum : sliceData.DataByCount;
            var total = data.Sum(x => x);
            var tve   = new TVEResults
            {
                SliceData = sliceData,
                Factor    = factor,
                Total     = total,
                Cutoff    = (int)(total * factor),
                Mode      = mode,
            };

            var sorted    = data.OrderByDescending(x => x).ToArray();
            int sum       = 0;
            int nToExceed = 0;

            for (int i = 0; i < sorted.Length; i++)
            {
                nToExceed++;
                sum += sorted[i];
                if (sum > tve.Cutoff)
                {
                    break;
                }
            }
            tve.Count      = nToExceed;
            tve.Percentage = nToExceed * 100.0 / sliceData.Count;
            return(tve);
        }
Exemplo n.º 2
0
        static int Main(string[] args)
        {
            var lcArgs = args.Select(arg => arg.ToLower());

            if (args.Length == 0 || lcArgs.Any(arg => arg == "/?" || arg == "help"))
            {
                Console.WriteLine($"Usage: dotnet {Assembly.GetEntryAssembly().GetName().Name} commands DICOM.file");
                Console.WriteLine("Valid commands are: PixelData SliceData Rolling TVEBySum TVEByCount HistoBySum HistoByCount HistoLogBySum HistoLogByCount");
                Console.WriteLine("Call with --version to get version info");
                return(0);
            }

            if (lcArgs.Any(arg => arg == "--version"))
            {
                Console.WriteLine(Assembly.GetEntryAssembly().GetName().Version);
                return(0);
            }

            // Check if last arg is a valid file.
            var      path     = Path.GetFullPath(args.LastOrDefault() ?? @"\");
            FileInfo fileInfo = new FileInfo(path);

            if (!fileInfo.Exists)
            {
                Console.WriteLine("No valid path supplied. Aborting.");
                return(1);
            }

            // Read and parse the DICOM file.
            var raw = RawData.FromDicom(fileInfo.FullName);

            if (raw == null)
            {
                Console.WriteLine("Failed to parse DICOM file. Aborting.");
                return(1);
            }

            // Output raw pixel data?
            if (lcArgs.Any(arg => arg == "pixeldata"))
            {
                Console.WriteLine(raw.DumpPixelData());
            }

            var sd = SliceData.Calculate(raw);

            // Output slice data?
            if (lcArgs.Any(arg => arg == "slicedata"))
            {
                Console.WriteLine(sd.Dump());
            }

            // Output rolling data?
            if (lcArgs.Any(arg => arg == "rolling"))
            {
                Console.WriteLine(sd.DumpRolling());
            }

            // Calculate and output TVE by sums?
            if (lcArgs.Any(arg => arg == "tvebysum"))
            {
                var tveSum = TVEResults.Calculate(sd);
                Console.WriteLine(tveSum.Dump());
            }

            // Calculate and output TVE by counts?
            if (lcArgs.Any(arg => arg == "tvebycount"))
            {
                var tveCount = TVEResults.Calculate(sd, mode: CalcMode.ByCount);
                Console.WriteLine(tveCount.Dump());
            }

            // Calculate and output histogram data?
            if (lcArgs.Any(arg => arg == "histobysum"))
            {
                var histo = Histogram.Calculate(sd, CalcMode.BySum, HistoMode.Normal);
                Console.WriteLine(histo.Dump());
            }
            if (lcArgs.Any(arg => arg == "histobycount"))
            {
                var histo = Histogram.Calculate(sd, CalcMode.ByCount, HistoMode.Normal);
                Console.WriteLine(histo.Dump());
            }
            if (lcArgs.Any(arg => arg == "histologbysum"))
            {
                var histo = Histogram.Calculate(sd, CalcMode.BySum, HistoMode.Log10);
                Console.WriteLine(histo.Dump());
            }
            if (lcArgs.Any(arg => arg == "histologbycount"))
            {
                var histo = Histogram.Calculate(sd, CalcMode.ByCount, HistoMode.Log10);
                Console.WriteLine(histo.Dump());
            }

#if DEBUG
            Console.ReadKey();
#endif
            return(0);
        }