[vtkusers] running example program

Stefan Wesarg stefan.wesarg at igd.fraunhofer.de
Thu Oct 28 10:49:38 EDT 2004


Hi Mark,

Your right! Just write the raw image data to a new file for every slice 
and it is done. I looked through my old code and found the read and 
write functions you need. You find them just below.

("unsigned short usVol[iImgSizeX * iImgSizeY]" contains the raw image data)

Best regards,
Stefan

 >>>> start of code snippet <<<<
void read_image(ifstream* pFile)
{
    int iImgSize = iImgSizeX * iImgSizeY;
    int i;
    unsigned char byte;
    unsigned char high, low;
    unsigned short usTag = 0x0000;

    // ignore header
    while (usTag != 0x7fe0)
    {
        pFile->read((unsigned char*) &low, sizeof(low));
        pFile->read((unsigned char*) &high, sizeof(high));
        usTag = (256 * high + low);
    }

    // read the last header bytes
    pFile->read((unsigned char*) &low, sizeof(low));
    pFile->read((unsigned char*) &high, sizeof(high));

    // start reading the data
    for (i = 0; i < iImgSize; i++)
    {
        pFile->read((unsigned char*) &low, sizeof(low));
        pFile->read((unsigned char*) &high, sizeof(high));
        usVol[i] = (256 * high + low);
    }

}

void write_image(ofstream* pFileOut)
{
    int iImgSize = iImgSizeX * iImgSizeY;

    for (int i = 0; i < iImgSize; i++)
    {
        unsigned short high    = usVol[i] >> 8;
        unsigned short low = unsigned short(usVol[i] << 8);
        low = low >> 8;
        *pFileOut << unsigned char(low);
        *pFileOut << unsigned char(high);
    }
}
 >>>> end of code snippet <<<<

Mark Wyszomierski wrote:

>Hi Stefan,
>
>Thanks this is just what I needed to know, I am in fact using
>uncompressed 16 bit data. Getting the pixel data as you suggested will
>be easy, in what form should I save it though? For each image slice do
>I literally extract byte 1 of the pixel data to the end, then write
>ONLY that information to a new file? No other information, just the
>pixel data?
>
>Thanks!
>
>
>On Thu, 28 Oct 2004 08:48:30 +0200, Stefan Wesarg
><stefan.wesarg at igd.fraunhofer.de> wrote:
>  
>
>>Hi Mark,
>>
>>the example that you are using does not support the loading of DICOM
>>data. In fact VTK doesn't do that at all.
>>If you want to load your DICOM data it has to be converted to 16 Bit
>>image data without any additional information in the files. For
>>uncompressed 16 Bit DICOM data - I gues that this is what you are
>>dealing with - it is quite easy.
>>
>>Simply write a small program that removes the header from the DICOM file
>>and that writes the remaining information back to a new file. The
>>program has to look for the Tag "7FE0" that signifies the start of the
>>image information. The image information itself starts 2 Bytes after the
>>"7FE0" Tag, i.e. "E0 7F xx xx ii" where "ii" is the first byte of the
>>image information.
>>
>>Stripping the DICOM header this way allows you to load the image data
>>with the vtkVolume16Reader that is used in the Medical1 example. (I did
>>it a several times like this, and it works quite well.)
>>
>>Best regards,
>>Stefan
>>
>>
>>
>>Mark Wyszomierski wrote:
>>
>>    
>>
>>>Hi everyone,
>>>
>>>I just downloaded and compiled VTK. I am trying to use the example
>>>programs, specifically Medical1.
>>>(C:\VTK\Examples\Medical\Cxx\Medical1).
>>>
>>>I have a dicom dataset I would like to visualize. I have them in a
>>>single directory. Do I need to convert this dataset into some kind of
>>>3D file type? Or will that be generated from the 2D slices?
>>>
>>>This is my first work in 3D file types for medical imaging, what are
>>>the most popular formats?
>>>
>>>Thank you,
>>>Mark
>>>_______________________________________________
>>>      
>>>
---------------------------------------------------------------------
Dipl.-Phys. Stefan Wesarg

Fraunhofer Institute for Computer Graphics
Cognitive Computing and Medical Imaging (A7)
Fraunhoferstr. 5, 64283 Darmstadt, Germany
---------------------------------------------------------------------
email:	stefan.wesarg at igd.fraunhofer.de
http://www.igd.fhg.de/~swesarg/

phone:	+49 6151 - 155 511
fax:	+49 6151 - 155 480
---------------------------------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3698 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20041028/ca23db14/attachment.bin>


More information about the vtkusers mailing list