static int Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("This program prints the patient name of a dicom file with gdcm");
                Console.WriteLine("Usage: [input.dcm]");
                return(1);
            }

            gdcm.Reader reader = new gdcm.Reader();
            reader.SetFileName(args[0]);
            bool ret = reader.Read();

            //TagSetType tst = new TagSetType();
            //tst.Add( new Tag(0x7fe0,0x10) );
            //bool ret = reader.ReadUpToTag( new Tag(0x88,0x200), tst );
            if (!ret)
            {
                return(1);
            }

            gdcm.File file = reader.GetFile();

            gdcm.StringFilter filter = new gdcm.StringFilter();
            filter.SetFile(file);
            string value = filter.ToString(new gdcm.Tag(0x0010, 0x0010));

            Console.WriteLine("Patient Name: " + value);
            return(0);
        }
    static int Main(string[] args)
      {
      if (args.Length != 1)
        {
        Console.WriteLine("This program prints the patient name of a dicom file with gdcm");
        Console.WriteLine("Usage: [input.dcm]");
        return 1;
        }

      gdcm.Reader reader = new gdcm.Reader();
      reader.SetFileName(args[0]);
      bool ret = reader.Read();
      //TagSetType tst = new TagSetType();
      //tst.Add( new Tag(0x7fe0,0x10) );
      //bool ret = reader.ReadUpToTag( new Tag(0x88,0x200), tst );
      if( !ret )
        {
        return 1;
        }

      gdcm.File file = reader.GetFile();

      gdcm.StringFilter filter = new gdcm.StringFilter();
      filter.SetFile(file);
      string value = filter.ToString(new gdcm.Tag(0x0010, 0x0010));

      Console.WriteLine("Patient Name: " + value);
      return 0;
      }
Esempio n. 3
0
    public static int Main(string[] args)
    {
        string filename = args[0];

        gdcm.Reader reader = new gdcm.Reader();
        reader.SetFileName(filename);
        if (!reader.Read())
        {
            return(1);
        }

        gdcm.File    f  = reader.GetFile();
        gdcm.DataSet ds = f.GetDataSet();

        string[] expectedSiemensTags = new string[] { "B_value", "AcquisitionMatrixText" };
        using (PrivateTag gtag = CSAHeader.GetCSAImageHeaderInfoTag())
        {
            if (ds.FindDataElement(gtag))
            {
                using (DataElement de = ds.GetDataElement(gtag))
                {
                    if (de != null && !de.IsEmpty())
                    {
                        using (CSAHeader csa = new CSAHeader())
                        {
                            if (csa.LoadFromDataElement(de))
                            {
                                foreach (string str in expectedSiemensTags)
                                {
                                    if (csa.FindCSAElementByName(str))
                                    {
                                        using (CSAElement elem = csa.GetCSAElementByName(str))
                                        {
                                            if (elem != null)
                                            {
                                                System.Console.WriteLine(elem.toString());
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }


        return(0);
    }
Esempio n. 4
0
    public static int Main(string[] args)
    {
        string filename = args[0];

        gdcm.Reader reader = new gdcm.Reader();
        reader.SetFileName( filename );
        if (!reader.Read()) return 1;

        gdcm.File f = reader.GetFile();
        gdcm.DataSet ds = f.GetDataSet();

        string[] expectedSiemensTags = new string[] { "B_value" , "AcquisitionMatrixText" };
        using (PrivateTag gtag = CSAHeader.GetCSAImageHeaderInfoTag())
        {
        if (ds.FindDataElement(gtag))
        {
            using (DataElement de = ds.GetDataElement(gtag))
            {
                if (de != null && !de.IsEmpty())
                {
                    using (CSAHeader csa = new CSAHeader())
                    {
                        if (csa.LoadFromDataElement(de))
                        {
                            foreach (string str in expectedSiemensTags)
                            {
                                if (csa.FindCSAElementByName(str))
                                {
                                    using (CSAElement elem = csa.GetCSAElementByName(str))
                                    {
                                        if (elem != null)
                                        {
                                            System.Console.WriteLine( elem.toString() );
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        }

        return 0;
    }
Esempio n. 5
0
        private void FramesQuery(string PatientId)
        {
            gdcm.ERootType typ = gdcm.ERootType.ePatientRootType;

            gdcm.EQueryLevel poziom = gdcm.EQueryLevel.ePatient; // zobacz inne

            gdcm.KeyValuePairArrayType klucze = new gdcm.KeyValuePairArrayType();
            gdcm.KeyValuePairType      klucz1 = new gdcm.KeyValuePairType(new gdcm.Tag(0x0010, 0x0020), PatientId); // NIE WOLNO TU STOSOWAC *; tutaj PatientID="01"
            klucze.Add(klucz1);

            // skonstruuj zapytanie
            gdcm.BaseRootQuery zapytanie = gdcm.CompositeNetworkFunctions.ConstructQuery(typ, poziom, klucze, true);

            // sprawdź, czy zapytanie spełnia kryteria
            if (!zapytanie.ValidateQuery())
            {
                MessageBox.Show("Wrong frames query.", "Error");
            }

            // przygotuj katalog na wyniki
            String odebrane = System.IO.Path.Combine(".", "temporary");

            if (!System.IO.Directory.Exists(odebrane))
            {
                System.IO.Directory.CreateDirectory(odebrane);
            }

            dane = System.IO.Path.Combine(odebrane, System.IO.Path.GetRandomFileName());  //katalog
            System.IO.Directory.CreateDirectory(dane);

            // wykonaj zapytanie - pobierz do katalogu _dane_
            bool stan = gdcm.CompositeNetworkFunctions.CMove(ip, port, zapytanie, port, aet, call, dane);

            // sprawdź stan
            if (!stan)
            {
                MessageBox.Show("PACS server doesn't work.", "Error");
            }
            // skasowanie listy zdjęć
            Images.Clear();
            ImageNames.Clear();
            Datas.Clear();
            List <string> pliki = new List <string>(System.IO.Directory.EnumerateFiles(dane));  //nazwy plikow

            foreach (String plik in pliki)
            {
                gdcm.Reader dataReader = new gdcm.Reader();
                dataReader.SetFileName(plik);

                if (!dataReader.Read())
                {
                    continue;
                }
                gdcm.File    file      = dataReader.GetFile();
                gdcm.DataSet dataSet   = file.GetDataSet();
                string       data      = dataSet.toString();
                gdcm.Global  g         = gdcm.Global.GetInstance();
                gdcm.Dicts   dicts     = g.GetDicts();
                gdcm.Dict    dict      = dicts.GetPublicDict();
                string[]     dataArray = dataSet.toString().Split('\n');
                Dictionary <string, string> dataValues = new Dictionary <string, string>();
                String[] id = plik.Split('\\');

                foreach (string s in dataArray)
                {
                    string[] dataArrayRow = s.Split('\t');
                    if (dataArrayRow.Length > 1)
                    {
                        string[] tags = dataArrayRow[0].Remove(0, 1).Remove(dataArrayRow[0].Length - 2, 1).Split(',');

                        //Pobranie nazwy Tagu
                        //gdcm.Tag tag = new gdcm.Tag(Convert.ToUInt16(tags[0]),Convert.ToUInt16(tags[1]));
                        //string dictDorTag = dict.GetKeywordFromTag(tag);
                        //if (dictDorTag != null)
                        //   dataValues.Add(dictDorTag, dataArrayRow[dataArrayRow.Length - 1]);

                        dataValues.Add(dataArrayRow[0], dataArrayRow[dataArrayRow.Length - 1]);
                    }
                }

                // przeczytaj pixele
                gdcm.PixmapReader reader = new gdcm.PixmapReader();
                reader.SetFileName(plik);
                if (!reader.Read())
                {
                    continue;
                }


                // przekonwertuj na "znany format"
                gdcm.Bitmap bmjpeg2000 = PACS.ImageConverter.pxmap2jpeg2000(reader.GetPixmap());
                // przekonwertuj na .NET bitmapy
                System.Drawing.Bitmap[] X = PACS.ImageConverter.gdcmBitmap2Bitmap(bmjpeg2000);

                // zapisz
                for (int i = 0; i < X.Length; i++)
                {
                    String name = "";
                    if (X.Length > 1)
                    {
                        name = String.Format("{0}_slice{1}.jpg", plik, i);
                        Images.Add(String.Format("{0}_slice{1}", id[id.Length - 1], i), X[i]);
                        ImageNames.Add(String.Format("{0}_slice{1}", id[id.Length - 1], i));
                        Datas.Add(String.Format("{0}_slice{1}", id[id.Length - 1], i), dataValues);
                    }
                    else
                    {
                        name = String.Format("{0}.jpg", plik);
                        Images.Add(String.Format("{0}", id[id.Length - 1]), X[i]);
                        ImageNames.Add(String.Format("{0}", id[id.Length - 1]));
                        Datas.Add(String.Format("{0}", id[id.Length - 1]), dataValues);
                    }

                    X[i].Save(name);
                }
            }
        }
Esempio n. 6
0
 gdcm.DataSet GetDatasetFromFile(string path)
 {
     gdcm.Reader reader = CreateReader(path);
     gdcm.File   file   = reader.GetFile();
     return(file.GetDataSet());
 }
Esempio n. 7
0
        private void FramesQuery(string PatientId, out string dane, out string name, out Dictionary <string, Dictionary <string, string> > Datas, out string segmentation_name)
        {
            gdcm.ERootType typ = gdcm.ERootType.ePatientRootType;

            gdcm.EQueryLevel poziom = gdcm.EQueryLevel.ePatient; // zobacz inne

            gdcm.KeyValuePairArrayType klucze = new gdcm.KeyValuePairArrayType();
            gdcm.KeyValuePairType      klucz1 = new gdcm.KeyValuePairType(new gdcm.Tag(0x0010, 0x0020), PatientId); // NIE WOLNO TU STOSOWAC *; tutaj PatientID="01"
            klucze.Add(klucz1);

            // skonstruuj zapytanie
            gdcm.BaseRootQuery zapytanie = gdcm.CompositeNetworkFunctions.ConstructQuery(typ, poziom, klucze, true);

            // sprawdź, czy zapytanie spełnia kryteria
            if (!zapytanie.ValidateQuery())
            {
                MessageBox.Show("Wrong frames query.", "Error");
            }

            // przygotuj katalog na wyniki
            String odebrane = System.IO.Path.Combine(".", "temporary");

            if (!System.IO.Directory.Exists(odebrane))
            {
                System.IO.Directory.CreateDirectory(odebrane);
            }

            dane = System.IO.Path.Combine(odebrane, System.IO.Path.GetRandomFileName());  //katalog
            System.IO.Directory.CreateDirectory(dane);

            // wykonaj zapytanie - pobierz do katalogu _dane_
            bool stan = gdcm.CompositeNetworkFunctions.CMove(ip, port, zapytanie, 10104, aet, call, dane);

            // sprawdź stan
            if (!stan)
            {
                MessageBox.Show("PACS server doesn't work.", "Error");
            }
            // skasowanie listy zdjęć
            name = "";
            segmentation_name = "";
            Datas             = new Dictionary <string, Dictionary <string, string> >();

            List <string> pliki = new List <string>(System.IO.Directory.EnumerateFiles(dane));  //nazwy plikow

            //OBRAZ ORYGINALNY
            gdcm.Reader dataReader = new gdcm.Reader();
            dataReader.SetFileName(pliki[0]);

            if (!dataReader.Read())
            {
            }

            gdcm.File    file    = dataReader.GetFile();
            gdcm.DataSet dataSet = file.GetDataSet();
            string       data    = dataSet.toString();

            gdcm.Global g         = gdcm.Global.GetInstance();
            gdcm.Dicts  dicts     = g.GetDicts();
            gdcm.Dict   dict      = dicts.GetPublicDict();
            string[]    dataArray = dataSet.toString().Split('\n');
            Dictionary <string, string> dataValues = new Dictionary <string, string>();

            String[] id = pliki[0].Split('\\');

            bool first_exp      = true;
            bool first_original = true;

            foreach (string plik in pliki)
            {
                dataValues.Clear();
                foreach (string s in dataArray)
                {
                    string[] dataArrayRow = s.Split('\t');
                    if (dataArrayRow.Length > 1)
                    {
                        string[] tags = dataArrayRow[0].Remove(0, 1).Remove(dataArrayRow[0].Length - 2, 1).Split(',');

                        //Pobranie nazwy Tagu
                        //gdcm.Tag tag = new gdcm.Tag(Convert.ToUInt16(tags[0]),Convert.ToUInt16(tags[1]));
                        //string dictDorTag = dict.GetKeywordFromTag(tag);
                        //if (dictDorTag != null)
                        //   dataValues.Add(dictDorTag, dataArrayRow[dataArrayRow.Length - 1]);

                        dataValues.Add(dataArrayRow[0], dataArrayRow[dataArrayRow.Length - 1]);
                    }
                }
                if (dataValues.Count > 0)
                {
                    if (dataValues["(0020,000d)"].Substring(0, 1) == "E" && first_exp == true)
                    {//OBRAZ SEGMENTACJI
                        gdcm.Reader dataReader2 = new gdcm.Reader();
                        dataReader2.SetFileName(plik);

                        if (!dataReader2.Read())
                        {
                        }

                        gdcm.File file2 = dataReader2.GetFile();

                        // przeczytaj pixele
                        gdcm.PixmapReader reader2 = new gdcm.PixmapReader();
                        string            temp    = plik;
                        if (plik.Substring(plik.Length - 4, 4) != ".dcm")
                        {
                            temp = pliki[1] + ".dcm";
                        }

                        reader2.SetFileName(plik);
                        if (!reader2.Read())
                        {
                        }

                        segmentation_name = String.Format("{0}", plik.Substring(0, plik.Length - 4));
                        first_exp         = false;
                    }
                    else
                    {
                        if (first_original == true)
                        {
                            // przeczytaj pixele
                            gdcm.PixmapReader reader = new gdcm.PixmapReader();
                            string            temp   = plik;
                            if (plik.Substring(plik.Length - 4, 4) != ".dcm")
                            {
                                temp = plik + ".dcm";
                            }
                            reader.SetFileName(plik);
                            if (!reader.Read())
                            {
                            }
                            name = String.Format("{0}", plik.Substring(0, plik.Length - 4));
                            Datas.Add(String.Format("{0}", plik.Substring(0, plik.Length - 4)).Replace("\\", "\\\\"), dataValues);
                            first_original = false;
                        }
                        else
                        {
                            gdcm.Reader dataReader2 = new gdcm.Reader();
                            dataReader2.SetFileName(plik);

                            if (!dataReader2.Read())
                            {
                            }

                            gdcm.File file2 = dataReader2.GetFile();

                            // przeczytaj pixele
                            gdcm.PixmapReader reader2 = new gdcm.PixmapReader();
                            string            temp    = plik;
                            if (plik.Substring(plik.Length - 4, 4) != ".dcm")
                            {
                                temp = pliki[1] + ".dcm";
                            }

                            reader2.SetFileName(plik);
                            if (!reader2.Read())
                            {
                            }

                            segmentation_name = String.Format("{0}", plik.Substring(0, plik.Length - 4));
                            first_exp         = false;
                        }
                    }
                }
            }
        }