Esempio n. 1
0
        //Converts input picture into sinogram
        public void PicturetoSinogram()
        {
            line = new BresenhamLine();

            this.alfa = 0;

            int i = 0;

            while (alfa < 2 * Math.PI)
            {
                SetEmmiterPoint();
                for (int j = 0; j < n; j++)
                {
                    Point det = GetDetectorPoint(j);
                    line.GenerateLine(emmiter, det);
                    foreach (Point pt in line.line)
                    {
                        int color = inpic[pt.X, pt.Y];
                        sinogram[j, i] += color;
                    }
                    sinogram[j, i] /= line.line.Count;
                }
                NextAlfa();
                i++;
            }

            int max = sinogram.Cast <int>().ToList().Max();

            for (int k = 0; k < sinogram.GetLength(0); k++)
            {
                for (int l = 0; l < sinogram.GetLength(1); l++)
                {
                    sinogram[k, l] = Convert.ToInt32(sinogram[k, l] * 1.0 / max * 255);
                }
            }
        }
Esempio n. 2
0
        //Converts sinogram into output picture
        public void SinogramtoPicture()
        {
            int[,] outpic = new int[inpic.GetLength(0), inpic.GetLength(1)];
            ResetArr(outpic);

            line = new BresenhamLine();

            this.alfa = 0;

            int i = 0;

            int d = 5;

            while (Math.PI / step / d > 100)
            {
                d += 1;
            }

            using (System.IO.StreamWriter file = new System.IO.StreamWriter("pomiary.txt"))
            {
                file.WriteLine("Steps;" + steps.ToString() + ";Step;" + step.ToString() + ";l;" + l.ToString() + ";n;" + n.ToString());
            }

            while (alfa < 2 * Math.PI)
            {
                if (i % d == 0)
                {
                    outpics.Add((int[, ])outpic.Clone());
                }

                SetEmmiterPoint();
                for (int j = 0; j < n; j++)
                {
                    int sum = filtredsinogram[j, i];

                    Point det = GetDetectorPoint(j);
                    line.GenerateLine(emmiter, det);

                    int val = 0;
                    foreach (Point pt in line.line)
                    {
                        val += outpic[pt.X, pt.Y];
                    }
                    val /= line.line.Count;

                    foreach (Point pt in line.line)
                    {
                        int pix  = outpic[pt.X, pt.Y];
                        int diff = 3;
                        if (sum > val)
                        {
                            pix += diff;
                            if (pix > 255)
                            {
                                pix = 255;
                            }
                        }
                        else
                        {
                            pix -= diff;
                            if (pix < 0)
                            {
                                pix = 0;
                            }
                        }
                        outpic[pt.X, pt.Y] = pix;
                    }
                }

                using (System.IO.StreamWriter file = new System.IO.StreamWriter("pomiary.txt", true))
                {
                    file.WriteLine(alfa.ToString() + ';' + i.ToString() + ';' + CountMeanSquaredError(outpic).ToString());
                }

                NextAlfa();
                i++;
            }
            outpics.Add((int[, ])outpic.Clone());
            this.meanSquaredError = CountMeanSquaredError(outpics[outpics.Count - 1]);
        }