Ejemplo n.º 1
0
        public SuperTomograph(IImageLoader bitmapLoader, IEmitterDetectorSystem emitterDetectorSystem,
                              IDicomCreator dicomCreator)
        {
            _bitmapLoader          = bitmapLoader;
            _emitterDetectorSystem = emitterDetectorSystem;
            _dicomCreator          = dicomCreator;

            Configuration    = new TomographConfiguration();
            DicomInformation = new DicomInformation();
        }
        public Image <Gray, byte> GetSinogram(Image <Gray, byte> inputImage, TomographConfiguration configuration)
        {
            int columnsCount = (int)(360 / RadianToDegree(configuration.Alpha));

            float[,] brightnessArray = new float[columnsCount, configuration.DetectorsCount];

            int width  = inputImage.Width - 1;
            int height = inputImage.Height - 1;

            int radius = Math.Min(width / 2, height / 2);

            float angle        = 0;
            int   columnNumber = 0;

            while (columnNumber < columnsCount)
            {
                var emitterCoordinates = new Coordinates()
                {
                    X = (int)(radius * Math.Cos(angle)) + width / 2,
                    Y = (int)(radius * Math.Sin(angle)) + height / 2
                };

                for (int i = 0; i < configuration.DetectorsCount; i++)
                {
                    var detectorCoordinates = new Coordinates()
                    {
                        X =
                            (int)
                            (radius *
                             Math.Cos(angle + Math.PI - configuration.Phi / 2 +
                                      i * configuration.Phi / (configuration.DetectorsCount - 1))) + width / 2,
                        Y =
                            (int)
                            (radius *
                             Math.Sin(angle + Math.PI - configuration.Phi / 2 +
                                      i * configuration.Phi / (configuration.DetectorsCount - 1))) + height / 2
                    };

                    brightnessArray[columnNumber, i] = GetBrightness(inputImage, emitterCoordinates, detectorCoordinates);
                }

                columnNumber++;
                angle += configuration.Alpha;
            }

            if (configuration.Filter)
            {
                FilterArray(brightnessArray, configuration.KernelSize);
            }

            NormalizeArray(brightnessArray);

            return(GetImageFromBrightnessArray(brightnessArray));
        }
        public IEnumerable <Image <Gray, byte> > GetOutputImagesFromSinogram(Image <Gray, byte> inputImage, Image <Gray, byte> sinogram, TomographConfiguration configuration)
        {
            var outputImages = new List <Image <Gray, byte> >();

            float[,] brightnessArray = new float[inputImage.Width, inputImage.Height];
            int[,] countArray        = new int[inputImage.Width, inputImage.Height];

            int width  = inputImage.Width - 1;
            int height = inputImage.Height - 1;

            int radius = Math.Min(width / 2, height / 2);

            float angle        = 0;
            int   columnNumber = 0;

            while (columnNumber < sinogram.Width)
            {
                var emitterCoordinates = new Coordinates()
                {
                    X = (int)(radius * Math.Cos(angle)) + width / 2,
                    Y = (int)(radius * Math.Sin(angle)) + height / 2
                };

                for (int i = 0; i < configuration.DetectorsCount; i++)
                {
                    var detectorCoordinates = new Coordinates()
                    {
                        X =
                            (int)
                            (radius *
                             Math.Cos(angle + Math.PI - configuration.Phi / 2 +
                                      i * configuration.Phi / (configuration.DetectorsCount - 1))) + width / 2,
                        Y =
                            (int)
                            (radius *
                             Math.Sin(angle + Math.PI - configuration.Phi / 2 +
                                      i * configuration.Phi / (configuration.DetectorsCount - 1))) + height / 2
                    };


                    float brightnessValue = sinogram.Data[i, columnNumber, 0];

                    DrawLine(brightnessArray, brightnessValue, countArray, emitterCoordinates, detectorCoordinates);
                }

                if ((columnNumber + 1) % (sinogram.Width / configuration.OutputImagesCount) == 0)
                {
                    var currentBrigthnessArray = (float[, ])brightnessArray.Clone();
                    DivideArray(currentBrigthnessArray, countArray);
                    NormalizeArray(currentBrigthnessArray);
                    outputImages.Add(GetImageFromBrightnessArray(currentBrigthnessArray));
                }

                columnNumber++;
                angle += configuration.Alpha;
            }

            return(outputImages);
        }