Esempio n. 1
0
        private float[,] BackProjection(TomographResult tomographResult)
        {
            var NN     = tomographResult.SampleCount;
            var pixels = new float[NN, NN];

            foreach (var projection in tomographResult.Projections)
            {
                var angle = projection.Key;

                var sinGL = Math.Sin(Math.PI / 180.0f * angle);
                var cosGL = Math.Cos(Math.PI / 180.0f * angle);


                for (int i = 0; i < NN; i++)
                {
                    for (int j = 0; j < NN; j++)
                    {
                        var v = (j - (NN / 2.0f)) * cosGL + (i - (NN / 2.0f)) * sinGL;
                        var r = Math.Round(v) + NN / 2.0f;

                        if ((r < (NN - 1)) && (r > -1))
                        {
                            pixels[i, j] = pixels[i, j] + projection.Value[(int)r];
                        }
                    }
                }
            }

            return(pixels);
        }
Esempio n. 2
0
        public static async Task <TomographResult> Read(string path)
        {
            return(await Task.Run(() =>
            {
                var fileLines = File.ReadLines(path);

                if (fileLines.Count() == 0)
                {
                    throw new Exception("пустой файл");
                }

                if (fileLines.First() != "data")
                {
                    throw new Exception("неверный формат данных");
                }

                var result = new TomographResult
                {
                    SampleCount = int.Parse(fileLines.ElementAt(1)),
                    ProjectionCount = int.Parse(fileLines.ElementAt(2)),
                    AngleStep = float.Parse(fileLines.ElementAt(3), CultureInfo.InvariantCulture)
                };

                var projectionsWithAngles = fileLines.Skip(5);

                var angle = 0f;

                for (int i = 0; i < projectionsWithAngles.Count(); i += 2)
                {
                    var projection = projectionsWithAngles
                                     .ElementAt(i)
                                     .Split(' ')
                                     .Where(x => string.IsNullOrWhiteSpace(x) == false)
                                     .Select(x => float.Parse(x, CultureInfo.InvariantCulture)).ToArray();

                    result.Projections.Add(angle, projection);

                    angle += result.AngleStep;
                }

                return result;
            }));
        }