ZSmain
ZSmain

Reputation: 390

How to convert a DicomImage(Dcmtk) with depth=17 to a Mat(Opencv) object?

When using this code I don't get the result that I want (see the picture).

DicomImage *image = new DicomImage("/home/000001.dcm");
cv::Mat inputImage(int(image->getHeight()), int(image->getWidth()), CV_16UC1, (uchar*)image->getOutputData(16));

Because image has a depth of 17, and if change CV_16UC1 to CV_32xx I get a nonsense image. Obviously a 17bits need more than 16bits to get stored correctly. My question is, which Opencv Map type should I use (CV_32SC1,CV_32SC2,CV_32SC3,CV_32SC4 or else), what is the difference between them, do I have to use a bitmask to prevent getting garbage in the rest upper bits and how can I do that?

[Pictue]

Upvotes: 0

Views: 461

Answers (1)

J. Riesmeier
J. Riesmeier

Reputation: 1702

The issue with the rendered image is not 16 vs. 17 bit depth (since you've specified to always get 16 bit) but that you haven't selected an appropriate VOI window, e.g. by calling image->setMinMaxWindow() before image->getOutputData().

Upvotes: 1

Related Questions