示例#1
0
        static void HSV(VectorMap vOriginal)
        {
            VectorMap vHsvChroma = vOriginal
                                   .ConvertAll(delegate(Vector i)
            {
                float max = Math.Max(Math.Max(i.X, i.Y), i.Z);
                float min = Math.Min(Math.Min(i.X, i.Y), i.Z);
                float c   = max - min;
                float h   = (float)Math.PI / 3 * (c == 0 ? 0
                                        : max == i.X ? ((i.Y - i.Z) / c + 6) % 6
                                        : max == i.Y ? (i.Z - i.X) / c + 2
                                        : (i.X - i.Y) / c + 4);
                return(new Vector(h, c == 0 ? 0 : c / max, max));
            })
                                   .ConvertAll(i => new Vector(i.X, i.Y, 1));

            Bitmap bHsvChroma = vHsvChroma
                                .ConvertAll(delegate(Vector i)
            {
                float c  = i.Z * i.Y;
                float h  = i.X * 3 / (float)Math.PI;
                float x  = c * (1 - Math.Abs(h % 2 - 1));
                Vector j = h < 1 ? new Vector(c, x, 0)
                                        : h < 2 ? new Vector(x, c, 0)
                                        : h < 3 ? new Vector(0, c, x)
                                        : h < 4 ? new Vector(0, x, c)
                                        : h < 5 ? new Vector(x, 0, c)
                                        : new Vector(c, 0, x);
                float m = i.Z - c;
                return(new Vector(j.X + m, j.Y + m, j.Z + m));
            })
                                .ToBitmap();
        }
示例#2
0
 static void FillBlots(VectorMap map, Sphere target, out BoolMap fillMap, out int area, out Rectangle bounds, out Point origin)
 {
     fillMap = new BoolMap(map.Width, map.Height);
     origin  = Point.Empty;
     area    = 0;
     bounds  = Rectangle.Empty;
     for (int y = 0; y < map.Height; y++)
     {
         for (int x = 0; x < map.Width; x++)
         {
             if (fillMap[x, y])
             {
                 continue;
             }
             var       xy = new Point(x, y);
             int       xyArea;
             Rectangle xyBounds;
             FloodFill(map, xy, target, fillMap, out xyArea, out xyBounds);
             if (xyArea > area)
             {
                 area   = xyArea;
                 bounds = xyBounds;
                 origin = xy;
             }
         }
     }
 }
 /// <exception cref="System.TypeLoadException"/>
 /// <exception cref="System.IO.IOException"/>
 public virtual void LoadSemantics(Properties props)
 {
     log.Info("LOADING SEMANTICS");
     //    wordnet = new WordNet();
     // load word vector
     if (HybridCorefProperties.LoadWordEmbedding(props))
     {
         log.Info("LOAD: WordVectors");
         string wordvectorFile = HybridCorefProperties.GetPathSerializedWordVectors(props);
         string word2vecFile   = HybridCorefProperties.GetPathWord2Vec(props);
         try
         {
             // Try to read the serialized vectors
             vectors = VectorMap.Deserialize(wordvectorFile);
         }
         catch (IOException e)
         {
             // If that fails, try to read the vectors from the word2vec file
             if (new File(word2vecFile).Exists())
             {
                 vectors = VectorMap.ReadWord2Vec(word2vecFile);
                 if (wordvectorFile != null && !wordvectorFile.StartsWith("edu"))
                 {
                     vectors.Serialize(wordvectorFile);
                 }
             }
             else
             {
                 // If that fails, give up and crash
                 throw new RuntimeIOException(e);
             }
         }
         dimVector = vectors.GetEnumerator().Current.Value.Length;
     }
 }
示例#4
0
        static void FloodFill(VectorMap map, Point origin, Sphere target, BoolMap fillMap, out int area, out Rectangle bounds)
        {
            var queue = new Queue <Point>(map.Width + map.Height);

            queue.Enqueue(origin);
            bounds = new Rectangle(int.MaxValue, int.MaxValue, 0, 0);
            area   = 0;
            while (queue.Count > 0)
            {
                Point p = queue.Dequeue();
                if (fillMap[p.X, p.Y] || !target.Contains(map[p]))
                {
                    continue;
                }
                fillMap[p.X, p.Y] = true;
                if (bounds.X > p.X)
                {
                    bounds.X = p.X;
                }
                if (bounds.Y > p.Y)
                {
                    bounds.Y = p.Y;
                }
                if (bounds.Right <= p.X)
                {
                    bounds.Width = p.X - bounds.X + 1;
                }
                if (bounds.Bottom <= p.Y)
                {
                    bounds.Height = p.Y - bounds.Y + 1;
                }
                area++;
                if (p.X > 0)
                {
                    queue.Enqueue(new Point(p.X - 1, p.Y));
                }
                if (p.Y > 0)
                {
                    queue.Enqueue(new Point(p.X, p.Y - 1));
                }
                if (p.X < map.Width - 1)
                {
                    queue.Enqueue(new Point(p.X + 1, p.Y));
                }
                if (p.Y < map.Height - 1)
                {
                    queue.Enqueue(new Point(p.X, p.Y + 1));
                }
            }
            if (bounds.Size == Size.Empty)
            {
                bounds.Location = Point.Empty;
            }
        }
示例#5
0
 private static void ApplySingleFilterInplace(VectorMap map, VectorToVectorFilter filter)
 {
     Parallel.For(0, map.Height, y =>
     {
         var pix = map.GetRow(y);
         for (var x = 0; x < map.Width; x++)
         {
             filter.ProcessColor(pix, pix);
             pix.MoveNext();
         }
     });
 }
示例#6
0
        private static void ProcessMiddleRows(RawBGGRMap <ushort> file, VectorMap res)
        {
            // Middle Rows
            Parallel.For(0, (res.Height - 2) / 2, yy =>
            {
                var y = yy * 2 + 1;
                ProcessMiddleOddRows(file.GetRow(y), res.Width, res.GetRow(y));

                y++;

                ProcessMiddleEvenRows(file.GetRow(y), res.Width, res.GetRow(y));
            });
        }
示例#7
0
 void browseButton_Click(object sender, EventArgs e)
 {
     using (var dialog = new OpenFileDialog())
     {
         if (dialog.ShowDialog() == DialogResult.Cancel)
         {
             return;
         }
         browseButton.Enabled = false;
         Cursor = Cursors.WaitCursor;
         string fileName = dialog.FileName;
         Text = "Loading: " + fileName;
         ThreadPool.UnsafeQueueUserWorkItem(delegate
         {
             try
             {
                 if (loadedImage != null)
                 {
                     loadedImage.Dispose();
                     loadedImage = null;
                     chromaMap   = null;
                 }
                 GC.Collect();
                 loadedImage = new Bitmap(fileName);
                 chromaMap   = new VectorMap(loadedImage);
                 chromaMap.ForEach(delegate(Vector i)
                 {
                     float m = Math.Max(Math.Max(i.X, i.Y), i.Z);
                     return(m > 0 ? new Vector(i.X / m, i.Y / m, i.Z / m) : new Vector(1, 1, 1));
                 });
                 imageRect.Size = loadedImage.Size;
                 if (colorPoints.Count > 0)
                 {
                     int area;
                     Rectangle bounds;
                     FillBlots(chromaMap, boundingSphere, out fillMap, out area, out bounds, out fillOrigin);
                 }
                 BeginInvoke(new Action(delegate { Text = fileName; }));
             }
             catch (Exception ex)
             {
                 imageRect.Size = Size.Empty;
                 BeginInvoke(new Action(delegate { MessageBox.Show(this, ex.Message); }));
             }
             finally
             {
                 BeginInvoke(new Action(delegate { Cursor = Cursors.Default; browseButton.Enabled = true; Invalidate(); }));
             }
         }, null);
     }
 }
示例#8
0
        // B G B G
        // G R G R
        // B G B G
        // G R G R
        public VectorMap Process(RawBGGRMap <ushort> file)
        {
            if (file.Width % 2 != 0 || file.Height % 2 != 0)
            {
                throw new ArgumentException("Width and Height should be even");
            }
            var res = new VectorMap(file.Width, file.Height);

            ProcessTopLine(file, res);

            ProcessMiddleRows(file, res);

            ProcessBottomLine(file, res);

            return(res);
        }
示例#9
0
        protected virtual bool Eval(VectorMap left, VectorMap right, int ulTimeEval, ref T output)
        {
            // Check for being the same or maybe wrap around
            if (left.Ticks >= right.Ticks)
            {
                output = right.Data;
                return(true);
            }

            // Find the relative position of ulTimeEval between right.Ticks and left.Ticks
            float fAlpha = Util.Unlerp(left.Ticks, ulTimeEval, right.Ticks);

            // Lerp between right.pos and left.pos
            output = Util.Lerp(left.Data, fAlpha, right.Data);
            return(true);
        }
示例#10
0
        private static VectorMap ApplyCurve(ColorMapUshort map, Vector3[] curve)
        {
            var result = new VectorMap(map.Width, map.Height);

            Parallel.For(0, result.Height, y =>
            {
                var input  = map.GetRow(y);
                var output = result.GetRow(y);
                for (var x = 0; x < result.Width; x++)
                {
                    output.SetAndMoveNext(curve[input.R].X, curve[input.G].Y, curve[input.B].Z);
                    input.MoveNext();
                }
            });
            return(result);
        }
示例#11
0
        private static RGB8Map ConvertToRGB(VectorMap map, VectorToColorFilter <byte> filter)
        {
            var result = new RGB8Map(map.Width, map.Height);

            Parallel.For(0, map.Height, y =>
            {
                var input  = map.GetRow(y);
                var output = result.GetRow(y);
                for (var x = 0; x < map.Width; x++)
                {
                    filter.ProcessColor(input, output);
                    input.MoveNext();
                    output.MoveNext();
                }
            });
            return(result);
        }
示例#12
0
        public object Execute(string scriptName, IDictionary <string, Object> dict = null)
        {
            VectorMap vm = new VectorMap();

            if (dict != null)
            {
                foreach (KeyValuePair <string, Object> p in dict)
                {
                    VectorChar vcKey   = toVectorChar(p.Key);
                    VectorChar vcValue = toVectorChar(argMarshaller.ObjectToByteBuffer(p.Value));
                    vm.Add(vcKey, vcValue);
                }
            }
            VectorByte vb = cache.execute(scriptName, vm);

            byte[] ret = new byte[vb.Count];
            vb.CopyTo(ret);
            return(argMarshaller.ObjectFromByteBuffer(ret));
        }
示例#13
0
        static void XYZ(VectorMap vOriginal)
        {
            // Note to self: sRGB white point = (0.3127, 0.329, 0.3583)

            /*string s = "";
             * e.Graphics.DrawString(s, form.Font, Brushes.Black, form.PointToClient(Form.MousePosition) - e.Graphics.MeasureString(s, form.Font).ToSize());*/

            VectorMap vXyyChroma = vOriginal
                                   .ConvertAll(i => RemoveGamma(i))
                                   .ConvertAll(i => RgbToXyz(i))
                                   .ConvertAll(i => XyzToXyy(i))
                                   .ConvertAll(i => new Vector(i.X, i.Y, 0.5f));

            Bitmap bXyzChroma = vXyyChroma
                                .ConvertAll(i => XyyToXyz(i))
                                .ConvertAll(i => XyzToRgb(i))
                                .ConvertAll(i => ApplyGamma(i))
                                .ToBitmap();
        }
示例#14
0
        // B G B G
        // G R G R
        // B G B G
        // G R G R
        private static void ProcessBottomLine(RawBGGRMap <ushort> map, VectorMap res)
        {
            var pix = res.GetPixel();
            var raw = map.GetRow(res.Height - 1);

            // Bottom Left pixel
            var lastY = res.Height - 1;

            pix.SetAndMoveNext(
                raw.GetRel(1, 0) << 1,
                    raw.Value << 1,
                    raw.GetRel(0, -1) << 1);
            raw.MoveNext();

            // Bottom row
            for (var x = 1; x < res.Width - 1; x += 2)
            {
                pix.SetAndMoveNext(
                    raw.Value << 1,
                        (raw.GetRel(-1, 0) + raw.GetRel(+1, 0) + raw.GetRel(0, -1) << 1) >> 1,
                        (raw.GetRel(-1, 0) + raw.GetRel(+1, 0)));

                pix.SetAndMoveNext(
                    (raw.Value + raw.GetRel(+2, 0)),
                    raw.GetRel(+1, 0) << 1,
                        raw.GetRel(+1, 0 - 1) << 1);

                raw.MoveNext();
                raw.MoveNext();
            }

            // Bottom right pixel
            pix.SetAndMoveNext(
                raw.GetRel(-1, 0) << 1,
                    (raw.GetRel(-1, -1) + raw.GetRel(-2, 0)),
                    raw.GetRel(-2, -1) << 1);
            raw.MoveNext();
        }
示例#15
0
        private static void ProcessTopLine(RawBGGRMap <ushort> map, VectorMap res)
        {
            float maxValue = map.MaxValue;
            var   pix      = res.GetPixel();
            var   raw      = map.GetRow(0);

            // Top Left pixel

            pix.SetAndMoveNext(
                (raw.GetRel(1, 1) / maxValue),
                (raw.GetRel(1, 0) + raw.GetRel(0, 1)),
                raw.Value << 1);
            raw.MoveNext();

            // Top row
            for (var x = 1; x < res.Width - 1; x += 2)
            {
                pix.SetAndMoveNext(
                    raw.GetRel(0, 1) << 1,
                        raw.Value << 1,
                        (raw.GetRel(-1, 0) + raw.GetRel(+1, 0)));

                pix.SetAndMoveNext(
                    (raw.GetRel(0, 1) + raw.GetRel(+2, 1)),
                    (raw.Value + raw.GetRel(+2, 0) + (raw.GetRel(+1, 1) << 1)) >> 1,
                    raw.GetRel(+1, 0) << 1);
                raw.MoveNext();
                raw.MoveNext();
            }

            // Top right pixel
            pix.SetAndMoveNext(
                (ushort)(raw.GetRel(res.Width - 1, 1) << 1),
                (ushort)(raw.GetRel(res.Width - 1, 0) << 1),
                (ushort)(raw.GetRel(res.Width - 2, 0) << 1));
            raw.MoveNext();
        }