コード例 #1
0
        /// <summary>
        /// Checks and produces mask where values != 0 means that values on those indicies are in the range.
        /// </summary>
        /// <param name="img">Input image.</param>
        /// <param name="min">Minimal value.</param>
        /// <param name="max">Maximal value.</param>
        /// <param name="valueToSet">Value to set to result mask.</param>
        /// <param name="channelIndicies">Which channel indicies to check. If not used then it is assumed that all indicies are used.</param>
        /// <returns>Mask</returns>
        public static Gray <byte>[,] InRange <TColor>(this TColor[,] img, TColor min, TColor max, byte valueToSet = 255, params int[] channelIndicies)
        where TColor : struct, IColor <byte>
        {
            var minArr = min.ColorToArray <TColor, byte>();
            var maxArr = max.ColorToArray <TColor, byte>();

            if (channelIndicies == null || channelIndicies.Length == 0)
            {
                channelIndicies = Enumerable.Range(0, img.ColorInfo().ChannelCount).ToArray();
            }

            if (channelIndicies.Length > img.ColorInfo().ChannelCount)
            {
                throw new Exception("Number of processed channels must not exceed the number of available image channels!");
            }

            var destMask = new Gray <byte> [img.Height(), img.Width()];

            destMask.SetValue <Gray <byte> >(Byte.MaxValue);

            using (var uImg = img.Lock())
                using (var uDestMask = destMask.Lock())
                {
                    inRangeByte(uImg, minArr, maxArr, channelIndicies, uDestMask, valueToSet);
                }

            return(destMask);
        }
コード例 #2
0
        /// <summary>
        /// Calculates histogram.
        /// </summary>
        /// <param name="channels">Image channels.</param>
        /// <param name="accumulate">Accumulate or erase histogram before.</param>
        /// <param name="mask">Mask for image color locations.</param>
        /// <param name="maskOffset">The location offset for the mask. The mask area will be [offsetX, offsetY, channelWidth, channelHeight].</param>
        public void Calculate(Gray<byte>[][,] channels, bool accumulate, Gray<byte>[,] mask, Point maskOffset)
        {
            if (!accumulate)
                Array.Clear(histogram, 0, this.NumberOfElements);

            if (mask == null)
            {
                mask = new Gray<byte>[channels[0].Width(), channels[0].Height()];
                mask.SetValue<Gray<byte>>(Byte.MaxValue);
            }

            var maskArea = new Rectangle(maskOffset, channels.First().Size());
            using (var uMask = mask.Lock(maskArea))
            {
                var uChannels = channels.Select(x => x.Lock()).ToArray();
                calculateHistByte(this, uChannels, uMask);
                uChannels.ForEach(x => x.Dispose());
            }
        }
コード例 #3
0
        /// <summary>
        /// Calculates histogram.
        /// </summary>
        /// <param name="channels">Image channels.</param>
        /// <param name="accumulate">Accumulate or erase histogram before.</param>
        /// <param name="mask">Mask for image color locations.</param>
        /// <param name="maskOffset">The location offset for the mask. The mask area will be [offsetX, offsetY, channelWidth, channelHeight].</param>
        public void Calculate(Gray <byte>[][,] channels, bool accumulate, Gray <byte>[,] mask, Point maskOffset)
        {
            if (!accumulate)
            {
                Array.Clear(histogram, 0, this.NumberOfElements);
            }

            if (mask == null)
            {
                mask = new Gray <byte> [channels[0].Width(), channels[0].Height()];
                mask.SetValue <Gray <byte> >(Byte.MaxValue);
            }

            var maskArea = new Rectangle(maskOffset, channels.First().Size());

            using (var uMask = mask.Lock(maskArea))
            {
                var uChannels = channels.Select(x => x.Lock()).ToArray();
                calculateHistByte(this, uChannels, uMask);
                uChannels.ForEach(x => x.Dispose());
            }
        }
コード例 #4
0
        public void TestLKFlow()
        {
            var im1 = new Gray<float>[480, 640];
            im1.SetValue<Gray<float>>(System.Byte.MaxValue, new Accord.Extensions.Rectangle(272, 82, 116, 64));

            var im2 = new Gray<float>[480, 640];
            im2.SetValue<Gray<float>>(System.Byte.MaxValue, new Accord.Extensions.Rectangle(277, 83, 116, 64));

            var pts = new List<PointF>();
            pts.Add(new PointF(272, 82)); //-> 277,83

            PointF[] currFeatures;
            KLTFeatureStatus[] featureStatus;
            /*LKOpticalFlow<Gray<float>>.EstimateFlow(lkStorage, pts.ToArray(),
                                                      out currFeatures, out featureStatus);*/

            PyrLKOpticalFlow<Gray<float>>.EstimateFlow(im1, im2, pts.ToArray(),
                                                       out currFeatures, out featureStatus);

            Assert.IsTrue(featureStatus[0] == KLTFeatureStatus.Success);
            Assert.IsTrue(Math.Round(currFeatures[0].X) == 277 && Math.Round(currFeatures[0].Y) == 83);
        }