/// <summary> /// Back-projects (creates probability map) from histogram values. /// </summary> /// <param name="srcs">Image channels.</param> /// <returns>Back-projection image (probability image) </returns> public Gray <byte>[,] BackProject(Gray <byte>[][,] srcs) { var destImg = srcs.First().CopyBlank(); using (var uDestImg = destImg.Lock()) { var uChannels = srcs.Select(x => x.Lock()).ToArray(); backProjectByte(this, uChannels, uDestImg); uChannels.ForEach(x => x.Dispose()); } return(destImg); }
/// <summary> /// Back-projects (creates probability map) from histogram values. /// </summary> /// <param name="srcs">Image channels.</param> /// <returns>Back-projection image (probability image) </returns> public Gray<byte>[,] BackProject(Gray<byte>[][,] srcs) { var destImg = srcs.First().CopyBlank(); using (var uDestImg = destImg.Lock()) { var uChannels = srcs.Select(x => x.Lock()).ToArray(); backProjectByte(this, uChannels, uDestImg); uChannels.ForEach(x => x.Dispose()); } return destImg; }
/// <summary> /// Computes the Bag of Words model. /// </summary> /// <typeparam name="TPoint"> /// The <see cref="Accord.Imaging.IFeaturePoint{TFeature}"/> type to be used with this class, /// such as <see cref="Accord.Imaging.SpeededUpRobustFeaturePoint"/>. /// </typeparam> /// <typeparam name="TFeature"> /// The feature type of the <typeparamref name="TPoint"/>, such /// as <see cref="T:double[]"/>. /// </typeparam> /// <param name="bow">Bag of Visual Words.</param> /// <param name="images">The set of images to initialize the model.</param> /// <param name="threshold">Convergence rate for the k-means algorithm. Default is 1e-5.</param> /// <returns>The list of feature points detected in all images.</returns> public static List <TPoint>[] Compute <TPoint, TFeature>(this BagOfVisualWords <TPoint, TFeature> bow, Gray <byte>[][,] images, double threshold = 1e-5) where TPoint : IFeatureDescriptor <TFeature> { var uImages = images.Select(x => x.Lock()); var featurePoints = bow.Compute ( uImages.Select(x => x.AsBitmap()).ToArray(), threshold ); uImages.ForEach(x => x.Dispose()); return(featurePoints); }
/// <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()); } }
/// <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()); } }