convert jpg to dicom c++
Moderator: Moderator Team
-
- Posts: 46
- Joined: Sun, 2012-02-26, 15:12
- Location: Egypt
convert jpg to dicom c++
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);
}
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);
}
-
- DCMTK Developer
- Posts: 2546
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Are you sure that your JPEG image uses RGB? What does img2dcm produce for this particular image?
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.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.
-
- Posts: 46
- Joined: Sun, 2012-02-26, 15:12
- Location: Egypt
convert JPEG to DICOM
sorry for beginnig questions. but how to ensure that my image uses RGB.J. Riesmeier wrote:Are you sure that your JPEG image uses RGB? What does img2dcm produce for this particular image?
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.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.
i used img2dcm tool and the output is the same as my code. And the
Photometric Interpretation=YBRFULL422.
-
- DCMTK Developer
- Posts: 2546
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
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.
-
- Posts: 46
- Joined: Sun, 2012-02-26, 15:12
- Location: Egypt
convert JPEG to DICOM
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?!!!
-
- DCMTK Developer
- Posts: 2546
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Obviously, one solution would be to remove the following line from your code:
Code: Select all
dataset->putAndInsertString(DCM_PhotometricInterpretation,"RGB");
-
- Posts: 46
- Joined: Sun, 2012-02-26, 15:12
- Location: Egypt
convert JPEG to DICOM
[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.
[code]dataset->putAndInsertString(DCM_PhotometricInterpretation,"RGB");[/code][/quote]
I removed this line but the effect is the same.
-
- DCMTK Developer
- Posts: 2546
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
-
- Posts: 46
- Joined: Sun, 2012-02-26, 15:12
- Location: Egypt
convert JPEG to DICOM
[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.
yes, it is identical. I use ezDicom viewer.
-
- DCMTK Developer
- Posts: 2546
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
-
- Posts: 46
- Joined: Sun, 2012-02-26, 15:12
- Location: Egypt
convert JPEG to DICOM
[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?
Can you suggest any viewer?
-
- DCMTK Developer
- Posts: 2546
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
If you need a viewer for the Windows OS, you could e.g. try synedra View Personal.
-
- Posts: 46
- Joined: Sun, 2012-02-26, 15:12
- Location: Egypt
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:J. Riesmeier wrote:If you need a viewer for the Windows OS, you could e.g. try synedra View Personal.
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
-
- DCMTK Developer
- Posts: 2546
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
-
- Posts: 46
- Joined: Sun, 2012-02-26, 15:12
- Location: Egypt
convert JPEG to DICOM
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.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 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?
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 0 guests