Beispiel #1
0
 /**Returns the unsorted files list in the given directory. This list is not filtered
  * (that means that the list may have non-dicom files) nor sorted.*/
 private gdcm.FilenamesType GetUnsortedFilenameList(string path)
 {
     gdcm.Directory dir = new gdcm.Directory();
     dir.Load(path);
     gdcm.FilenamesType unsortedFiles = dir.GetFilenames();
     return(unsortedFiles);
 }
Beispiel #2
0
        public bool Store(string path)
        {
            gdcm.FilenamesType pliki = new gdcm.FilenamesType();
            pliki.Add(path);
            bool stan = gdcm.CompositeNetworkFunctions.CStore(ip, port, pliki, aet, call);

            return(stan);
        }
Beispiel #3
0
 private gdcm.FilenamesType GetFilteredFiles(string path, Func <float, string, float> progressCallback)
 {
     gdcm.FilenamesType unsortedFiles = GetUnsortedFilenameList(path);
     progressCallback(0.01f, "Aquired file list.");
     gdcm.Scanner       scanner       = PrepareFileScanner();
     gdcm.FilenamesType filteredFiles = ScanFiles(scanner, unsortedFiles);
     progressCallback(0.05f, "Filtered files.");
     return(filteredFiles);
 }
Beispiel #4
0
    /// <summary>
    /// Scan the given directory with the given scanner returning the only the files that
    /// have the tags on the given scanner.
    /// </summary>
    /// <param name="scanner">The scanner with the tags</param>
    /// <param name="directory">The directory to be scanned</param>
    /// <returns>The file list without the files that don't have the tags.</returns>
    gdcm.FilenamesType ScanFiles(gdcm.Scanner scanner, gdcm.FilenamesType directory)
    {
        bool b = scanner.Scan(directory);

        if (!b)
        {
            throw new FileScanException(directory.First());
        }
        return(scanner.GetKeys());
    }
Beispiel #5
0
    List <PathAndData> SortFilenames(gdcm.FilenamesType files, Func <float, string, float> progressCallback)
    {
        var currentFileCount     = 0;
        List <PathAndData> paths = files.Select(currFilePath =>
        {
            gdcm.DataSet ds1 = GetDatasetFromFile(currFilePath);
            float percentage = (float)currentFileCount / (float)files.Count();
            progressCallback(percentage, currFilePath);
            Thread.Yield();
            string p1Name                  = GetPatientName(ds1);
            string p1Study                 = GetStudyUid(ds1);
            string p1Series                = GetSeriesUid(ds1);
            float[] p1Position             = GetImagePosition(ds1);
            float[] image1OrientationPlane = GetDirectionCosines(ds1);
            var pd = new PathAndData()
            {
                path = currFilePath, patient = p1Name, study = p1Study, series = p1Series, orientationPlane = image1OrientationPlane, position = p1Position
            };
            currentFileCount++;
            return(pd);
        }).ToList <PathAndData>();

        paths.Sort((PathAndData file1, PathAndData file2) =>
        {
            int nameComparison   = file1.patient.CompareTo(file2.patient);
            int studyComparison  = file1.study.CompareTo(file2.study);
            int seriesComparison = file1.series.CompareTo(file2.series);

            var image1OrientationPlane = file1.orientationPlane;
            var p1Position             = file1.position;
            var p2Position             = file2.position;
            double[] normal            = new double[3];
            normal[0]    = image1OrientationPlane[1] * image1OrientationPlane[5] - image1OrientationPlane[2] * image1OrientationPlane[4];
            normal[1]    = image1OrientationPlane[2] * image1OrientationPlane[3] - image1OrientationPlane[0] * image1OrientationPlane[5];
            normal[2]    = image1OrientationPlane[0] * image1OrientationPlane[4] - image1OrientationPlane[1] * image1OrientationPlane[3];
            double dist1 = 0;
            for (var i = 0; i < 3; ++i)
            {
                dist1 += normal[i] * p1Position[i];
            }
            double dist2 = 0;
            for (var i = 0; i < 3; ++i)
            {
                dist2 += normal[i] * p2Position[i];
            }
            int imagePositionComparison = dist1.CompareTo(dist2);

            if (nameComparison != 0)
            {
                return(nameComparison);                    //Se o nome é diferente retorna a comparacao do nome
            }
            if (studyComparison != 0)
            {
                return(studyComparison);                     //Se o nome é igual e o estudo é diferente retorna a comparação do estudo
            }
            if (seriesComparison != 0)
            {
                return(seriesComparison);                      //Se o nome e o estudo são iguais e a serie é diferente retorna a comparacao da serie.
            }
            //Se o nome, estudo e série são iguais retorna a comparação da image position
            return(imagePositionComparison);
        });
        return(paths);
    }
    public static int Main(string[] args)
    {
        string directory = args[0];

        gdcm.Directory dir    = new gdcm.Directory();
        uint           nfiles = dir.Load(directory);

        //System.Console.WriteLine(dir.toString());
        gdcm.FilenamesType filenames = dir.GetFilenames();

        Image image = new Image();

        image.SetNumberOfDimensions(3); // important for now
        DataElement pixeldata = new DataElement(new gdcm.Tag(0x7fe0, 0x0010));

        // Create a new SequenceOfFragments C++ object, store it as a SmartPointer :
        SmartPtrFrag sq = SequenceOfFragments.New();

        // Yeah, the file are not garantee to be in order, please adapt...
        for (uint i = 0; i < nfiles; ++i)
        {
            System.Console.WriteLine(filenames[(int)i]);
            string file = filenames[(int)i];
            System.IO.FileStream infile =
                new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read);
            uint fsize = gdcm.PosixEmulation.FileSize(file);

            byte[] jstream = new byte[fsize];
            infile.Read(jstream, 0, jstream.Length);

            Fragment frag = new Fragment();
            frag.SetByteValue(jstream, new gdcm.VL((uint)jstream.Length));
            sq.AddFragment(frag);
        }

        // Pass by reference:
        pixeldata.SetValue(sq.__ref__());

        // insert:
        image.SetDataElement(pixeldata);

        // JPEG use YBR to achieve better compression ratio by default (not RGB)
        // FIXME hardcoded:
        PhotometricInterpretation pi = new PhotometricInterpretation(PhotometricInterpretation.PIType.MONOCHROME2);

        image.SetPhotometricInterpretation(pi);
        // FIXME hardcoded:
        PixelFormat pixeltype = new PixelFormat(1, 8, 8, 7);

        image.SetPixelFormat(pixeltype);

        // FIXME hardcoded:
        image.SetTransferSyntax(new TransferSyntax(TransferSyntax.TSType.JPEGLosslessProcess14_1));
        image.SetDimension(0, 512);
        image.SetDimension(1, 512);
        image.SetDimension(2, 355);

        // Decompress !
        byte[] decompressedData = new byte[(int)image.GetBufferLength()];
        image.GetBuffer(decompressedData);

        // Write out the decompressed bytes
        System.Console.WriteLine(image.toString());
        using (System.IO.Stream stream =
                   System.IO.File.Open(@"/tmp/dd.raw",
                                       System.IO.FileMode.Create))
        {
            System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
            writer.Write(decompressedData);
        }


        return(0);
    }