<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:12.0pt;
        font-family:"Times New Roman",serif;}
span.m3219583261859247826gmail-sy1
        {mso-style-name:m_3219583261859247826gmail-sy1;}
span.m3219583261859247826hoenzb
        {mso-style-name:m_3219583261859247826hoenzb;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">If you drag-and-drop a single image slice into Slicer then by default it will load that single image slice. How to load the full volume from DICOM:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Option A: Drag-and-drop the directory that contains your DICOM files to the Slicer main window. Slicer offers to import them, accept that option, wait for the
 import to complete, then select the data set in the DICOM browser and load it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Option B: Drag-and-drop a single DICOM file to Slicer. You have the option to load that single slice (default behavior), or check “Show Options” in the top-right
 corner and uncheck “Single File” option in the table.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Andras<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> vtkusers [mailto:vtkusers-bounces@vtk.org]
<b>On Behalf Of </b>David Gobbi<br>
<b>Sent:</b> January 25, 2017 8:36<br>
<b>To:</b> Eddy Cappeau <edcpwk@gmail.com><br>
<b>Cc:</b> vtkusers@vtk.org<br>
<b>Subject:</b> Re: [vtkusers] Problem using vtkDicomWriter<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">Hi Eddy,<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The code is using a vtkDICOMCTGenerator to write an MR image, which is definitely wrong.  Use the vtkDICOMMRGenerator, and make sure the meta data matches the IOD: <a href="http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.8.3.html">http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.8.3.html</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">The standard says that BitsAllocated must be 16 for MR images, therefore an 8-bit MR image is non-standard and DICOM software may to refuse to display it.  You should convert your data to 16-bit (In fact, it seems fishy that you are working
 with unsigned char, since if you are writing a reformat of an MR image, then wasn't the original MR image a 16-bit image?)<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">I can't answer about why Slicer is only showing one slice, as I don't currently have Slicer installed.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"> - David  <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Wed, Jan 25, 2017 at 1:57 AM, Eddy Cappeau <<a href="mailto:edcpwk@gmail.com" target="_blank">edcpwk@gmail.com</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Hi David,<br>
<br>
Here's the code below. This is almost the example of the api doc :<br>
<br>
    auto generator = vtkSmartPointer <vtkDICOMCTGenerator>::New();<br>
    vtkSmartPointer <vtkDICOMMetaData> meta = vtkSmartPointer <vtkDICOMMetaData>::New();<br>
<br>
    meta->SetAttributeValue(DC::PatientName, "Test");<br>
    meta->SetAttributeValue(DC::PatientID, "0000001");<br>
    meta->SetAttributeValue(DC::ScanOptions, "");<br>
    meta->SetAttributeValue(DC::ScanningSequence, "GR");<br>
    meta->SetAttributeValue(DC::SequenceVariant, "SP");<br>
    meta->SetAttributeValue(DC::ScanOptions, "");<br>
    meta->SetAttributeValue(DC::MRAcquisitionType, "2D");<br>
<br>
    vtkSmartPointer <vtkDICOMWriter> dicom_writer =<br>
        vtkSmartPointer <vtkDICOMWriter>::New();<br>
    dicom_writer->SetInputData(img);<br>
    dicom_writer->SetMetaData(meta);<br>
    dicom_writer->SetGenerator(generator);<br>
    dicom_writer->SetSeriesDescription("Sagittal Multi-planar Reformat");<br>
<br>
    // Set the output filename format as a printf-style string.<br>
    dicom_writer->SetFilePattern("%s/IM-0001-%04.4d.dcm");<br>
    // Set the directory to write the files into.<br>
    dicom_writer->SetFilePrefix(path.toStdString().c_str());<br>
    // Write the file.<br>
    dicom_writer->Write();<o:p></o:p></p>
</div>
<p class="MsoNormal">Sorry, the use of an unsigned short type was a carreless mistake. The result is better with unsigned char,<o:p></o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">but I still see just one image of the serie on 3D Slicer. Is there something missing to have a complete serie ?
<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">I didn't know the vtkImageImport and I'll give it a try.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Thanks,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal">Eddy<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">2017-01-24 15:41 GMT+01:00 David Gobbi <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>>:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<p class="MsoNormal">Hi Eddy,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Can you provide the code that you used to write the image with vtkDICOMWriter?  Here is an example:<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><a href="http://dgobbi.github.io/vtk-dicom/doc/api/image_writer.html" target="_blank">http://dgobbi.github.io/vtk-dicom/doc/api/image_writer.html</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Creating an image with a loop that calls GetScalarPointer() for every pixel is not very efficient, and casting to a "char *" when the data is "unsigned short" is wrong: you are setting only 8 bits of each 16-bit pixel, while leaving the
 other 8 bits uninitialized.  The vtkImageImport filter is a better way of generating image data:<o:p></o:p></p>
</div>
<p class="MsoNormal"><a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/ImageImport" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Images/ImageImport</a><span class="m3219583261859247826hoenzb"><span style="color:#888888"><o:p></o:p></span></span></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#888888"> - David<o:p></o:p></span></p>
</div>
<div>
<div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Tue, Jan 24, 2017 at 2:51 AM, Eddy Cappeau <<a href="mailto:edcpwk@gmail.com" target="_blank">edcpwk@gmail.com</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt">Hi,<o:p></o:p></p>
</div>
<p class="MsoNormal">I'd like to use the vtkDICOMWriter class to convert a vtkImage to a set of DICOM images.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><br>
I've compile VTK with the vtkDICOM module enabled and followed the example from the pdf found on the github repository (<a href="http://dgobbi.github.io/vtk-dicom/doc/vtk-dicom.pdf" target="_blank">http://dgobbi.github.io/vtk-dicom/doc/vtk-dicom.pdf</a>).<o:p></o:p></p>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
The image data is created like this :<br>
<br>
    auto  img = vtkSmartPointer < vtkImageData >::New();<br>
    img->SetOrigin(0, 0, 0);<br>
    img->SetDimensions(1024, 1024, numlayer);<br>
    img->SetSpacing(1, 1, 1);<br>
    img->AllocateScalars(VTK_UNSIGNED_SHORT, 1);<o:p></o:p></p>
</div>
<p class="MsoNormal">and the data filled like this : <br>
<br>
           for (int n = 0; x < numlayer; n++) {<br>
                for (int x = 0; x < 1024; x++) {<br>
                    for (int y = 0; y < 1024; y++) {<br>
                        char* pixel = static_cast<char*>(img->GetScalarPointer(x, y, n));<br>
                        pixel[0] = values[x][y];<br>
                    }<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt">I can load the converted result with paraview without problems.<br>
But with 3D Slicer, I can just load the first file of the serie and it display a blank image.<o:p></o:p></p>
</div>
<p class="MsoNormal">What do I have to do to be able to load the images with both application ?<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
Thanks, <o:p></o:p></p>
</div>
<p class="MsoNormal">Eddy<o:p></o:p></p>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</body>
</html>