Пример #1
0
 /// <summary>
 /// Makes all values absolute
 /// </summary>
 /// <param name="queue">cloo command queue</param>
 /// <param name="source">image</param>
 public void Abs(ClooCommandQueue queue, ClooImage2DFloatRgbA image)
 {
     Abs(queue, image, image);
 }
Пример #2
0
        /// <summary>
        /// Create histogram
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="histogram">byte buffer (256 bytes)</param>
        /// <param name="startX">start from X coordinate</param>
        /// <param name="startY">start from Y coordinate</param>
        /// <param name="width">width</param>
        /// <param name="height">height</param>
        public void Histogram256(ClooCommandQueue queue, ClooImage2DByteA source, ClooBuffer<uint> histogram,
            int startX = 0, int startY = 0, int width = 0, int height = 0)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source == null) throw new ArgumentNullException("source");
            if (histogram == null) throw new ArgumentNullException("histogram");

            if (histogram.Size < 256) throw new ArgumentException("Buffer size for histogram must be at least 256 bytes", "histogram");
            if (width == 0) width = source.Width - startX;
            if (height == 0) height = source.Height - startY;
            if (width < 0) throw new ArgumentOutOfRangeException("width");
            if (height < 0) throw new ArgumentOutOfRangeException("height");

            KernelCoreUIntSetValue.SetArguments(histogram, (uint)0);
            queue.Execute(KernelCoreUIntSetValue, null, new long[] { 256 }, null, null);

            KernelImageByteHistogram256.SetArguments(source, histogram, (uint)startX, (uint)startY);
            queue.Execute(KernelImageByteHistogram256, null, new long[] { width, height }, null, null);
            histogram.Modified = true;
        }
Пример #3
0
        /// <summary>
        /// Sets a constant value to all cells in an image
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="image">image</param>
        /// <param name="value">value to set</param>
        public void SetValue(ClooCommandQueue queue, ClooImage2DUIntA image, uint value)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (image == null) throw new ArgumentNullException("dest");

            KernelImageUIntSetValueA.SetArguments(image, value);
            queue.Execute(KernelImageUIntSetValueA, null, new long[] { image.Width, image.Height }, null, null);
            image.Modified = true;
        }
Пример #4
0
 /// <summary>
 /// Denormalize float image
 /// </summary>
 /// <param name="queue">cloo command queue</param>
 /// <param name="image">image</param>
 public void Denormalize(ClooCommandQueue queue, ClooImage2DFloatRgbA image)
 {
     Denormalize(queue, image, image);
 }
Пример #5
0
        /// <summary>
        /// Extracts a channel of an RGB image
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="dest">image destination</param>
        /// <param name="offset">offset (0..3)</param>
        public void ExtractChannel(ClooCommandQueue queue, ClooImage2DByteRgbA source, ClooImage2DByteA dest, byte offset)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source == null) throw new ArgumentNullException("source");
            if (dest == null) throw new ArgumentNullException("dest");
            if (offset > 3) throw new ArgumentOutOfRangeException("offset", String.Format("offset must be between 0..3 but was {0}", offset));
            if ((source.Width > dest.Width) || (source.Height > dest.Height)) throw new ArgumentException("Destination image (" + dest.Width + "x" + dest.Height + ") must have at least the same size as the source image (" + source.Width + "x" + source.Height + ")");

            KernelImageByteExtractChannel.SetArguments(source, dest, offset);
            queue.Execute(KernelImageByteExtractChannel, null, new long[] { source.Width, source.Height }, null, null);
            dest.Modified = true;
        }
Пример #6
0
        /// <summary>
        /// Convert gray byte image to RGB byte image
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="dest">image destination</param>
        public void ByteAToByteRgbA(ClooCommandQueue queue, ClooImage2DByteA source, ClooImage2DByteRgbA dest)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source == null) throw new ArgumentNullException("source");
            if (dest == null) throw new ArgumentNullException("dest");
            if ((source.Width > dest.Width) || (source.Height > dest.Height)) throw new ArgumentException("Destination image (" + dest.Width + "x" + dest.Height + ") must have at least the same size as the source image (" + source.Width + "x" + source.Height + ")");

            KernelImageByteAToByteRgbA.SetArguments(source, dest);
            queue.Execute(KernelImageByteAToByteRgbA, null, new long[] { source.Width, source.Height }, null, null);
            dest.Modified = true;
        }
Пример #7
0
 /// <summary>
 /// Clamps minimum and maximum value
 /// </summary>
 /// <param name="queue">cloo command queue</param>
 /// <param name="image">image</param>
 /// <param name="minValue">minimum value</param>
 /// <param name="maxValue">maximum value</param>
 public void Clamp(ClooCommandQueue queue, ClooImage2DFloatRgbA image, float minValue, float maxValue)
 {
     Clamp(queue, image, image, minValue, maxValue);
 }
Пример #8
0
 /// <summary>
 /// Normalize float image
 /// </summary>
 /// <param name="queue">cloo command queue</param>
 /// <param name="image">image</param>
 public void Normalize(ClooCommandQueue queue, ClooImage2DFloatA image)
 {
     Normalize(queue, image, image);
 }
Пример #9
0
        /// <summary>
        /// RGB to HSL image
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="dest">image destination</param>
        public void RgbToHsl(ClooCommandQueue queue, ClooImage2DFloatRgbA source, ClooImage2DFloatRgbA dest)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source == null) throw new ArgumentNullException("source");
            if (dest == null) throw new ArgumentNullException("dest");
            if ((source.Width > dest.Width) || (source.Height > dest.Height)) throw new ArgumentException("Destination image (" + dest.Width + "x" + dest.Height + ") must have at least the same size as the source image (" + source.Width + "x" + source.Height + ")");

            if (source.Normalized)
            {
                // use normalized kernel
                KernelImageFloatRgbToHslNorm.SetArguments(source, dest);
                queue.Execute(KernelImageFloatRgbToHslNorm, null, new long[] { source.Width, source.Height }, null, null);
            }
            else
            {
                // use normal kernel
                KernelImageFloatRgbToHsl.SetArguments(source, dest);
                queue.Execute(KernelImageFloatRgbToHsl, null, new long[] { source.Width, source.Height }, null, null);
            }
            dest.Modified = true;
            dest.Normalized = source.Normalized;
        }
Пример #10
0
        /// <summary>
        /// Convert an float image to a squared integral image
        /// </summary>
        /// <remarks>
        /// We skip the last line to keep the original size (better performance)
        /// </remarks>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="dest">image destination</param>
        public void IntegralSquare(ClooCommandQueue queue, ClooImage2DByteA source, ClooImage2DUIntA dest)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source == null) throw new ArgumentNullException("source");
            if (dest == null) throw new ArgumentNullException("dest");
            if ((source.Width > dest.Width) || (source.Height > dest.Height)) throw new ArgumentException("Destination image (" + dest.Width + "x" + dest.Height + ") must have at least the source image width and height but is only " + source.Width + "x" + source.Height);

            // execute step 1
            SetValue(queue, dest, 0);
            KernelImageUIntIntegralSquareStep1.SetArguments(source, dest);
            queue.Execute(KernelImageUIntIntegralSquareStep1, null, new long[] { source.Height - 1 }, null, null);
            dest.Modified = true;

            // execute step 2
            KernelImageUIntIntegralSquare.SetArguments(dest, dest, source.Height);
            queue.Execute(KernelImageUIntIntegralSquare, null, new long[] { source.Width - 1 }, null, null);
            dest.Modified = true;
        }
Пример #11
0
 /// <summary>
 /// Multiplies a constant value to all float values in an image
 /// </summary>
 /// <param name="queue">cloo command queue</param>
 /// <param name="image">image</param>
 /// <param name="factor">factor to multiply</param>
 public void MultiplyValue(ClooCommandQueue queue, ClooImage2DFloatRgbA image, float factor)
 {
     MultiplyValue(queue, image, image, factor);
 }
Пример #12
0
        /// <summary>
        /// Convert an float image to an integral image
        /// </summary>
        /// <remarks>
        /// We skip the last line to keep the original size (better performance)
        /// </remarks>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="dest">image destination</param>
        public void Integral(ClooCommandQueue queue, ClooImage2DFloatA source, ClooImage2DFloatA dest)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source == null) throw new ArgumentNullException("source");
            if (dest == null) throw new ArgumentNullException("dest");
            if (source == dest) throw new ArgumentNullException("Source image and destination image must not be the same instance");
            if ((source.Width > dest.Width) || (source.Height > dest.Height)) throw new ArgumentException("Destination image (" + dest.Width + "x" + dest.Height + ") must have at least the source image width and height but is only " + source.Width + "x" + source.Height);

            // execute step 1
            SetValue(queue, dest, 0);
            KernelImageFloatIntegralStep1.SetArguments(source, dest);
            queue.Execute(KernelImageFloatIntegralStep1, null, new long[] { source.Height - 1 }, null, null);
            dest.Modified = true;

            // execute step 2
            KernelImageFloatIntegral.SetArguments(dest, dest, source.Height);
            queue.Execute(KernelImageFloatIntegral, null, new long[] { source.Width - 1 }, null, null);
            dest.Modified = true;

            dest.Normalized = false;
        }
Пример #13
0
        /// <summary>
        /// Create color histogram with N bins
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="histogram">uint buffer (must be at least bins^3 in length)</param>
        /// <param name="bins">number of bins</param>
        /// <param name="startX">start from X coordinate</param>
        /// <param name="startY">start from Y coordinate</param>
        /// <param name="width">width</param>
        /// <param name="height">height</param>
        public void HistogramN(ClooCommandQueue queue, ClooImage2DByteRgbA source, ClooBuffer<uint> histogram,
            byte bins, int startX = 0, int startY = 0, int width = 0, int height = 0)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source == null) throw new ArgumentNullException("source");
            if (histogram == null) throw new ArgumentNullException("histogram");
            if (bins < 2) throw new ArgumentException("bins must be at least 2", "bins");

            int length = bins * bins * bins;
            if (histogram.Count < length) throw new ArgumentException("Buffer length for histogram must be at least " + length, "histogram");
            if (width == 0) width = source.Width - startX;
            if (height == 0) height = source.Height - startY;
            if (width < 0) throw new ArgumentOutOfRangeException("width");
            if (height < 0) throw new ArgumentOutOfRangeException("height");

            KernelCoreUIntSetValue.SetArguments(histogram, (uint)0);
            queue.Execute(KernelCoreUIntSetValue, null, new long[] { 256 }, null, null);

            KernelImageByteRgbHistogramN.SetArguments(source, histogram, bins, (uint)startX, (uint)startY);
            queue.Execute(KernelImageByteRgbHistogramN, null, new long[] { width, height }, null, null);
            histogram.Modified = true;
        }
Пример #14
0
        /// <summary>
        /// Create histogram backprojection for RGB float image
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="dest">image destination (for propability map)</param>
        /// <param name="srcHistogram">source histogram uint buffer (must be at least bins^3 in length)</param>
        /// <param name="frameHistogram">frame histogram uint buffer (must be at least bins^3 in length)</param>
        /// <param name="bins">number of bins</param>
        /// <param name="startX">start from X coordinate</param>
        /// <param name="startY">start from Y coordinate</param>
        /// <param name="width">width</param>
        /// <param name="height">height</param>
        public void HistogramBackprojection(ClooCommandQueue queue, ClooImage2DByteRgbA source, ClooImage2DFloatRgbA dest,
            ClooBuffer<uint> srcHistogram, ClooBuffer<uint> frameHistogram, byte bins, int startX = 0, int startY = 0,
            int width = 0, int height = 0)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source == null) throw new ArgumentNullException("source");
            if (dest == null) throw new ArgumentNullException("dest");
            if (srcHistogram == null) throw new ArgumentNullException("srcHistogram");
            if (frameHistogram == null) throw new ArgumentNullException("frameHistogram");
            if (bins < 2) throw new ArgumentException("bins must be at least 2", "bins");

            int length = bins * bins * bins;
            if (srcHistogram.Count < length) throw new ArgumentException("Buffer length for histogram must be at least " + length, "srcHistogram");
            if (frameHistogram.Count < length) throw new ArgumentException("Buffer length for histogram must be at least " + length, "frameHistogram");
            if (width == 0) width = source.Width - startX;
            if (height == 0) height = source.Height - startY;
            if (width < 0) throw new ArgumentOutOfRangeException("width");
            if (height < 0) throw new ArgumentOutOfRangeException("height");

            KernelImageByteRgbHistogramFloatBP.SetArguments(source, dest, srcHistogram, frameHistogram, bins, (uint)startX, (uint)startY);
            queue.Execute(KernelImageByteRgbHistogramFloatBP, null, new long[] { width, height }, null, null);
            dest.Modified = true;
            dest.Normalized = true;
        }
Пример #15
0
 /// <summary>
 /// Adds a constant value to all float values in an image
 /// </summary>
 /// <param name="queue">cloo command queue</param>
 /// <param name="image">image</param>
 /// <param name="value">value to add</param>
 public void AddValue(ClooCommandQueue queue, ClooImage2DFloatRgbA image, float value)
 {
     AddValue(queue, image, image, value);
 }
Пример #16
0
 /// <summary>
 /// Sets channel of a RGBA image
 /// </summary>
 /// <param name="queue">cloo command queue</param>
 /// <param name="image">image</param>
 /// <param name="mask">mask image</param>
 /// <param name="offset">offset (0..3)</param>
 public void SetChannel(ClooCommandQueue queue, ClooImage2DFloatRgbA image, ClooImage2DFloatA mask, byte offset)
 {
     SetChannel(queue, image, mask, image, offset);
 }
Пример #17
0
        /// <summary>
        /// Box blur image
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="dest">image destination</param>
        /// <param name="sampler">sampler to be used for image reading</param>
        /// <param name="offset">offset</param>
        public void BoxBlur(ClooCommandQueue queue, ClooImage2DFloatRgbA source, ClooImage2DFloatRgbA dest, ClooSampler sampler, int offset)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source == null) throw new ArgumentNullException("source");
            if (dest == null) throw new ArgumentNullException("dest");
            if ((source.Width > dest.Width) || (source.Height > dest.Height)) throw new ArgumentException("Destination image (" + dest.Width + "x" + dest.Height + ") must have at least the same size as the source image (" + source.Width + "x" + source.Height + ")");

            KernelImageFloatBoxBlur.SetArguments(source, dest, sampler, offset);
            queue.Execute(KernelImageFloatBoxBlur, null, new long[] { source.Width, source.Height }, null, null);
            dest.Modified = true;
            dest.Normalized = source.Normalized;
        }
Пример #18
0
 /// <summary>
 /// Sets channel of a RGBA image
 /// </summary>
 /// <param name="queue">cloo command queue</param>
 /// <param name="image">image</param>
 /// <param name="mask">mask image</param>
 /// <param name="offset">offset (0..3)</param>
 /// <param name="value">constant mask value</param>
 public void SetChannel(ClooCommandQueue queue, ClooImage2DFloatRgbA image, byte offset, byte value)
 {
     SetChannel(queue, image, image, offset, value);
 }
Пример #19
0
        /// <summary>
        /// Clamps minimum and maximum value
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="dest">image destination</param>
        /// <param name="minValue">minimum value</param>
        /// <param name="maxValue">maximum value</param>
        public void Clamp(ClooCommandQueue queue, ClooImage2DFloatA source, ClooImage2DFloatA dest, float minValue, float maxValue)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source == null) throw new ArgumentNullException("source");
            if (dest == null) throw new ArgumentNullException("dest");
            if ((source.Width > dest.Width) || (source.Height > dest.Height)) throw new ArgumentException("Destination image (" + dest.Width + "x" + dest.Height + ") must have at least the same size as the source image (" + source.Width + "x" + source.Height + ")");

            KernelImageFloatClamp.SetArguments(source, dest, minValue, maxValue);
            queue.Execute(KernelImageFloatClamp, null, new long[] { source.Width, source.Height }, null, null);
            dest.Modified = true;
            dest.Normalized = source.Normalized;
        }
Пример #20
0
        /// <summary>
        /// Sets a constant value to all cells in an image
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="image">image</param>
        /// <param name="value">value to set</param>
        public void SetValue(ClooCommandQueue queue, ClooImage2DByteRgbA image, byte value)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (image == null) throw new ArgumentNullException("image");

            KernelImageByteSetValueA.SetArguments(image, (uint)value);
            queue.Execute(KernelImageByteSetValueA, null, new long[] { image.Width, image.Height }, null, null);
            image.Modified = true;
        }
Пример #21
0
        /// <summary>
        /// Denormalize float image
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="dest">image destination</param>
        public void Denormalize(ClooCommandQueue queue, ClooImage2DFloatRgbA source, ClooImage2DFloatRgbA dest)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source == null) throw new ArgumentNullException("source");
            if (dest == null) throw new ArgumentNullException("dest");
            if ((source.Width > dest.Width) || (source.Height > dest.Height)) throw new ArgumentException("Destination image (" + dest.Width + "x" + dest.Height + ") must have at least the same size as the source image (" + source.Width + "x" + source.Height + ")");

            KernelImageFloatMultiplyValue.SetArguments(source, dest, 255f);
            queue.Execute(KernelImageFloatMultiplyValue, null, new long[] { source.Width, source.Height }, null, null);
            dest.Modified = true;
            dest.Normalized = false;
        }
Пример #22
0
        /// <summary>
        /// Sets a constant value to all cells in an image
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="image">image</param>
        /// <param name="value">value to set</param>
        public void SetValue(ClooCommandQueue queue, ClooImage2DByteRgbA image, uint value)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (image == null) throw new ArgumentNullException("image");

            uint r = (value >> 24) % 256;
            uint g = (value >> 16) % 256;
            uint b = (value >> 8) % 256;
            uint a = (value) % 256;
            KernelImageByteSetValueRgbA.SetArguments(image, r, g, b, a);
            queue.Execute(KernelImageByteSetValueRgbA, null, new long[] { image.Width, image.Height }, null, null);
            image.Modified = true;
        }
Пример #23
0
        /// <summary>
        /// Calculates the difference between two images (e.g. for background subtraction)
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="dest">image destination</param>
        public void Diff(ClooCommandQueue queue, ClooImage2DFloatRgbA source1, ClooImage2DFloatRgbA source2, ClooImage2DFloatA dest)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source1 == null) throw new ArgumentNullException("source1");
            if (source2 == null) throw new ArgumentNullException("source2");
            if (dest == null) throw new ArgumentNullException("dest");
            if ((source2.Width > source1.Width) || (source2.Height > source1.Height)) throw new ArgumentException("Second image (" + dest.Width + "x" + dest.Height + ") must have at least the same size as the first image (" + source1.Width + "x" + source1.Height + ")");
            if ((source1.Width > dest.Width) || (source1.Height > dest.Height)) throw new ArgumentException("Destination image (" + dest.Width + "x" + dest.Height + ") must have at least the same size as the source image (" + source1.Width + "x" + source1.Height + ")");

            KernelImageFloatDiff.SetArguments(source1, source2, dest);
            queue.Execute(KernelImageFloatDiff, null, new long[] { source2.Width, source2.Height }, null, null);
            dest.Modified = true;
            dest.Normalized = false;
        }
Пример #24
0
        /// <summary>
        /// Sets a constant value to all float values in an image
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="image">image</param>
        /// <param name="value">value to set</param>
        public void SetValue(ClooCommandQueue queue, ClooImage2DFloatRgbA image, float value)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (image == null) throw new ArgumentNullException("image");

            KernelImageFloatSetValue.SetArguments(image, value);
            queue.Execute(KernelImageFloatSetValue, null, new long[] { image.Width, image.Height }, null, null);
            image.Modified = true;
        }
Пример #25
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="handle">event handle</param>
 /// <param name="queue">cloo compute command queue</param>
 public ClooEvent(IntPtr handle, ClooCommandQueue queue)
     : base(handle, queue)
 {
 }
Пример #26
0
        /// <summary>
        /// Flip image Y coordinate
        /// </summary>
        /// <param name="queue">cloo command queue</param>
        /// <param name="source">image source</param>
        /// <param name="dest">image destination</param>
        public void FlipY(ClooCommandQueue queue, ClooImage2DFloatRgbA source, ClooImage2DFloatRgbA dest)
        {
            if (queue == null) throw new ArgumentNullException("queue");
            if (source == null) throw new ArgumentNullException("source");
            if (dest == null) throw new ArgumentNullException("dest");
            if (source == dest) throw new ArgumentException("Flipping kernel is not designed to run inline therefore source and destination must be different images");
            if ((source.Width > dest.Width) || (source.Height > dest.Height)) throw new ArgumentException("Destination image (" + dest.Width + "x" + dest.Height + ") must have at least the same size as the source image (" + source.Width + "x" + source.Height + ")");

            KernelImageFloatFlipY.SetArguments(source, dest);
            queue.Execute(KernelImageFloatFlipY, null, new long[] { source.Width, source.Height }, null, null);
            dest.Modified = true;
            dest.Normalized = source.Normalized;
        }