public GrayscaleBitmap PerformAdditionalIterations(int iterationCount, ProgressCounter progressCounter = null)
 {
     if (currentReconstruction == null)
         throw new NullReferenceException("The Reconstruct method must be called first");
     for (int i = 0; i < iterationCount; i++)
     {
         lastIterationNumber++;
         Console.WriteLine("Iteration: " + lastIterationNumber);
         performOneIteration(lastIterationNumber % projections.Count, currentReconstruction);
         progressCounter?.AddStep();
     }
     GrayscaleBitmap ret = new GrayscaleBitmap(currentReconstruction.Width, currentReconstruction.Height);
     for (int i = 0; i < currentReconstruction.Width; i++)
     {
         for (int j = 0; j < currentReconstruction.Height; j++)
         {
             if (currentReconstruction[i, j] < 0)
                 ret[i, j] = 0;
             else if (currentReconstruction[i, j] > 1)
                 ret[i, j] = 1;
             else
                 ret[i, j] = currentReconstruction[i, j];
         }
     }
     return ret;
 }
        /// <summary>
        /// Reconstructs the image from projections specified in constructor
        /// </summary>
        /// <param name="progressCounter"></param>
        /// <returns>Reconstructed image</returns>
        public GrayscaleBitmap Reconstruct(ProgressCounter progressCounter = null)
        {
            int             size = projections[0].Length;
            GrayscaleBitmap bmp  = new GrayscaleBitmap(size, size);


            for (int i = 0; i < projections.Count; i++)
            {
                double angle = angleBetweenProjections * i;

                //Extrude projection in given angle
                GrayscaleBitmap extrudedProjection = projectionHandler.ExtrudeProjection(projections[i], angle);

                //add given extruded projection to the result
                bmp += extrudedProjection;
                progressCounter?.AddStep();
            }

            bmp.Stretch();
            return(bmp);
        }
 public GrayscaleBitmap Reconstruct(int iterationCount, ProgressCounter progressCounter = null)
 {
     int size = projections[0].Length;
     double avrg = 0;
     for (int i = 0; i < projections[0].Length; i++)
         avrg += projections[0][i];
     avrg /= (size * size);
     GrayscaleBitmap bmp = new GrayscaleBitmap(size, size);
     for (int i = 0; i < bmp.Width; i++)
     {
         for (int j = 0; j < bmp.Height; j++)
         {
             bmp[i, j] = avrg;
         }
     }
     for (int i = 0; i < iterationCount; i++)
     {
         Console.WriteLine("Iteration: " + i);
         performOneIteration(i % projections.Count, bmp);
         lastIterationNumber = i;
         progressCounter?.AddStep();
     }
     GrayscaleBitmap ret = new GrayscaleBitmap(bmp.Width, bmp.Height);
     for (int i = 0; i < bmp.Width; i++)
     {
         for (int j = 0; j < bmp.Height; j++)
         {
             if (bmp[i, j] < 0)
                 ret[i, j] = 0;
             else if (bmp[i, j] > 1)
                 ret[i, j] = 1;
             else
                 ret[i, j] = bmp[i, j];
         }
     }
     currentReconstruction = bmp;
     return ret;
 }
Beispiel #4
0
        public List <double[]> GenerateProjections(GrayscaleBitmap bmp, int sliceCount, ProgressCounter progressCounter = null)
        {
            if (sliceCount < 1)
            {
                throw new ArgumentOutOfRangeException("sliceCount", "sliceCount must be at least 1");
            }

            List <double[]> projections = new List <double[]>(sliceCount);

            double angleStep = 180.0 / sliceCount;

            for (int i = 0; i < sliceCount; i++)
            {
                double angle = i * angleStep;

                projections.Add(CreateProjection(bmp, angle));
                progressCounter?.AddStep();
            }

            return(projections);
        }