示例#1
0
        private async Task <BitmapSource> GpuTom(int width, int height)
        {
            return(await Task.Run(async() =>
            {
                //Чтение файла
                var fileDialog = new OpenFileDialog();
                var filePath = string.Empty;

                if (fileDialog.ShowDialog() == true)
                {
                    filePath = fileDialog.FileName;
                }
                else
                {
                    return null;
                }

                var tomographResult = await FileReader.Read(filePath);

                var time = 0.0f;

                //Расчет проекций
                float[] projetions = tomographResult.Projections.SelectMany(x => x.Value).ToArray();
                float[] result = new float[height *width];

                CudaLib.BackProjection(projetions, tomographResult.SampleCount, tomographResult.ProjectionCount, tomographResult.AngleStep, result, ref time);

                //перевод результата в двумерный массив
                var pixels = new float[height, width];

                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        pixels[i, j] = result[j + i *height];
                    }
                }

                Dispatcher.Invoke(() => Console.Text = "Время: " + time + "мс" + Environment.NewLine);

                //Подготовка битовой карты для отображения изображения
                var bitmap = await GetBitmap(pixels, width, height, true);

                return bitmap;
            }));
        }
示例#2
0
        private async Task <BitmapSource> GpuGauss(int width, int height)
        {
            return(await Task.Run(() =>
            {
                var result = new float[width *height];
                var time = 0.0f;
                CudaLib.GpuGaussCalc(result, ref time);

                var pixels = new float[height, width];

                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        pixels[i, j] = result[j + i *height];
                    }
                }

                Dispatcher.Invoke(() => Console.Text = "Время: " + time + "мс" + Environment.NewLine);
                return GetBitmap(pixels, width, height, true);
            }));
        }