Esempio n. 1
0
    public static bool ProcessOneFile(string filename, string outfilename)
    {
        PixmapReader reader = new PixmapReader();

        reader.SetFileName(filename);
        if (!reader.Read())
        {
            System.Console.WriteLine("Could not read: " + filename);
            return(false);
        }

        ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();

        change.SetForce(false);             // do we really want to recompress when input is alread compressed in same alg ?
        change.SetCompressIconImage(false); // Keep it simple
        change.SetTransferSyntax(new TransferSyntax(TransferSyntax.TSType.JPEG2000Lossless));
        change.SetInput(reader.GetPixmap());
        if (!change.Change())
        {
            System.Console.WriteLine("Could not change: " + filename);
            return(false);
        }

        gdcm.FileMetaInformation fmi = reader.GetFile().GetHeader();
        // The following three lines make sure to regenerate any value:
        fmi.Remove(new gdcm.Tag(0x0002, 0x0012));
        fmi.Remove(new gdcm.Tag(0x0002, 0x0013));
        fmi.Remove(new gdcm.Tag(0x0002, 0x0016));

        PixmapWriter writer = new PixmapWriter();

        writer.SetFileName(outfilename);
        writer.SetFile(reader.GetFile());
        gdcm.Bitmap bitout = change.GetOutput();
        gdcm.Pixmap pixout = (gdcm.Pixmap)bitout;
        //System.Console.WriteLine( "Debug: " + pixout.toString() );

        writer.SetPixmap(pixout);
        if (!writer.Write())
        {
            System.Console.WriteLine("Could not write: " + outfilename);
            return(false);
        }

        return(true);
    }
Esempio n. 2
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);
                }
            }
        }