<div dir="ltr"><div>Hi Mengda,</div><div><br></div><div>If the vtkImageMapToColors was changing the spacing and origin of the images, then many of the nightly VTK tests would be failing, so I was kind of suspicious about this.</div><div><br></div><div>I tried a few things.</div><div><br></div><div>1) First, I ran your program as-is. And yes, the output .mha file had (1,1,1) spacing.</div><div><br></div><div>2) Then, I added imageColor->Update(), and the spacing of the output .mha file was correct:</div><div><br></div><div><div> Spacing: (0.5, 1.12048, 1)</div><div> Origin: (10, 20, 0)</div></div><div><br></div><div>3) Then, I removed imageColor->Update(), and replaced the vtkMetaImageWriter with vtkNIFTIImageWriter. The spacing in the .nii file was correct.</div><div><br></div><div>4) Then, I put the vtkMetaImageWriter back, and replaced vtkImageMapToColors with vtkImageCast. The resulting .mha file had spacing (1,1,1).</div><div><br></div><div>So this tells me:</div><div><br></div><div>A) The problem is not specific to vtkImageMapToColors.</div><div>B) The problem appears to be specific to vtkMetaImageWriter</div><div>C) The problem goes away if I add an Update() before the writer</div><div><br></div><div>Mengda, can you confirm this by trying a different image writer?</div><div><br></div><div> - David</div><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 13, 2016 at 8:44 AM, Mengda Wu <span dir="ltr"><<a href="mailto:wumengda@gmail.com" target="_blank">wumengda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Has anyone tested this bug?<div><br></div><div>Thanks!</div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 6, 2016 at 4:22 PM, Mengda Wu <span dir="ltr"><<a href="mailto:wumengda@gmail.com" target="_blank">wumengda@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">Hi Vtkusers,<div><br></div><div> I found a bug in vtkImageMapToColors. It does not output with input spacing and origin. It sets the spacing to [1,1,1] and origin to [0,0,0]. I am using VTK 6.2 but I believe it happens also in VTK 7.0. Can you fix this? Here is a test program and a sample image (input.mha) and its output(input-colormap.mha):</div><div><br></div><div> <span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkMetaImageReader> inputReader = vtkSmartPointer<vtkMetaImageReader>::New();</div><div><span style="white-space:pre-wrap"> </span>inputReader->SetFileName(argv[1]);</div><div><span style="white-space:pre-wrap"> </span>try</div><div><span style="white-space:pre-wrap"> </span>{</div><div><span style="white-space:pre-wrap"> </span>inputReader->Update();</div><div><span style="white-space:pre-wrap"> </span>}</div><div><span style="white-space:pre-wrap"> </span>catch(...)</div><div><span style="white-space:pre-wrap"> </span>{</div><div><span style="white-space:pre-wrap"> </span>std::cerr << "Error occurs when reading " << argv[1] << std::endl;</div><div><span style="white-space:pre-wrap"> </span>return EXIT_FAILURE;</div><div><span style="white-space:pre-wrap"> </span>}</div><div><br></div><div><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();</div><div><span style="white-space:pre-wrap"> </span>lookupTable->SetTableRange(0.0, 255.0);</div><div><span style="white-space:pre-wrap"> </span>lookupTable->SetNumberOfTableValues(256);</div><div><span style="white-space:pre-wrap"> </span>lookupTable->SetTableValue(0, 0.0, 0.0, 0.0, 0.0);</div><div><span style="white-space:pre-wrap"> </span>for(vtkIdType i=1; i<256; i++)</div><div><span style="white-space:pre-wrap"> </span>lookupTable->SetTableValue(i, 1.0, 0.0, 0.0, 0.4);</div><div><span style="white-space:pre-wrap"> </span>lookupTable->Build();</div><div><span style="white-space:pre-wrap"> </span>vtkSmartPointer<vtkImageMapToColors> imageColor = vtkSmartPointer<vtkImageMapToColors>::New();</div><div><span style="white-space:pre-wrap"> </span>imageColor->SetInputConnection(inputReader->GetOutputPort());</div><div><span style="white-space:pre-wrap"> </span>imageColor->SetOutputFormatToRGBA();</div><div><span style="white-space:pre-wrap"> </span>imageColor->SetLookupTable(lookupTable);</div><div><br></div><div><span style="white-space:pre-wrap"> </span>vtkSmartPointer< vtkMetaImageWriter > writer = vtkSmartPointer< vtkMetaImageWriter >::New();</div><div><span style="white-space:pre-wrap"> </span>writer->SetFileName(argv[2]);</div><div><span style="white-space:pre-wrap"> </span>writer->SetInputConnection(imageColor->GetOutputPort());</div><div><span style="white-space:pre-wrap"> </span>try</div><div><span style="white-space:pre-wrap"> </span>{</div><div><span style="white-space:pre-wrap"> </span>writer->Write();</div><div><span style="white-space:pre-wrap"> </span>}</div><div><span style="white-space:pre-wrap"> </span>catch(...)</div><div><span style="white-space:pre-wrap"> </span>{</div><div><span style="white-space:pre-wrap"> </span>std::cerr << "Error occurs when writing " << argv[2] << std::endl;</div><div><span style="white-space:pre-wrap"> </span>return EXIT_FAILURE;</div><div><span style="white-space:pre-wrap"> </span>}</div><div><br></div><div>Thanks,</div><div>Mengda</div></div></blockquote></div></div></div></div>
<br></blockquote></div><br></div></div>