<div>hello:</div>
<div>I want to do a series of DICOM image processing with vtkImageData class, ie, getting the gray value of point (i,j) with GetScalarComponentAsDouble(i,&nbsp;&nbsp;j,0,0), and set it with SetScalarComponentFromDouble(i,j,0,0,grayValue), but there is some problem:
</div>
<div>the program is as follow:</div>
<div>
<table class="t_msg" cellspacing="0" cellpadding="4" border="0">
<tbody>
<tr>
<td class="line" style="PADDING-TOP: 10px" valign="top" height="100%">
<div class="t_msgfont">#include &quot;vtkDICOMImageReader.h&quot;<br>#include &quot;vtkImageViewer.h&quot;<br>#include &quot;vtkRenderWindowInteractor.h&quot;<br>#include &quot;vtkImageData.h&quot;<br>#include &quot;vtkRenderer.h
&quot;<br><br>int main()<br>{<br>&nbsp; &nbsp; vtkDICOMImageReader&nbsp; &nbsp;*reader =&nbsp;&nbsp;vtkDICOMImageReader::New();<br>&nbsp; &nbsp; &nbsp; &nbsp; reader-&gt;SetDataByteOrderToLittleEndian();<br>&nbsp; &nbsp; &nbsp; &nbsp; reader-&gt;SetFileName(&quot;ankle.dcm&quot;);<br>&nbsp; &nbsp; &nbsp; &nbsp; //Set the origin of the data (location of first pixel in the file)
<br>&nbsp; &nbsp; &nbsp; &nbsp; reader-&gt;SetDataOrigin(0.0,0.0,0.0);<br>&nbsp; &nbsp; &nbsp; &nbsp; reader-&gt;Update();<br>&nbsp; &nbsp; &nbsp; &nbsp; int wide=reader-&gt;GetWidth();<br>&nbsp; &nbsp; &nbsp; &nbsp; int height=reader-&gt;GetHeight();<br><br>&nbsp; &nbsp; &nbsp; &nbsp; vtkImageData *imgData=vtkImageData::New();
<br>&nbsp; &nbsp; &nbsp; &nbsp; imgData-&gt;SetDimensions(wide,height,1);<br>&nbsp; &nbsp; imgData-&gt;SetScalarTypeToUnsignedChar();<br>&nbsp; &nbsp; imgData-&gt;SetNumberOfScalarComponents(4);<br>&nbsp; &nbsp; imgData-&gt;AllocateScalars();&nbsp; &nbsp; &nbsp; &nbsp; <br><br>&nbsp; &nbsp; &nbsp; &nbsp; imgData-&gt;DeepCopy(reader-&gt;GetOutput());
<br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; for(int i=1;i&lt;wide-1;i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(int j=1;j&lt;height-1;j++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; double temp;&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp=reader-&gt;GetOutput()-&gt;GetScalarComponentAsDouble(i,&nbsp;&nbsp;j,0,0);
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //evaluate&nbsp;imgData with&nbsp;original image&#39;s gray value</div>
<div class="t_msgfont">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imgData-&gt;SetScalarComponentFromDouble(i,j,0,0,temp);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //grads</div>
<div class="t_msgfont">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for( i=1;i&lt;wide-1;i++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for(int j=1;j&lt;height-1;j++)<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int temp1[10];</div>
<div class="t_msgfont">&nbsp;&nbsp;&nbsp;&nbsp;//the processed image is good when using progarm 2. but the processed image is exceptional when progarm 1 is used. The data in imageData and reader should be the same with &quot;temp=reader-&gt;GetOutput()-&gt;GetScalarComponentAsDouble(i,&nbsp;&nbsp;j,0,0);
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //evaluate&nbsp;imgData with&nbsp;original image&#39;s gray value 
<div class="t_msgfont">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imgData-&gt;SetScalarComponentFromDouble(i,j,0,0,temp);&quot;</div>
<div class="t_msgfont">but the actual result is different. Maybe the class data style is different. It will be thankful if you can tell me why!<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //=====program 1£º<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp1[1]=imgData-&gt;GetScalarComponentAsDouble(i-1,j-1,0,0);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp1[2]=imgData-&gt;GetScalarComponentAsDouble(i,&nbsp;&nbsp;j-1,0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp1[3]=imgData-&gt;GetScalarComponentAsDouble(i+1,j-1,0,0);
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp1[4]=imgData-&gt;GetScalarComponentAsDouble(i-1,j,0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp1[5]=imgData-&gt;GetScalarComponentAsDouble(i,&nbsp;&nbsp;j,0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp1[6]=imgData-&gt;GetScalarComponentAsDouble(i+1,j,0,0);*/
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//=====program 2£º<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp1[1]=reader-&gt;GetOutput()-&gt;GetScalarComponentAsDouble(i-1,j-1,0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp1[2]=reader-&gt;GetOutput()-&gt;GetScalarComponentAsDouble(i,&nbsp;&nbsp;j-1,0,0);
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp1[3]=reader-&gt;GetOutput()-&gt;GetScalarComponentAsDouble(i+1,j-1,0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp1[4]=reader-&gt;GetOutput()-&gt;GetScalarComponentAsDouble(i-1,j,0,0);
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp1[5]=reader-&gt;GetOutput()-&gt;GetScalarComponentAsDouble(i,&nbsp;&nbsp;j,0,0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; temp1[6]=reader-&gt;GetOutput()-&gt;GetScalarComponentAsDouble(i+1,j,0,0);&nbsp;&nbsp;&nbsp;&nbsp;</div></div>
<div class="t_msgfont">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //=====program2&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; temp1[5]=sqrt((temp1[5]-temp1[3])*(temp1[5]-temp1[3])+(temp1[2]-temp1[6])*(temp1[2]-temp1[6]));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imgData-&gt;SetScalarComponentFromDouble(i,j,0,0,temp1[5]);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; <br><br><br>//=======================================================
<br><br>&nbsp; &nbsp; vtkImageViewer&nbsp;&nbsp;*viewer = vtkImageViewer::New();<br>&nbsp; &nbsp; viewer-&gt;SetInput(imgData);<br>&nbsp; &nbsp; &nbsp; &nbsp; viewer-&gt;SetColorWindow(280);<br>&nbsp; &nbsp; &nbsp; &nbsp; viewer-&gt;SetColorLevel(40);<br>&nbsp; &nbsp; &nbsp; &nbsp; viewer-&gt;SetPosition(100,100);
<br>&nbsp; &nbsp; &nbsp; &nbsp; viewer-&gt;Render();<br><br>&nbsp; &nbsp; vtkRenderWindowInteractor *viewerinter = vtkRenderWindowInteractor::New();<br>&nbsp; &nbsp; viewer-&gt;SetupInteractor(viewerinter);<br>&nbsp; &nbsp; viewerinter-&gt;Initialize();<br>&nbsp; &nbsp; viewerinter-&gt;Start(); 
<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; reader-&gt;Delete();<br>&nbsp; &nbsp; &nbsp; &nbsp; imgData-&gt;Delete();<br>&nbsp; &nbsp; &nbsp; &nbsp; viewer-&gt;Delete();<br>&nbsp; &nbsp; &nbsp; &nbsp; viewerinter-&gt;Delete();<br>&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp; &nbsp; &nbsp; return 0;<br>}</div><br><font style="FONT: 12px Tahoma, Verdana; COLOR: #333333">
</font></td></tr>
<tr>
<td align="right">&nbsp;</td></tr></tbody></table></div>