Exemplo 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);
    }
Exemplo n.º 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);
    }
Exemplo n.º 3
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;
    }
Exemplo n.º 4
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;
    }
Exemplo n.º 5
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);
    }
Exemplo n.º 6
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;
    }