Ejemplo n.º 1
0
    public static void PNG(string filePath, TifFile tif, bool autoScale = false)
    {
        if (tif.Channels.Length == 1)
        {
            double[,] gray = tif.Channels[0].Values;

            if (autoScale)
            {
                gray = Adjust.AutoScale(gray);
            }

            PNG(filePath, gray);
            return;
        }
        else if (tif.Channels.Length >= 3)
        {
            double[,] r = tif.Channels[0].Values;
            double[,] g = tif.Channels[1].Values;
            double[,] b = tif.Channels[2].Values;

            if (autoScale)
            {
                r = Adjust.AutoScale(r);
                g = Adjust.AutoScale(g);
                b = Adjust.AutoScale(b);
            }

            PNG(filePath, r, g, b);
            return;
        }
        else
        {
            throw new InvalidOperationException("unsupported number of channels");
        }
    }
Ejemplo n.º 2
0
        public void Test_Load_ColorImage_16bitGrayscale()
        {
            string  filePath = Path.Combine(SampleData.DataFolder, "calibration-20x-ruler-0.32365.tif");
            TifFile tif      = new(filePath);

            Assert.AreEqual(1896, tif.Channels[0].Values[0, 0]);

            double[,] scaled = Adjust.AutoScale(tif.Channels[0].Values);
            Assert.AreNotEqual(1896, scaled[0, 0]);
        }
Ejemplo n.º 3
0
        public void Test_Export_AllTestImages()
        {
            string outputFolder = Path.GetFullPath(Path.Combine(TestContext.CurrentContext.TestDirectory, "output"));

            if (!Directory.Exists(outputFolder))
            {
                Directory.CreateDirectory(outputFolder);
            }

            foreach (string tifPath in SampleData.TifFiles)
            {
                TifFile tif = new(tifPath);
                Console.WriteLine(tif);
                string outputPath = Path.Combine(outputFolder, Path.GetFileName(tifPath) + ".png");
                Console.WriteLine(outputPath);
                Export.PNG(outputPath, Adjust.AutoScale(tif.Channels[0].Values));
            }
        }