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 jpg to dicom c++

#1 Post by MuhammadHemdan »

Hi,
I'm writing my own code to convert jpg to dicom using c++ with DCMTK.Then I view the dicom image using ezDicom tool. I can view the image but the colors of the dicom image is grades of orange and black that is not the same colors of my orginal jpg image.
There is another problem that is the transfer syntax of the converted dicom image is "Transfer Syntax UID=1.2.840.10008.1.2.4.50", so I can't transfer it to PACS using storscu.
But if i convert BMP image there is no any problem in convertion or transferring. Can anyone help me?. The following is my code of conversion:


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);
}

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

#2 Post by J. Riesmeier »

Are you sure that your JPEG image uses RGB? What does img2dcm produce for this particular image?
There is another problem that is the transfer syntax of the converted dicom image is "Transfer Syntax UID=1.2.840.10008.1.2.4.50", so I can't transfer it to PACS using storscu.
Of course, you can. This is at least true for the sender side (storescu). What about using option --propose-jpeg8? Using dcmsend would be easier, but this tool requires the latest DCMTK snapshot.

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

convert JPEG to DICOM

#3 Post by MuhammadHemdan »

J. Riesmeier wrote:Are you sure that your JPEG image uses RGB? What does img2dcm produce for this particular image?
There is another problem that is the transfer syntax of the converted dicom image is "Transfer Syntax UID=1.2.840.10008.1.2.4.50", so I can't transfer it to PACS using storscu.
Of course, you can. This is at least true for the sender side (storescu). What about using option --propose-jpeg8? Using dcmsend would be easier, but this tool requires the latest DCMTK snapshot.
sorry for beginnig questions. but how to ensure that my image uses RGB.
i used img2dcm tool and the output is the same as my code. And the
Photometric Interpretation=YBRFULL422.

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

#4 Post by J. Riesmeier »

As far as I know, the img2dcm tool (and the underlying class library) does not convert the color model of the input image. It just feeds the JPEG stream into a DICOM image (and sets the header fields appropriately). Also, JPEG images with RGB color model are not that usual because the compression ratio is not as good as for the YCbCr models.

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

convert JPEG to DICOM

#5 Post by MuhammadHemdan »

J. Riesmeier wrote:As far as I know, the img2dcm tool (and the underlying class library) does not convert the color model of the input image. It just feeds the JPEG stream into a DICOM image (and sets the header fields appropriately). Also, JPEG images with RGB color model are not that usual because the compression ratio is not as good as for the YCbCr models.

When I convert BMP image there is no any problem as i mentioned before. So what is the solution, how can i convert my jpeg image to dicom with same colors?!!!

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

#6 Post by J. Riesmeier »

Obviously, one solution would be to remove the following line from your code:

Code: Select all

dataset->putAndInsertString(DCM_PhotometricInterpretation,"RGB");

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

convert JPEG to DICOM

#7 Post by MuhammadHemdan »

[quote="J. Riesmeier"]Obviously, one solution would be to remove the following line from your code:

[code]dataset->putAndInsertString(DCM_PhotometricInterpretation,"RGB");[/code][/quote]

I removed this line but the effect is the same.

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

#8 Post by J. Riesmeier »

But the DICOM output is now identical to img2dcm? Maybe, your viewer is wrong?

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

convert JPEG to DICOM

#9 Post by MuhammadHemdan »

[quote="J. Riesmeier"]But the DICOM output is now identical to img2dcm? Maybe, your viewer is wrong?[/quote]

yes, it is identical. I use ezDicom viewer.

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

#10 Post by J. Riesmeier »

What about trying another DICOM viewer in order to see whether ezDicom is correct or wrong?

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

convert JPEG to DICOM

#11 Post by MuhammadHemdan »

[quote="J. Riesmeier"]What about trying another DICOM viewer in order to see whether ezDicom is correct or wrong?[/quote]

Can you suggest any viewer?

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

#12 Post by J. Riesmeier »

If you need a viewer for the Windows OS, you could e.g. try synedra View Personal.

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

#13 Post by MuhammadHemdan »

J. Riesmeier wrote:If you need a viewer for the Windows OS, you could e.g. try synedra View Personal.
I tried this viewer. But there is a problem in color also. But when I used its converter the result is correct and ezDICOM can view the image correctly. When i examined the tags in ezDICOM in case of my converted image using my code or img2dcm i found:
TransferSyntaxUID =JPEGBaseline
PhotometricInterpretation=YBRFULL422
Pixel Data=0

But in case of the converted image from synedra viewer (which is correct as the output from converting BMP image) i found:
TransferSyntaxUID =LittleEndianExplicit
PhotometricInterpretation=RGB
Pixel Data=3888000

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

#14 Post by J. Riesmeier »

Sorry, but I don't get what you intend to say in your last posting. Could you please describe again (with other words or in more detail) what you did to create the DICOM image, what the textual dump is (group 0028 and pixel data) and which viewer shows what result.

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

convert JPEG to DICOM

#15 Post by MuhammadHemdan »

J. Riesmeier wrote:Sorry, but I don't get what you intend to say in your last posting. Could you please describe again (with other word or in more detail) what you did to create the DICOM image, what the textual dump is (group 0028 and pixel data) and which viewer shows what result.
I used the synedra viewer to view the dicom image i generated from my code and the colors of this image were not correct as happend with ezDICOM viewer. So the problem is not in the viewer.

I converted the jpeg image with the synedra converter and the colors of the dicom image were the same of the original image.

Now I have two dicom images one from my code and one from synedra converter. I took these two images and view them in ezDICOM viewer and display their meta data i found the following differences:

in case of my converted image i found:
TransferSyntaxUID =JPEGBaseline
PhotometricInterpretation=YBRFULL422
Pixel Data=0

But in case of the converted image from synedra converter i found:
TransferSyntaxUID =LittleEndianExplicit
PhotometricInterpretation=RGB
Pixel Data=3888000

Data in group 0028 are the same in the two cases:
0028,0002,Samples Per Pixel=3
0028,0006,Planar Configuration=0
0028,0010,Rows=900
0028,0011,Columns=1440
0028,0100,Bits Allocated=8
0028,0101,Bits Stored=8
0028,0102,High Bit=7
0028,0103,Pixel Representation=0
0028,2110,?=12592
0028,2114,?=ISO.10918.1

so why these differences?

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 0 guests