Ejemplo n.º 1
0
        public static uint[] GetHistogram(Index3 index, ArrayView3D <short> imageView, /*remove*/ Index2 histImageIndex, HistogramData histData)
        {
            var histogramKernel      = GpuContext.Instance.Accelerator.LoadAutoGroupedStreamKernel <Index3, ArrayView <int>, ArrayView3D <short> >(HistogramKernels.CalculateHistogram);
            var histogramImageKernel = GpuContext.Instance.Accelerator.LoadAutoGroupedStreamKernel <Index, ArrayView2D <short>, ArrayView <int>, double, double, int>(HistogramKernels.CalculateHistogramImage);

            uint[] result;
            int[]  buf1;

            using (var bufHist = GpuContext.Instance.Accelerator.Allocate <int>(short.MaxValue))
            {
                bufHist.MemSetToZero();
                histogramKernel(index, bufHist.View, imageView);
                GpuContext.Instance.Accelerator.Synchronize();

                buf1 = bufHist.GetAsArray();
                var lastElement = KernelHelpers.FindLastNotZeroIndex(buf1);
                histData.histogramData = buf1.Take(lastElement + 1).ToArray();
                var max = buf1.Skip(1).Max();


                using (var bufHistImage = GpuContext.Instance.Accelerator.Allocate <short>(histImageIndex))
                    using (var bufOut2 = GpuContext.Instance.Accelerator.Allocate <uint>(histImageIndex.Size))
                    {
                        bufHistImage.MemSetToZero();
                        histogramImageKernel(new Index(lastElement + 1), bufHistImage.View, bufHist.View.GetSubView(0, lastElement + 1), 1000, 1000, max);
                        GpuContext.Instance.Accelerator.Synchronize();

                        PiсConvertKernel(histImageIndex.Size, bufOut2, bufHistImage.AsLinearView(), 1, 0);
                        GpuContext.Instance.Accelerator.Synchronize();

                        result = bufOut2.GetAsArray();
                    }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static void CalculateSobel(Index2 index, ArrayView2D <short> result, ArrayView3D <short> accumulatedSobel)
        {
            var val = KernelHelpers.Magnitude(accumulatedSobel, index);

            result[index] = val;
        }
Ejemplo n.º 3
0
 public static void AccumulateSobelMap(Index3 index, ArrayView3D <short> result, ArrayView3D <short> hSobel, ArrayView3D <short> vSobel)
 {
     result[index] = KernelHelpers.Magnitude(hSobel[index], vSobel[index]);
 }