Example #1
0
        public Sinogram Clone()
        {
            Sinogram res = new Sinogram();

            res.data = (double[, ])data.Clone();
            res.anglesDistribution = anglesDistribution.Clone();

            return(res);
        }
Example #2
0
        public static void SaveSinogramToStream(System.IO.Stream s, Sinogram sino)
        {
            int sz = Sinogram.GetSinogramSizeInBytes(sino);

            var outBytes = new byte[sz];

            SaveSinogramToBytes(outBytes, 0, sino);

            s.Write(outBytes, 0, outBytes.Length);
        }
Example #3
0
        public static void SaveSinogramToBytes(byte[] b, int ofs, Sinogram sino)
        {
            int Offset = ofs;

            int numSamples = sino.NumSamples;
            int numPhi     = sino.AnglesDistribution.Count;

            // 1. кол-во сэмплов по S
            BitUtils.ToBytes32((uint)numSamples, b, Offset + 0);
            // 2. кол-во направлений
            BitUtils.ToBytes32((uint)numPhi, b, Offset + 4);
            // 3. данные синограммы, doubles
            Offset += 8;

            for (int j = 0; j < numPhi; j++)
            {
                for (int i = 0; i < numSamples; i++)
                {
                    BitUtils.ToDouble(sino[j, i], b, Offset);
                    Offset += 8;
                }
            }
        }
Example #4
0
 public static int GetSinogramSizeInBytes(Sinogram sino)
 {
     // +8 - это NumSamples и NumPhi
     return(8 * sino.NumSamples * sino.AnglesDistribution.Count + 8);
 }
        public void Build(string path)
        {
            var sins = new double[numSins][, ];

            for (int i = 0; i < numSins; i++)
            {
                sins[i] = new double[indexer.NumDirs, indexer.NumLines];
            }

            Bitmap   bmp = new Bitmap(1024, 1024);
            Graphics gr  = Graphics.FromImage(bmp);

            gr.TranslateTransform(bmp.Width / 2f, bmp.Height / 2f);

            List <string> fileList = new List <string>();

            if (Directory.Exists(path))
            {
                DirectoryInfo    di    = new DirectoryInfo(path);
                FileSystemInfo[] files = di.GetFileSystemInfos();
                foreach (var file in files)
                {
                    fileList.Add(file.FullName);
                }
            }

            foreach (var file in fileList)
            {
                var clist = WorkWithFiles.ReadCoincList(file);
                foreach (var c in clist)
                {
                    PETDigitalCoincidenceTOF cIJ = new PETDigitalCoincidenceTOF();
                    EventConverter.CalculateDigitalCoincidenceTOF(c, ref cIJ);

                    int Ring1 = indexer.GetRing(c.Position1, cIJ.J1);
                    int Ring2 = indexer.GetRing(c.Position2, cIJ.J2);

                    var sinidx = Ring1 + Ring2;

                    if (sinidx >= numSins)
                    {
                        continue;
                    }

                    int Dir  = indexer.GetDir(c.Position1, c.Position2, cIJ.I1, cIJ.I2);
                    int Line = indexer.GetLine(c.Position1, c.Position2, cIJ.I1, cIJ.I2);

                    //if (isDebug && ++cnt % 1000 == 0)
                    //{
                    // gr.DrawLine(Pens.White, 410 * (float)Math.Cos(Math.PI * Detector1 / 360), 410 * (float)Math.Sin(Math.PI * Detector1 / 360),
                    // 410 * (float)Math.Cos(Math.PI * Detector2 / 360), 410 * (float)Math.Sin(Math.PI * Detector2 / 360));
                    //}
                    if (Line < 0)
                    {
                        continue;
                    }
                    sins[sinidx][Dir, Line]++;
                }
            }

            if (!Directory.Exists(outDir))
            {
                Directory.CreateDirectory(outDir);
            }

            for (int i = 0; i < numSins; i++)
            {
                Sinogram sino    = new Sinogram(sins[i], AnglesDistribution.Uniform(0, Math.PI, indexer.NumDirs));
                Stream   ostream = File.Create(string.Format("{0}\\{1}", outDir, string.Format("{0}.sg", i)));
                //using (StreamWriter w = new StreamWriter(ostream, Encoding.UTF8))
                using (ostream)
                {
                    Sinogram.SaveSinogramToStream(ostream, sino);
                }

                Sinogram.DumpSinogram(sins[i], string.Format("{0}\\{1}.png", outDir, i));
                //if (isDebug)
                // bmp.Save(string.Format("{0}\\lines.png", arg.OutDir));
            }
        }