Click here to Skip to main content
14,934,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
I am compressing dicom images using GDCM Tool but image is not compressed properly. I am Posting the Sample Code.

What I have tried:

My code is as follow:
string inputFileNamepath = @"G:\Test\Test_07_06_2016\Source\CT-MONO2-16-ankle.dcm";
string outputFileNamepath = @"G:\Test\Test_07_06_2016\Source1\CT-MONO2-16-ankle.dcm";

//FileInfo file = new FileInfo(@"G:\Test\Test_07_06_2016\Source\BU001015MN-166-CL-001V01_2005101414120923_1_1.dcm");

string extension = Path.GetExtension(inputFileNamepath);
inputFileName = Path.GetFileName(inputFileNamepath);

outputFileName = Path.GetFileName(outputFileNamepath);

try
{
gdcm.ImageReader reader = new ImageReader();
reader.SetFileName(inputFileNamepath);
if (!reader.Read())
{
//System.Console.WriteLine("Could not read: " + filename);
MessageBox.Show("Error ");
return;
}


gdcm.File file = reader.GetFile();

gdcm.DataSet ds = file.GetDataSet();
gdcm.Image image = reader.GetImage();

ImageChangeTransferSyntax change = new ImageChangeTransferSyntax();
TransferSyntax targets = new TransferSyntax(TransferSyntax.TSType.JPEG2000Lossless);
change.SetTransferSyntax(targets);

JPEGCodec codec = new JPEGCodec();

if(!codec.CanCode(targets))
{
// MessageBox.Show("WrongData");
//return;
}
codec.SetLossless(false);
codec.SetQuality(90); // poor quality !
change.SetUserCodec(codec); // specify the codec to use to the ImageChangeTransferSyntax

change.SetInput(image);

bool b = change.Change();

if (!b)
{
MessageBox.Show("Can not change Ttansfer Syntax");
//return;
}

ImageWriter writer = new ImageWriter();
writer.SetImage((gdcm.Image)change.GetOutput());
writer.SetFile(reader.GetFile());
writer.SetFileName(outputFileNamepath);

if (!writer.Write())
{
MessageBox.Show("Could not write");
}




}
catch (Exception ex)
{

}
Posted
Updated 28-Jun-16 2:22am
Comments
Richard MacCutchan 28-Jun-16 6:07am
   
Please explain "image is not compressed properly".
dattaprasaddhuri 28-Jun-16 6:34am
   
after compressing the image only white color is display in the image area.
Richard MacCutchan 28-Jun-16 7:07am
   
You will probably need help from the people who wrote the GDCM tool.

1 solution

You're going to have to talk to the people who wrote the "GDCM tool" you're using. There doesn't appear to be a problem with the code you posted.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900