noobalert
noobalert

Reputation: 865

DicomImage's writeBMP function produces unclear gray image

I am using DCMTK to read and hopefully modify DICOM images. I have the following code:

#include <iostream>
#include <opencv\cv.h>
#include <dcmtk\dcmimgle\dcmimage.h>

int main() {
    try {
        DicomImage* dicomImage = new DicomImage("C:/Users/Kriselle/Documents/000004.dcm");
        if ((dicomImage != NULL) && (dicomImage->isMonochrome())) {
            dicomImage->writeBMP("C:/Users/Kriselle/Documents/z.bmp", 8);
            std::cout << "z.bmp is created" << std::endl;
        }
        else {
            std::cout << "dicomImage is null or not monochrome" << std::endl;
        }
    }
    catch (cv::Exception e) {
        std::cerr << e.what() << std::endl;
    }
    return 0;
}

All I did was create a DicomImage and write its pixel data to a BMP file with the filename I specified but the image returns only a gray image with the outline of the original image barely recognized.

This is what it should look like: https://www.dropbox.com/s/6dw8nlae8hfvqf6/000004.jpg?dl=0 This is what the code produces: https://www.dropbox.com/s/fff2kch124bzjqy/z.bmp?dl=0

Am I missing something in the code or did I not understand what the function does? Can anyone please enlighten me? Thank you very much!

Upvotes: 0

Views: 157

Answers (1)

J. Riesmeier
J. Riesmeier

Reputation: 1702

As you can read in the API documentation of the DicomImage class, the default is that no VOI transformation is enabled when rendering monochrome DICOM images. In your case, this seems to be inappropriate, so you should specify a more appropriate VOI setting (e.g. a min-max window) or use one of the VOI windows stored in the DICOM dataset (if any).

By the way, after loading the image in the constructor, you should also check the status of this process using the getStatus() method.

Upvotes: 1

Related Questions