示例#1
0
    public static int Main(string[] args)
    {
        string filename = args[0];

        // instantiate the reader:
        gdcm.ImageRegionReader reader = new gdcm.ImageRegionReader();
        reader.SetFileName(filename);

        // pull DICOM info:
        if (!reader.ReadInformation())
        {
            return(1);
        }
        // Get file infos
        gdcm.File f = reader.GetFile();

        // get some info about image
        UIntArrayType dims      = ImageHelper.GetDimensionsValue(f);
        PixelFormat   pf        = ImageHelper.GetPixelFormatValue(f);
        int           pixelsize = pf.GetPixelSize();

        // buffer to get the pixels
        byte[] buffer = new byte[dims[0] * dims[1] * pixelsize];

        // define a simple box region.
        BoxRegion box = new BoxRegion();

        for (uint z = 0; z < dims[2]; z++)
        {
            // Define that I want the image 0, full size (dimx x dimy pixels)
            // and do that for each z:
            box.SetDomain(0, dims[0] - 1, 0, dims[1] - 1, z, z);
            //System.Console.WriteLine( box.toString() );
            reader.SetRegion(box);

            // reader will try to load the uncompressed image region into buffer.
            // the call returns an error when buffer.Length is too small. For instance
            // one can call:
            // uint buf_len = reader.ComputeBufferLength(); // take into account pixel size
            // to get the exact size of minimum buffer
            if (reader.ReadIntoBuffer(buffer, (uint)buffer.Length))
            {
                using (System.IO.Stream stream =
                           System.IO.File.Open(@"/tmp/frame.raw",
                                               System.IO.FileMode.Create))
                {
                    System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
                    writer.Write(buffer);
                }
            }
            else
            {
                throw new Exception("can't read pixels error");
            }
        }

        return(0);
    }
示例#2
0
    public static int Main(string[] args)
    {
        string filename = args[0];

        // instantiate the reader:
        gdcm.ImageRegionReader reader = new gdcm.ImageRegionReader();
        reader.SetFileName( filename );

        // pull DICOM info:
        if (!reader.ReadInformation()) return 1;
        // Get file infos
        gdcm.File f = reader.GetFile();

        // get some info about image
        UIntArrayType dims = ImageHelper.GetDimensionsValue(f);
        PixelFormat pf = ImageHelper.GetPixelFormatValue (f);
        int pixelsize = pf.GetPixelSize();
        PhotometricInterpretation pi = ImageHelper.GetPhotometricInterpretationValue(f);
        Console.WriteLine( pi.toString() );

        // buffer to get the pixels
        byte[] buffer = new byte[ dims[0] * dims[1] * pixelsize ];

        // define a simple box region.
        BoxRegion box = new BoxRegion();
        for (uint z = 0; z < dims[2]; z++)
          {
          // Define that I want the image 0, full size (dimx x dimy pixels)
          // and do that for each z:
          box.SetDomain(0, dims[0] - 1, 0, dims[1] - 1, z, z);
          //System.Console.WriteLine( box.toString() );
          reader.SetRegion( box );

          // reader will try to load the uncompressed image region into buffer.
          // the call returns an error when buffer.Length is too small. For instance
          // one can call:
          // uint buf_len = reader.ComputeBufferLength(); // take into account pixel size
          // to get the exact size of minimum buffer
          if (reader.ReadIntoBuffer(buffer, (uint)buffer.Length))
        {
        using (System.IO.Stream stream =
          System.IO.File.Open(@"/tmp/frame.raw",
            System.IO.FileMode.Create))
          {
          System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
          writer.Write(buffer);
          }
        }
          else
        {
        throw new Exception("can't read pixels error");
        }
          }

        return 0;
    }