Пример #1
0
    public static int Main(string[] args)
    {
        string      file1  = args[0];
        string      file2  = args[1];
        ImageReader reader = new ImageReader();

        reader.SetFileName(file1);
        bool ret = reader.Read();

        if (!ret)
        {
            return(1);
        }

        Image image = new Image();
        Image ir    = reader.GetImage();

        image.SetNumberOfDimensions(ir.GetNumberOfDimensions());

        //Just for fun:
        //int dircos =  ir.GetDirectionCosines();
        //t = gdcm.Orientation.GetType(dircos);
        //int l = gdcm.Orientation.GetLabel(t);
        //System.Console.WriteLine( "Orientation label:" + l );

        // Set the dimensions,
        // 1. either one at a time
        //image.SetDimension(0, ir.GetDimension(0) );
        //image.SetDimension(1, ir.GetDimension(1) );

        // 2. the array at once
        uint[] dims = { 0, 0 };
        // Just for fun let's invert the dimensions:
        dims[0] = ir.GetDimension(1);
        dims[1] = ir.GetDimension(0);
        ir.SetDimensions(dims);

        PixelFormat pixeltype = ir.GetPixelFormat();

        image.SetPixelFormat(pixeltype);

        PhotometricInterpretation pi = ir.GetPhotometricInterpretation();

        image.SetPhotometricInterpretation(pi);

        DataElement pixeldata = new DataElement(new Tag(0x7fe0, 0x0010));

        byte[] str1 = new byte[ir.GetBufferLength()];
        ir.GetBuffer(str1);
        //System.Console.WriteLine( ir.GetBufferLength() );
        pixeldata.SetByteValue(str1, new VL((uint)str1.Length));
        //image.SetDataElement( pixeldata );
        ir.SetDataElement(pixeldata);


        ImageWriter writer = new ImageWriter();

        writer.SetFileName(file2);
        writer.SetFile(reader.GetFile());
        writer.SetImage(ir);
        ret = writer.Write();
        if (!ret)
        {
            return(1);
        }

        return(0);
    }
Пример #2
0
    public static int Main(string[] args)
    {
        if (args.Length < 2)
        {
            System.Console.WriteLine(" input.dcm output.dcm");
            return(1);
        }
        string filename    = args[0];
        string outfilename = args[1];

        ImageReader reader = new ImageReader();

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

        // The output of gdcm::Reader is a gdcm::File
        File file = reader.GetFile();

        // the dataset is the the set of element we are interested in:
        DataSet ds = file.GetDataSet();

        Image image = reader.GetImage();
        //image.Print( cout );

        ImageChangeTransferSyntax change   = new ImageChangeTransferSyntax();
        TransferSyntax            targetts = new TransferSyntax(TransferSyntax.TSType.JPEGBaselineProcess1);

        change.SetTransferSyntax(targetts);

        // Setup our JPEGCodec, warning it should be compatible with JPEGBaselineProcess1
        JPEGCodec jpegcodec = new JPEGCodec();

        if (!jpegcodec.CanCode(targetts))
        {
            System.Console.WriteLine("Something went really wrong, JPEGCodec cannot handle JPEGBaselineProcess1");
            return(1);
        }
        jpegcodec.SetLossless(false);
        jpegcodec.SetQuality(50);       // poor quality !
        change.SetUserCodec(jpegcodec); // specify the codec to use to the ImageChangeTransferSyntax

        change.SetInput(image);
        bool b = change.Change();

        if (!b)
        {
            System.Console.WriteLine("Could not change the Transfer Syntax");
            return(1);
        }

        ImageWriter writer = new ImageWriter();

        writer.SetImage((gdcm.Image)change.GetOutput());
        writer.SetFile(reader.GetFile());
        writer.SetFileName(outfilename);
        if (!writer.Write())
        {
            System.Console.WriteLine("Could not write: " + outfilename);
            return(1);
        }

        return(0);
    }
Пример #3
0
    public static int Main(string[] args)
    {
        string file1 = args[0];
        string file2 = args[1];
        ImageReader reader = new ImageReader();
        reader.SetFileName( file1 );
        bool ret = reader.Read();
        if( !ret )
          {
          return 1;
          }

        Image image = new Image();
        Image ir = reader.GetImage();

        image.SetNumberOfDimensions( ir.GetNumberOfDimensions() );

        //Just for fun:
        //int dircos =  ir.GetDirectionCosines();
        //t = gdcm.Orientation.GetType(dircos);
        //int l = gdcm.Orientation.GetLabel(t);
        //System.Console.WriteLine( "Orientation label:" + l );

        // Set the dimensions,
        // 1. either one at a time
        //image.SetDimension(0, ir.GetDimension(0) );
        //image.SetDimension(1, ir.GetDimension(1) );

        // 2. the array at once
        uint[] dims = {0, 0};
        // Just for fun let's invert the dimensions:
        dims[0] = ir.GetDimension(1);
        dims[1] = ir.GetDimension(0);
        ir.SetDimensions( dims );

        PixelFormat pixeltype = ir.GetPixelFormat();
        image.SetPixelFormat( pixeltype );

        PhotometricInterpretation pi = ir.GetPhotometricInterpretation();
        image.SetPhotometricInterpretation( pi );

        DataElement pixeldata = new DataElement( new Tag(0x7fe0,0x0010) );
        byte[] str1 = new byte[ ir.GetBufferLength()];
        ir.GetBuffer( str1 );
        //System.Console.WriteLine( ir.GetBufferLength() );
        pixeldata.SetByteValue( str1, new VL( (uint)str1.Length ) );
        //image.SetDataElement( pixeldata );
        ir.SetDataElement( pixeldata );

        ImageWriter writer = new ImageWriter();
        writer.SetFileName( file2 );
        writer.SetFile( reader.GetFile() );
        writer.SetImage( ir );
        ret = writer.Write();
        if( !ret )
          {
          return 1;
          }

        return 0;
    }
Пример #4
0
  public static int Main(string[] args)
    {
    string filename = args[0];

    // instanciate the reader:
    gdcm.ImageReader reader = new gdcm.ImageReader();
    reader.SetFileName( filename );

    if (!reader.Read()) return 1;

    Image ir = reader.GetImage();

    uint[] dims = {0, 0, 0};
    dims[0] = ir.GetDimension(0);
    dims[1] = ir.GetDimension(1);
    dims[2] = ir.GetDimension(2);
    System.Console.WriteLine( "Dim:" + dims[0] );
    System.Console.WriteLine( "Dim:" + dims[1] );
    System.Console.WriteLine( "Dim:" + dims[2] );

    // buffer to get the pixels
    byte[] buffer = new byte[ ir.GetBufferLength()];
    System.Console.WriteLine( "Dim:" + ir.GetBufferLength() );
    ir.GetBuffer( buffer );

    for (uint z = 0; z < dims[2]; z++)
      {
      for (uint y = 0; y < dims[1] / 2; y++) // only half Y
        {
        for (uint x = 0; x < dims[0] / 2; x++) // only half X
          {
          buffer[ (z * dims[1] + y) * dims[0] + x ] = 0; // works when pixel type == UINT8
          }
        }
      }

    DataElement pixeldata = new DataElement( new Tag(0x7fe0,0x0010) );
    pixeldata.SetByteValue( buffer, new VL( (uint)buffer.Length ) );
    ir.SetDataElement( pixeldata );
    ir.SetTransferSyntax( new TransferSyntax( TransferSyntax.TSType.ExplicitVRLittleEndian ) );

    ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();
    change.SetTransferSyntax( new TransferSyntax( TransferSyntax.TSType.JPEGLSLossless ) );
    change.SetInput( ir );
    if( !change.Change() )
      {
      System.Console.WriteLine( "Could not change: " + filename );
      return 1;
      }

    ImageWriter writer = new ImageWriter();
    writer.SetFileName( "out.dcm" );
    writer.SetFile( reader.GetFile() );
    writer.SetImage( change.GetOutput() );
    bool ret = writer.Write();
    if( !ret )
      {
      return 1;
      }


    return 0;
    }
Пример #5
0
    public static int Main(string[] args)
    {
        if( args.Length < 2 )
          {
          System.Console.WriteLine( " input.dcm output.dcm" );
          return 1;
          }
        string filename = args[0];
        string outfilename = args[1];

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

        // The output of gdcm::Reader is a gdcm::File
        File file = reader.GetFile();

        // the dataset is the the set of element we are interested in:
        DataSet ds = file.GetDataSet();

        Image image = reader.GetImage();
        //image.Print( cout );

        ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();
        TransferSyntax targetts =  new TransferSyntax( TransferSyntax.TSType.JPEGBaselineProcess1 );
        change.SetTransferSyntax( targetts );

        // Setup our JPEGCodec, warning it should be compatible with JPEGBaselineProcess1
        JPEGCodec jpegcodec = new JPEGCodec();
        if( !jpegcodec.CanCode( targetts ) )
          {
          System.Console.WriteLine( "Something went really wrong, JPEGCodec cannot handle JPEGBaselineProcess1" );
          return 1;
          }
        jpegcodec.SetLossless( false );
        jpegcodec.SetQuality( 50 ); // poor quality !
        change.SetUserCodec( jpegcodec ); // specify the codec to use to the ImageChangeTransferSyntax

        change.SetInput( image );
        bool b = change.Change();
        if( !b )
          {
          System.Console.WriteLine( "Could not change the Transfer Syntax" );
          return 1;
          }

        ImageWriter writer = new ImageWriter();
        writer.SetImage( change.GetOutput() );
        writer.SetFile( reader.GetFile() );
        writer.SetFileName( outfilename );
        if( !writer.Write() )
          {
          System.Console.WriteLine( "Could not write: " + outfilename );
          return 1;
          }

        return 0;
    }
Пример #6
0
    public static int Main(string[] args)
    {
        string filename = args[0];

        // instanciate the reader:
        gdcm.ImageReader reader = new gdcm.ImageReader();
        reader.SetFileName(filename);

        if (!reader.Read())
        {
            return(1);
        }

        Image ir = reader.GetImage();

        uint[] dims = { 0, 0, 0 };
        dims[0] = ir.GetDimension(0);
        dims[1] = ir.GetDimension(1);
        dims[2] = ir.GetDimension(2);
        System.Console.WriteLine("Dim:" + dims[0]);
        System.Console.WriteLine("Dim:" + dims[1]);
        System.Console.WriteLine("Dim:" + dims[2]);

        // buffer to get the pixels
        byte[] buffer = new byte[ir.GetBufferLength()];
        System.Console.WriteLine("Dim:" + ir.GetBufferLength());
        ir.GetBuffer(buffer);

        for (uint z = 0; z < dims[2]; z++)
        {
            for (uint y = 0; y < dims[1] / 2; y++)               // only half Y
            {
                for (uint x = 0; x < dims[0] / 2; x++)           // only half X
                {
                    buffer[(z * dims[1] + y) * dims[0] + x] = 0; // works when pixel type == UINT8
                }
            }
        }

        DataElement pixeldata = new DataElement(new Tag(0x7fe0, 0x0010));

        pixeldata.SetByteValue(buffer, new VL((uint)buffer.Length));
        ir.SetDataElement(pixeldata);
        ir.SetTransferSyntax(new TransferSyntax(TransferSyntax.TSType.ExplicitVRLittleEndian));

        ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();

        change.SetTransferSyntax(new TransferSyntax(TransferSyntax.TSType.JPEGLSLossless));
        change.SetInput(ir);
        if (!change.Change())
        {
            System.Console.WriteLine("Could not change: " + filename);
            return(1);
        }

        ImageWriter writer = new ImageWriter();

        writer.SetFileName("out.dcm");
        writer.SetFile(reader.GetFile());
        writer.SetImage(change.GetOutput());
        bool ret = writer.Write();

        if (!ret)
        {
            return(1);
        }


        return(0);
    }