convert jpg to dicom c++

All other questions regarding DCMTK

Moderator: Moderator Team

Message
Author
MuhammadHemdan
Posts: 46
Joined: Sun, 2012-02-26, 15:12
Location: Egypt

convert JPEG to DICOM

#31 Post by MuhammadHemdan »

J. Riesmeier wrote:Where do you define "dataset"? Its value should be the pointer returned by dcmff.getDataset().

Btw, the color space conversion flags are also available to dcmj2pnm ...

Code: Select all

color space conversion (compressed images only):

  +cp   --conv-photometric
          convert if YCbCr photometric interpretation (default)

  +cl   --conv-lossy
          convert YCbCr to RGB if lossy JPEG

  +cg   --conv-guess
          convert to RGB if YCbCr is guessed by library

  +cgl  --conv-guess-lossy
          convert to RGB if lossy JPEG and YCbCr is
          guessed by the underlying JPEG library

  +ca   --conv-always
          always convert YCbCr to RGB

  +cn   --conv-never
          never convert color space

This is my code to convert jpeg to dicom and where i get the dataset:

Image2Dcm i2d;
I2DOutputPlug *outPlug = new I2DOutputPlugSC();
I2DImgSource *inputPlug = new I2DJpegSource();
E_TransferSyntax writeXfer;
inputPlug->setImageFile(jpgFile);
DcmDataset *dataset = NULL;
OFCondition result = i2d.convert(inputPlug, outPlug, dataset, writeXfer);

// Saving output DICOM image
if (result.good())
{
dataset->putAndInsertString(DCM_PhotometricInterpretation,"RGB");

DcmFileFormat dcmff(dataset);
result = dcmff.saveFile(dcmFile, writeXfer);
}

//then the decompression code here

MuhammadHemdan
Posts: 46
Joined: Sun, 2012-02-26, 15:12
Location: Egypt

Re: convert JPEG to DICOM

#32 Post by MuhammadHemdan »

MuhammadHemdan wrote:
J. Riesmeier wrote:Where do you define "dataset"? Its value should be the pointer returned by dcmff.getDataset().

Btw, the color space conversion flags are also available to dcmj2pnm ...

Code: Select all

color space conversion (compressed images only):

  +cp   --conv-photometric
          convert if YCbCr photometric interpretation (default)

  +cl   --conv-lossy
          convert YCbCr to RGB if lossy JPEG

  +cg   --conv-guess
          convert to RGB if YCbCr is guessed by library

  +cgl  --conv-guess-lossy
          convert to RGB if lossy JPEG and YCbCr is
          guessed by the underlying JPEG library

  +ca   --conv-always
          always convert YCbCr to RGB

  +cn   --conv-never
          never convert color space

This is my code to convert jpeg to dicom and where i get the dataset:

Image2Dcm i2d;
I2DOutputPlug *outPlug = new I2DOutputPlugSC();
I2DImgSource *inputPlug = new I2DJpegSource();
E_TransferSyntax writeXfer;
inputPlug->setImageFile(jpgFile);
DcmDataset *dataset = NULL;
OFCondition result = i2d.convert(inputPlug, outPlug, dataset, writeXfer);

// Saving output DICOM image
if (result.good())
{
dataset->putAndInsertString(DCM_PhotometricInterpretation,"RGB");

DcmFileFormat dcmff(dataset);
result = dcmff.saveFile(dcmFile, writeXfer);
}

//then the decompression code here

I add the line of dataset and it is ok now. I can now view the DICOM image on any viewer. Thank you so much.

MuhammadHemdan
Posts: 46
Joined: Sun, 2012-02-26, 15:12
Location: Egypt

Re: convert JPEG to DICOM

#33 Post by MuhammadHemdan »

MuhammadHemdan wrote:
MuhammadHemdan wrote:
J. Riesmeier wrote:Where do you define "dataset"? Its value should be the pointer returned by dcmff.getDataset().

Btw, the color space conversion flags are also available to dcmj2pnm ...

Code: Select all

color space conversion (compressed images only):

  +cp   --conv-photometric
          convert if YCbCr photometric interpretation (default)

  +cl   --conv-lossy
          convert YCbCr to RGB if lossy JPEG

  +cg   --conv-guess
          convert to RGB if YCbCr is guessed by library

  +cgl  --conv-guess-lossy
          convert to RGB if lossy JPEG and YCbCr is
          guessed by the underlying JPEG library

  +ca   --conv-always
          always convert YCbCr to RGB

  +cn   --conv-never
          never convert color space

This is my code to convert jpeg to dicom and where i get the dataset:

Image2Dcm i2d;
I2DOutputPlug *outPlug = new I2DOutputPlugSC();
I2DImgSource *inputPlug = new I2DJpegSource();
E_TransferSyntax writeXfer;
inputPlug->setImageFile(jpgFile);
DcmDataset *dataset = NULL;
OFCondition result = i2d.convert(inputPlug, outPlug, dataset, writeXfer);

// Saving output DICOM image
if (result.good())
{
dataset->putAndInsertString(DCM_PhotometricInterpretation,"RGB");

DcmFileFormat dcmff(dataset);
result = dcmff.saveFile(dcmFile, writeXfer);
}

//then the decompression code here

I add the line of dataset and it is ok now. I can now view the DICOM image on any viewer. Thank you so much.

According to transmit the DICOM image:
I can transmit the decompressed one. But I can't transmit the DICOM image without decompression. The error message tells me " unable to convert dataset from 'JPEG Baseline' transfer syntax to 'Little Endian Explicit' ". I doupt in the "writeXfer" in the previous code.

J. Riesmeier
DCMTK Developer
Posts: 2501
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

#34 Post by J. Riesmeier »

This is an easy one (in fact, you could find the answer yourself by using the "Search" function of this forum system): If you are using storescu and storescp, you have to tell them to propose and accept the JPEG lossy transfer syntax.
This error can also be avoided on the sender side by using dcmsend instead of storescu, and on the receiver side by using the storescp option --accept-all.

MuhammadHemdan
Posts: 46
Joined: Sun, 2012-02-26, 15:12
Location: Egypt

#35 Post by MuhammadHemdan »

J. Riesmeier wrote:This is an easy one (in fact, you could find the answer yourself by using the "Search" function of this forum system): If you are using storescu and storescp, you have to tell them to propose and accept the JPEG lossy transfer syntax.
This error can also be avoided on the sender side by using dcmsend instead of storescu, and on the receiver side by using the storescp option --accept-all.
I'm using sendSTORERequest() function to transmit dicom file. how can I set --propose-jpeg8 in my code?

omarelgazzar
Posts: 101
Joined: Wed, 2009-07-08, 16:06
Location: Oldenburg, Germany

#36 Post by omarelgazzar »

This is achieved by the function DCMSCU::addPresentationContext() and proposing the jpeg8 transfer syntax in one of the transfer syntaxes of the presentation context. Look at dcmsend as an example in the last DCMTK snapshot.

MuhammadHemdan
Posts: 46
Joined: Sun, 2012-02-26, 15:12
Location: Egypt

#37 Post by MuhammadHemdan »

omarelgazzar wrote:This is achieved by the function DCMSCU::addPresentationContext() and proposing the jpeg8 transfer syntax in one of the transfer syntaxes of the presentation context. Look at dcmsend as an example in the last DCMTK snapshot.

This my code where i can propose the jpeg8?


OFList<OFString> ts;
ts.push_back(UID_LittleEndianExplicitTransferSyntax);
ts.push_back(UID_BigEndianExplicitTransferSyntax);
ts.push_back(UID_LittleEndianImplicitTransferSyntax);
//ts.push_back(UID_JPEGProcess1TransferSyntax);

//i add this line but dosen't work
//scu.addPresentationContext(UID_JPEGProcess1TransferSyntax, ts);

scu.addPresentationContext(UID_SecondaryCaptureImageStorage, ts);
scu.addPresentationContext(UID_VerificationSOPClass, ts);

OFCondition result = scu.initNetwork();
result = scu.negotiateAssociation();
T_ASC_PresentationContextID presID = findUncompressedPC(UID_SecondaryCaptureImageStorage, scu);
DcmDataset * rspCommandSet = NULL;
DcmDataset * rspStatusDetail = NULL;
Uint16 rspStatusCode = 0;

result = scu.sendSTORERequest(presID, filname, 0, rspCommandSet, rspStatusDetail, rspStatusCode);
scu.closeAssociation(DCMSCU_RELEASE_ASSOCIATION);

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest