Beispiel #1
0
        public void ConstructorTest()
        {
            // Arrange
            int type = 4;

            double[] parameters   = new double[] { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 };
            double   gamma        = 2.2;
            uint     nItems       = 0;
            string   languageCode = "en";
            string   countryCode  = "US";
            string   text         = "constructor";

            using (var context = Context.Create(IntPtr.Zero, IntPtr.Zero))
                using (var ucr = ToneCurve.BuildParametric(context, type, parameters))
                    using (var bg = ToneCurve.BuildGamma(context, gamma))
                        using (var desc = MultiLocalizedUnicode.Create(context, nItems))
                        {
                            desc.SetASCII(languageCode, countryCode, text);

                            var expectedUcr  = ucr.Handle;
                            var expectedBg   = bg.Handle;
                            var expectedDesc = desc.Handle;

                            // Act
                            var target     = new UcrBg(ucr, bg, desc);
                            var actualUcr  = target.Ucr;
                            var actualBg   = target.Bg;
                            var actualDesc = target.Desc;

                            // Assert
                            Assert.AreEqual(expectedUcr, actualUcr);
                            Assert.AreEqual(expectedBg, actualBg);
                            Assert.AreEqual(expectedDesc, actualDesc);
                        }
        }
Beispiel #2
0
        public void ConstructorTest()
        {
            // Arrange
            int type = 4;

            double[] parameters   = new double[] { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 };
            double   gamma        = 2.2;
            uint     nItems       = 0;
            string   languageCode = "en";
            string   countryCode  = "US";
            string   text         = "constructor";

            using (var expectedUcr = ToneCurve.BuildParametric(null, type, parameters))
                using (var expectedBg = ToneCurve.BuildGamma(null, gamma))
                    using (var expectedDesc = MultiLocalizedUnicode.Create(null, nItems))
                    {
                        expectedDesc.SetASCII(languageCode, countryCode, text);

                        // Act
                        var target     = new UcrBg(expectedUcr, expectedBg, expectedDesc);
                        var actualUcr  = target.Ucr;
                        var actualBg   = target.Bg;
                        var actualDesc = target.Desc;

                        // Assert
                        Assert.AreSame(expectedUcr, actualUcr);
                        Assert.AreSame(expectedBg, actualBg);
                        Assert.AreSame(expectedDesc, actualDesc);
                    }
        }
        static void Main(string[] args)
        {
            // 5.画像CまたはDに対し、ソラリゼーション(入力[0-255],出 力[0-254]の濃度値の間で振幅127,周期3の余弦波 曲線)を行い、ヒストグ ラム分布の変化を確認せよ。

            // ソラリゼーション用トーンカーブ作成
            var curve = new ToneCurve();

            for (var i = 0; i < 256; ++i)
            {
                curve[i] = (int)(127 * (Math.Cos(i * 3 * 2 * Math.PI / 256) + 1));
            }

            foreach (var name in new List <string> {
                "C", "D"
            })
            {
                // 画像読み込み
                var src = new GlayImage(name + ".pgm");

                // ヒストグラム画像を生成して出力
                new Histgram(src).GetHistgramImage().Write(name + "_hist.pgm");

                // ソラリゼーション適用
                var dest = src.Apply(curve);

                // 画像を出力
                dest.Write(name + "_solar.pgm");

                // ヒストグラム画像を生成して出力
                new Histgram(dest).GetHistgramImage().Write(name + "_solar_hist.pgm");
            }
        }
Beispiel #4
0
        public void ReadTagTest()
        {
            // Arrange
            int type = 5;

            double[] parameters = new double[] { 0.45, Math.Pow(1.099, 1.0 / 0.45), 0.0, 4.5, 0.018, -0.099, 0.0 };

            using (var red = ToneCurve.BuildParametric(null, type, parameters))
                using (var green = ToneCurve.BuildParametric(null, type, parameters))
                    using (var blue = ToneCurve.BuildParametric(null, type, parameters))
                    {
                        var target = new VideoCardGamma(red, green, blue);

                        using (var profile = Profile.CreatePlaceholder(null))
                        {
                            profile.WriteTag(TagSignature.Vcgt, target);

                            // Act
                            var actual      = profile.ReadTag <VideoCardGamma>(TagSignature.Vcgt);
                            var actualRed   = actual.Red;
                            var actualGreen = actual.Green;
                            var actualBlue  = actual.Blue;

                            // Assert
                            Assert.IsNotNull(actualRed);
                            Assert.IsNotNull(actualGreen);
                            Assert.IsNotNull(actualBlue);
                        }
                    }
        }
Beispiel #5
0
        public void ReadTagTest()
        {
            // Arrange
            double gammaUcr = 2.4, gammaBg = -2.2;
            string languageCode = "en";
            string countryCode  = "US";
            string expectedText = "read-tag";

            using (var ucr = ToneCurve.BuildGamma(null, gammaUcr))
                using (var bg = ToneCurve.BuildGamma(null, gammaBg))
                    using (var desc = MultiLocalizedUnicode.Create(null))
                    {
                        desc.SetASCII(languageCode, countryCode, expectedText);

                        var target = new UcrBg(ucr, bg, desc);
                        using (var profile = Profile.CreatePlaceholder(null))
                        {
                            profile.WriteTag(TagSignature.UcrBg, target);

                            // Act
                            var actual     = profile.ReadTag <UcrBg>(TagSignature.UcrBg);
                            var actualUcr  = actual.Ucr;
                            var actualBg   = actual.Bg;
                            var actualDesc = actual.Desc;

                            // Assert
                            Assert.IsNotNull(actualUcr);
                            Assert.IsNotNull(actualBg);
                            Assert.IsNotNull(actualDesc);
                            var actualText = actualDesc.GetASCII(languageCode, countryCode);
                            Assert.AreEqual(expectedText, actualText);
                        }
                    }
        }
Beispiel #6
0
        public void BuildSegmentedTest()
        {
            // Arrange
            IntPtr plugin   = IntPtr.Zero;
            IntPtr userData = IntPtr.Zero;

            float[]  sampled    = new float[] { 0.0f, 1.0f };
            GCHandle hSampled   = GCHandle.Alloc(sampled, GCHandleType.Pinned);
            IntPtr   ptrSampled = hSampled.AddrOfPinnedObject();

            try
            {
                CurveSegment[] segments = new CurveSegment[]
                {
                    new CurveSegment
                    {
                        x0         = -1e22f,
                        x1         = 1.0f,
                        type       = 6,
                        parameters = new double[10] {
                            1, 0, 0, 0, 0, 0, 0, 0, 0, 0
                        },
                        nGridPoints   = 0,
                        sampledPoints = IntPtr.Zero
                    },
                    new CurveSegment
                    {
                        x0            = 0.0f,
                        x1            = 1.0f,
                        type          = 0,
                        parameters    = new double[10],
                        nGridPoints   = 2,
                        sampledPoints = ptrSampled
                    },
                    new CurveSegment
                    {
                        x0            = 1.0f,
                        x1            = -1e22f,
                        type          = 6,
                        parameters    = new double[] { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
                        nGridPoints   = 0,
                        sampledPoints = IntPtr.Zero
                    }
                };

                // Act
                using (var context = Context.Create(plugin, userData))
                    using (var toneCurve = ToneCurve.BuildSegmented(context, segments))
                    {
                        // Assert
                        Assert.IsNotNull(toneCurve);
                    }
            }
            finally
            {
                hSampled.Free();
            }
        }
        static void Do1()
        {
            // 画像読み込み
            var src = new GlayImage("A.pgm");

            // 階調の最小値と最大値を調べる
            var min = 255;
            var max = 0;

            for (var y = 0; y < src.Size.Height; ++y)
            {
                for (var x = 0; x < src.Size.Width; ++x)
                {
                    if (src[x, y] < min)
                    {
                        min = src[x, y];
                    }
                    if (src[x, y] > max)
                    {
                        max = src[x, y];
                    }
                }
            }

            // トーンカーブ作成
            var curve = new ToneCurve();

            for (var i = 0; i < 256; ++i)
            {
                if (i < min)
                {
                    curve[i] = 0;
                }
                else if (i > max)
                {
                    curve[i] = 255;
                }
                else
                {
                    curve[i] = (i - min) * (200 - 30) / (max - min) + 30;
                }
            }

            // 画像を変換
            var dest = src.Apply(curve);

            // 出力
            dest.Write("A_curve.pgm");
        }
Beispiel #8
0
        public void BuildGammaTest()
        {
            // Arrange
            IntPtr plugin   = IntPtr.Zero;
            IntPtr userData = IntPtr.Zero;
            double gamma    = 2.2;

            // Act
            using (var context = Context.Create(plugin, userData))
                using (var toneCurve = ToneCurve.BuildGamma(context, gamma))
                {
                    // Assert
                    Assert.IsNotNull(toneCurve);
                }
        }
Beispiel #9
0
        public void ReverseTest2()
        {
            // Arrange
            IntPtr plugin   = IntPtr.Zero;
            IntPtr userData = IntPtr.Zero;
            double gamma    = 2.2;

            // Act
            using (var context = Context.Create(plugin, userData))
                using (var toneCurve = ToneCurve.BuildGamma(context, gamma))
                    using (var duplicate = toneCurve.Reverse(4096))
                    {
                        // Assert
                        Assert.IsNotNull(duplicate);
                    }
        }
Beispiel #10
0
        public void BuildTabulatedTest()
        {
            // Arrange
            IntPtr plugin   = IntPtr.Zero;
            IntPtr userData = IntPtr.Zero;

            ushort[] values = new ushort[] { 0, 0, 0, 0, 0, 0x5555, 0x6666, 0x7777, 0x8888, 0x9999, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff };

            // Act
            using (var context = Context.Create(plugin, userData))
                using (var toneCurve = ToneCurve.BuildTabulated(context, values))
                {
                    // Assert
                    Assert.IsNotNull(toneCurve);
                }
        }
Beispiel #11
0
        protected override List <Profile> GenerateAdjustments()
        {
            var profiles = new List <Profile> ();
            var hist     = new Histogram(Input);

            tables = new ToneCurve[3];

            for (int channel = 0; channel < tables.Length; channel++)
            {
                hist.GetHighLow(channel, out var high, out var low);
                Log.DebugFormat($"high = {high}, low = {low}");
                tables[channel] = StretchChannel(255, low / 255.0, high / 255.0);
            }
            profiles.Add(new Profile(IccColorSpace.Rgb, tables));
            return(profiles);
        }
Beispiel #12
0
        public void FromHandleTest()
        {
            // Arrange
            int type = 4;

            double[] parameters   = new double[] { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 };
            double   gamma        = 2.2;
            uint     nItems       = 0;
            string   languageCode = "en";
            string   countryCode  = "US";
            string   expectedText = "from-handle";

            using (var context = Context.Create(IntPtr.Zero, IntPtr.Zero))
                using (var ucr = ToneCurve.BuildParametric(context, type, parameters))
                    using (var bg = ToneCurve.BuildGamma(context, gamma))
                        using (var desc = MultiLocalizedUnicode.Create(context, nItems))
                        {
                            desc.SetASCII(languageCode, countryCode, expectedText);

                            var notExpectedUcr  = IntPtr.Zero;
                            var notExpectedBg   = IntPtr.Zero;
                            var notExpectedDesc = IntPtr.Zero;

                            var target = new UcrBg(ucr, bg, desc);

                            using (var profile = Profile.CreatePlaceholder(null))
                            {
                                profile.WriteTag(TagSignature.UcrBg, target);
                                IntPtr handle = profile.ReadTag(TagSignature.UcrBg);

                                // Act
                                var actual     = UcrBg.FromHandle(handle);
                                var actualUcr  = actual.Ucr;
                                var actualBg   = actual.Bg;
                                var actualDesc = actual.Desc;

                                // Assert
                                Assert.AreNotEqual(notExpectedUcr, actualUcr);
                                Assert.AreNotEqual(notExpectedBg, actualBg);
                                Assert.AreNotEqual(notExpectedDesc, actualDesc);
                                var desc2      = MultiLocalizedUnicode.FromHandle(actualDesc);
                                var actualText = desc2.GetASCII(languageCode, countryCode);
                                Assert.AreEqual(expectedText, actualText);
                            }
                        }
        }
Beispiel #13
0
        public void IsDescendingTest()
        {
            // Arrange
            IntPtr plugin   = IntPtr.Zero;
            IntPtr userData = IntPtr.Zero;
            double gamma    = 2.2;

            // Act
            using (var context = Context.Create(plugin, userData))
                using (var toneCurve = ToneCurve.BuildGamma(context, gamma))
                {
                    var isDescending = toneCurve.IsDescending;

                    // Assert
                    Assert.IsFalse(isDescending);
                }
        }
Beispiel #14
0
        public void IsMonotonicTest()
        {
            // Arrange
            IntPtr plugin   = IntPtr.Zero;
            IntPtr userData = IntPtr.Zero;
            double gamma    = 2.2;

            // Act
            using (var context = Context.Create(plugin, userData))
                using (var toneCurve = ToneCurve.BuildGamma(context, gamma))
                {
                    var isMonotonic = toneCurve.IsMonotonic;

                    // Assert
                    Assert.IsTrue(isMonotonic);
                }
        }
Beispiel #15
0
        public void SmoothTest()
        {
            // Arrange
            IntPtr plugin   = IntPtr.Zero;
            IntPtr userData = IntPtr.Zero;

            ushort[] values = new ushort[] { 0, 0, 0, 0, 0, 0x5555, 0x6666, 0x7777, 0x8888, 0x9999, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff };

            // Act
            using (var context = Context.Create(plugin, userData))
                using (var toneCurve = ToneCurve.BuildTabulated(context, values))
                {
                    var smoothed = toneCurve.Smooth(1.0);

                    // Assert
                }
        }
Beispiel #16
0
        public void JoinTest()
        {
            // Arrange
            IntPtr plugin   = IntPtr.Zero;
            IntPtr userData = IntPtr.Zero;
            double gamma    = 3.0;

            // Act
            using (var context = Context.Create(plugin, userData))
                using (var forward = ToneCurve.BuildGamma(context, gamma))
                    using (var reverse = ToneCurve.BuildGamma(context, gamma))
                        using (var joined = forward.Join(context, reverse, 256))
                        {
                            // Assert
                            Assert.IsNotNull(joined);
                        }
        }
Beispiel #17
0
        public void BuildParametricTest()
        {
            // Arrange
            IntPtr plugin   = IntPtr.Zero;
            IntPtr userData = IntPtr.Zero;
            int    type     = 4;

            double[] parameters = new double[] { 2.4, 1.0 / 1.055, 0.055 / 1.055, 1.0 / 12.92, 0.04045 };

            // Act
            using (var context = Context.Create(plugin, userData))
                using (var toneCurve = ToneCurve.BuildParametric(context, type, parameters))
                {
                    // Assert
                    Assert.IsNotNull(toneCurve);
                }
        }
Beispiel #18
0
        public void EstimatedTableTest()
        {
            // Arrange
            IntPtr plugin      = IntPtr.Zero;
            IntPtr userData    = IntPtr.Zero;
            double gamma       = 2.2;
            IntPtr notExpected = IntPtr.Zero;

            // Act
            using (var context = Context.Create(plugin, userData))
                using (var toneCurve = ToneCurve.BuildGamma(context, gamma))
                {
                    IntPtr actual = toneCurve.EstimatedTable;

                    // Assert
                    Assert.AreNotEqual(notExpected, actual);
                }
        }
Beispiel #19
0
        public void EstimateGammaTest()
        {
            // Arrange
            IntPtr plugin    = IntPtr.Zero;
            IntPtr userData  = IntPtr.Zero;
            double expected  = 2.2;
            double precision = 0.01;

            // Act
            using (var context = Context.Create(plugin, userData))
                using (var toneCurve = ToneCurve.BuildGamma(context, expected))
                {
                    var actual = toneCurve.EstimateGamma(precision);

                    // Assert
                    Assert.AreEqual(expected, actual, precision);
                }
        }
Beispiel #20
0
        public void EvaluateTest2()
        {
            // Arrange
            IntPtr plugin   = IntPtr.Zero;
            IntPtr userData = IntPtr.Zero;
            double gamma    = 1.0;

            // Act
            using (var context = Context.Create(plugin, userData))
                using (var toneCurve = ToneCurve.BuildGamma(context, gamma))
                {
                    for (ushort i = 0; i < ushort.MaxValue; i++)
                    {
                        ushort actual = toneCurve.Evaluate(i);

                        // Assert
                        Assert.AreEqual(i, actual);
                    }
                }
        }
Beispiel #21
0
        public void ReadTagTest()
        {
            // Arrange
            double expected  = 2.2;
            double precision = 0.01;

            using (var profile = Profile.CreatePlaceholder(null))
            {
                using (var toneCurve = ToneCurve.BuildGamma(null, expected))
                {
                    profile.WriteTag(TagSignature.RedTRC, toneCurve);
                }

                // Act
                using (var toneCurve2 = profile.ReadTag <ToneCurve>(TagSignature.RedTRC))
                {
                    // Assert
                    var actual = toneCurve2.EstimateGamma(precision);
                    Assert.AreEqual(expected, actual, precision);
                }
            }
        }
Beispiel #22
0
        public void CreateTest2()
        {
            // Arrange
            IntPtr plugin    = IntPtr.Zero;
            IntPtr userData  = IntPtr.Zero;
            uint   nChannels = 3;

            using (var context = Context.Create(plugin, userData))
                using (var toneCurve = ToneCurve.BuildGamma(context, 2.2))
                {
                    ToneCurve[] curves = new ToneCurve[3] {
                        toneCurve, toneCurve, toneCurve
                    };

                    // Act
                    using (var stage = Stage.Create(context, nChannels, curves))
                    {
                        // Assert
                        Assert.IsNotNull(stage);
                    }
                }
        }
Beispiel #23
0
        public void ConstructorTest()
        {
            // Arrange
            int type = 5;

            double[] parameters = new double[] { 0.45, Math.Pow(1.099, 1.0 / 0.45), 0.0, 4.5, 0.018, -0.099, 0.0 };

            using (var expectedRed = ToneCurve.BuildParametric(null, type, parameters))
                using (var expectedGreen = ToneCurve.BuildParametric(null, type, parameters))
                    using (var expectedBlue = ToneCurve.BuildParametric(null, type, parameters))
                    {
                        // Act
                        var target      = new VideoCardGamma(expectedRed, expectedGreen, expectedBlue);
                        var actualRed   = target.Red;
                        var actualGreen = target.Green;
                        var actualBlue  = target.Blue;

                        // Assert
                        Assert.AreSame(expectedRed, actualRed);
                        Assert.AreSame(expectedGreen, actualGreen);
                        Assert.AreSame(expectedBlue, actualBlue);
                    }
        }
Beispiel #24
0
        public void BuildTabulatedTest2()
        {
            // Arrange
            IntPtr plugin   = IntPtr.Zero;
            IntPtr userData = IntPtr.Zero;

            float[]      values = new float[1025];
            const double gamma  = 2.2;

            for (int i = 0; i <= 1024; i++)
            {
                double d = i / 1024.0;
                values[i] = (float)Math.Pow(d, gamma);
            }

            // Act
            using (var context = Context.Create(plugin, userData))
                using (var toneCurve = ToneCurve.BuildTabulated(context, values))
                {
                    // Assert
                    Assert.IsNotNull(toneCurve);
                }
        }
        static void Do2()
        {
            // 画像読み込み
            var src = new GlayImage("A.pgm");

            foreach (var item in new List <Tuple <string, double> > {
                Tuple.Create("2_0", 2.0), Tuple.Create("0_5", 0.5)
            })
            {
                var name  = item.Item1;
                var gamma = item.Item2;

                // ガンマ補正のトーンカーブ作成
                var curve = new ToneCurve();
                for (var i = 0; i < 256; ++i)
                {
                    var val = (int)(255 * Math.Pow(curve[i] / 255.0, 1 / gamma));
                    if (val >= 256)
                    {
                        val = 255;
                    }
                    curve[i] = val;
                }

                // 画像を変換
                var dest = src.Apply(curve);

                // 画像を出力
                dest.Write("A_gamma_" + name + ".pgm");

                // ヒストグラム画像を生成
                var hist = GetHistgramImage(dest);

                // ヒストグラム画像を出力
                hist.Write("A_gamma_" + name + "_hist.pgm");
            }
        }