Beispiel #1
0
        /* 画素フィルタスクリプト */
        public static ScriptResult Filter(PixelDouble _inputPixel, string code)
        {
            var ssr = ScriptSourceResolver.Default
                      .WithBaseDirectory(Environment.CurrentDirectory);
            var options = ScriptOptions.Default
                          .WithSourceResolver(ssr)
                          .WithReferences(typeof(object).Assembly)//参照アセンブリを指定
                          .WithReferences(typeof(PixelDouble).Assembly)
                          .WithReferences(Assembly.GetEntryAssembly())
                          .WithImports(//using する名前空間を指定
                "System",
                "System.Collections.Generic",
                "Pixels");

            var hostObject = new hostObject_ {
                inputPixel = _inputPixel
            };

            var script = CSharpScript.Create(
                code,
                options,
                typeof(hostObject_)
                );

            var state = script.RunAsync(hostObject).Result;

            ScriptResult ret = new ScriptResult();

            ret.outputPixel = (PixelDouble)state.GetVariable("result")?.Value ?? null;
            ret.outputStr   = (string)state.GetVariable("resultStr")?.Value ?? "";
            return(ret);
        }
Beispiel #2
0
        public static void WriteZip(this PixelDouble p, string zipfilename, string statusname = "000", bool append = false, CompressionLevel level = CompressionLevel.Fastest)
        {
            XML.PixelModelDependent.ModelDataXML buf = new XML.PixelModelDependent.ModelDataXML();

            buf.Width    = p.Width;
            buf.Height   = p.Height;
            buf.FileName = new List <string> {
                $"^{statusname}.bin$"
            };
            buf.FileSize = -1;
            buf.SetFileType(typeof(PixelDouble));
            //buf.SetFileType(p.GetType());

            ZipArchiveMode mode = append ? ZipArchiveMode.Update : ZipArchiveMode.Create;

            using (var archive = ZipFile.Open(zipfilename, mode))
            {
                using (var z = archive.CreateEntry($"PixelsModel\\{statusname}.model", level).Open())
                {
                    Pixels.IO.XMLSetter.Write <PixelModelDependent.ModelDataXML>(buf, z);
                }
                using (var z = archive.CreateEntry($"{statusname}.bin").Open())
                {
                    PixelStream.WriteBin(z, p);
                }
            }
        }
Beispiel #3
0
        public static void WriteZipTxt(this PixelDouble p, string zipfilename, string statusname = "000", bool append = false, CompressionLevel level = CompressionLevel.Fastest)
        {
            var sta = new StaPara();

            sta.Width    = p.Width;
            sta.Height   = p.Height;
            sta.filename = statusname + ".txt";
            sta.type     = "txt";

            ZipArchiveMode mode = append ? ZipArchiveMode.Update : ZipArchiveMode.Create;

            using (var archive = ZipFile.Open(zipfilename, mode))
            {
                using (var z = archive.CreateEntry(statusname + ext_status, level).Open())
                    WriteStatus(z, sta);
                using (var z = archive.CreateEntry(sta.filename).Open())
                    PixelStream.WriteTxt(z, p);
            }
        }
Beispiel #4
0
 public void Add(PixelDouble i)
 {
     outV.Write(action(i));
 }
Beispiel #5
0
        public static BitmapSource DemosaicToRGBW(this PixelDouble pix, double offset, double depth, double depth_w, double Rgain, double Bgain)
        {
            byte[] R = new byte[pix.Size];
            byte[] G = new byte[pix.Size];
            byte[] B = new byte[pix.Size];
            byte[] W = new byte[pix.Size];

            int c11 = 0;
            int c12 = 1;
            int c13 = 2;
            int c21 = pix.Width + 0;
            int c22 = pix.Width + 1;
            int c23 = pix.Width + 2;
            int c31 = 2 * pix.Width + 0;
            int c32 = 2 * pix.Width + 1;
            int c33 = 2 * pix.Width + 2;

            for (int i = 0; i < pix.Size - 2 - 2 * pix.Width; i++)
            {
                double rr = 0;
                double gg = 0;
                double bb = 0;
                double ww = 0;

                int hoge = i % 2 + 2 * ((int)(i / pix.Width) % 2);
                switch (hoge)
                {
                case 0:    //G
                    rr = (pix[c12] + pix[c32]) / 2;
                    gg = (pix[c11] + pix[c13] + pix[c31] + pix[c33]) / 4;
                    bb = (pix[c21] + pix[c23]) / 2;
                    ww = pix[c22];
                    break;

                case 1:    //R
                    gg = (pix[c12] + pix[c32]) / 2;
                    rr = (pix[c11] + pix[c13] + pix[c31] + pix[c33]) / 4;
                    ww = (pix[c21] + pix[c23]) / 2;
                    bb = pix[c22];
                    break;

                case 2:    //B
                    ww = (pix[c12] + pix[c32]) / 2;
                    bb = (pix[c11] + pix[c13] + pix[c31] + pix[c33]) / 4;
                    gg = (pix[c21] + pix[c23]) / 2;
                    rr = pix[c22];
                    break;

                case 3:    //W
                    bb = (pix[c12] + pix[c32]) / 2;
                    ww = (pix[c11] + pix[c13] + pix[c31] + pix[c33]) / 4;
                    rr = (pix[c21] + pix[c23]) / 2;
                    gg = pix[c22];
                    break;
                }
                c11++;
                c12++;
                c13++;
                c21++;
                c22++;
                c23++;
                c31++;
                c32++;
                c33++;

                rr = 255 * Rgain * (rr + offset) / depth;
                bb = 255 * Bgain * (bb + offset) / depth;
                gg = 255 * (gg + offset) / depth;
                ww = 255 * depth_w * (ww + offset) / depth;

                R[i] = (byte)(rr > 255 ? 255 : rr < 0 ? 0 : rr);
                G[i] = (byte)(gg > 255 ? 255 : gg < 0 ? 0 : gg);
                B[i] = (byte)(bb > 255 ? 255 : bb < 0 ? 0 : bb);
                W[i] = (byte)(ww > 255 ? 255 : ww < 0 ? 0 : ww);
            }

            using (var Rmat = new Mat(pix.Height, pix.Width, MatType.CV_8UC1, R))
                using (var Gmat = new Mat(pix.Height, pix.Width, MatType.CV_8UC1, G))
                    using (var Bmat = new Mat(pix.Height, pix.Width, MatType.CV_8UC1, B))
                        using (var Wmat = new Mat(pix.Height, pix.Width, MatType.CV_8UC1, W))
                        {
                            var rgbmat = new Mat();
                            Cv2.Merge(new Mat[] { Bmat, Gmat, Rmat }, rgbmat);

                            var hsvmat = new Mat();
                            Cv2.CvtColor(rgbmat, hsvmat, ColorConversionCodes.BGR2HSV);

                            var splitmat = hsvmat.Split();

                            Cv2.Merge(new Mat[] { splitmat[0], splitmat[1], Wmat }, hsvmat);
                            //Cv2.Merge(new Mat[]{Wmat, splitmat[1],splitmat[2]}, hsvmat);

                            Cv2.CvtColor(hsvmat, rgbmat, ColorConversionCodes.HSV2BGR);

                            var buf = rgbmat.ToBitmapSource();
                            buf.Freeze();

                            return(buf);
                        }
        }
Beispiel #6
0
        public double Cat02_CLM()
        {
            PixelDouble p = ReadPixs(Illuminant.L50, Register.Full, FileType.Ave, Area.Full);

            return(p.Ave());
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            //PixelDouble p = new PixelDouble(new double[] { 1, 2, 3, 4 }, 2, 2);

            PixelDouble p = new PixelDouble(10000, 10000);


            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();

            PixelScripting.hostObject_ obj = new PixelScripting.hostObject_()
            {
                pixel = p
            };

            Console.WriteLine($"{p[0]}");
            Console.WriteLine($"{p[1]}");
            Console.WriteLine($"{p[2]}");
            Console.WriteLine($"{p[3]}");
            Console.WriteLine($"{p.Ave()}");

            Vector4[] a = new Vector4[10000 * 10000 / 4];
            for (int i = 0; i < 10000 * 10000 / 4; i++)
            {
                a[i] = new Vector4(0, 1, 2, 3);
            }

            sw.Start();

            //for (int i = 0; i < 3; i++)
            //{
            //    p = p - p;
            //}
            for (int j = 0; j < 3; j++)
            {
                for (int i = 0; i < a.Length; i++)
                {
                    a[i] = a[i] + a[i]; //234はやい
                }
            }



            sw.Stop();
            Console.WriteLine(sw.Elapsed.TotalMilliseconds);

            Console.WriteLine("Scripting : ");
            for (;;)
            {
                Console.Write("> ");
                var str = Console.ReadLine();
                if (str == "quit")
                {
                    break;
                }

                try
                {
                    var result = PixelScripting.Run(str, obj);
                }
                catch
                {
                    Console.WriteLine("Script Err.");
                }
            }
        }