<div>Hi,David,</div><div><span style="line-height: 1.5;"><br></span></div><div><span style="line-height: 1.5;">As you help me on this thread, I would like to continue on it. I don't clearly understand your words "</span><span style="line-height: 1.5;">I didn't think it would be necessary, because I thought that if you passed an RGB (or RGBA) image to vtkImageViewer2 ....</span><span style="line-height: 1.5;">". How to pass an RGB image to the vtkImageViewer2? </span></div><div><span style="line-height: 1.5;"><br></span></div><div><span style="line-height: 1.5;">My requirement is that the pixels in some greyscale threshold displayed at some specific color and other pixels are not changed. At that time I had some misunderstanding and I thought it worked.</span><span style="line-height: 1.5;">Actually I don't work it out. </span><span style="line-height: 1.5;">My code is below. I just change the lookup table of the vtkImageViewer2's </span><span style="line-height: 1.5;">vtkImageMapToWindowLevelColors. The result is not I need. </span></div><div><span style="line-height: 1.5;"><br></span></div><div><span style="line-height: 1.5;">It just directly change the image of </span><span style="line-height: 1.5;">vtkImageViewer2</span><span style="line-height: 1.5;"> and the whole image are changed.</span><span style="line-height: 1.5;"> See the attachment image 1. </span></div><div><span style="line-height: 1.5;">If I use a new </span>vtkImageMapToColors instead of the <span style="line-height: 1.5;">vtkImageViewer2's </span><span style="line-height: 1.5;">vtkImageMapToWindowLevelColors, then nothing happen. Seems the </span><span style="line-height: 1.5;">vtkImageMapToColors shows no effect. </span><span style="line-height: 1.5;">See the attachment image 2.</span></div><div><span style="line-height: 1.5;"><br></span></div><div><span style="line-height: 1.5;">My DICOM series is 512*512*190. The scalar range is [0, 3140]. In my test, the threshold value is [0,400].</span></div><div><span style="line-height: 1.5;"><br></span></div><div><div><span class="Apple-tab-span" style="white-space:pre"> </span>private void GrayToColors( Segament_Threshold threshold)</div><div> {</div><div> vtkLookupTable lookupTable = vtkLookupTable.New();</div><div><br></div><div> double validmin = System.Math.Max(m_scalarrange[0], threshold.Min_Threshold);</div><div> double validmax = System.Math.Min(m_scalarrange[1], threshold.Max_Threshold);</div><div> int number = (int)(m_scalarrange[1] - m_scalarrange[0] + 1);</div><div> lookupTable.SetRange(m_scalarrange[0], m_scalarrange[1]);</div><div> lookupTable.SetNumberOfTableValues(number);</div><div> lookupTable.Build();</div><div><br></div><div> for (int i = (int)(m_scalarrange[0]); i < (int)(validmin); i++)</div><div> {</div><div> lookupTable.SetTableValue(i - (int)m_scalarrange[0], 0.0, 0.0, 0.0, 0.0);</div><div> }</div><div> for (int i = (int)(validmin); i <= (int)(validmax); i++)</div><div> {</div><div> lookupTable.SetTableValue(i - (int)m_scalarrange[0], 0x66/0xff, 1.0, 1.0, 1.0);</div><div> }</div><div> for (int i = (int)(threshold.Max_Threshold) + 1; i < (int)(m_scalarrange[1]); i++)</div><div> {</div><div> lookupTable.SetTableValue(i - (int)m_scalarrange[0], 0.0, 0.0, 0.0, 0.0);</div><div> }</div><div><br></div><div><span style="line-height: 1.5;"> vtkImageMapToWindowLevelColors colormapper = m_imageViewer.GetWindowLevel();</span></div><div> colormapper.SetOutputFormatToRGBA();</div><div> colormapper.PassAlphaToOutputOn();</div><div> colormapper.SetLookupTable(lookupTable);</div><div> colormapper.Update();</div><div><br></div><div> if (m_colormapActor == null)</div><div> {</div><div> m_colormapActor = vtkImageActor.New();</div><div> m_colormapActor.GetMapper().SetInputConnection(colormapper.GetOutputPort());</div><div> m_renderer.AddViewProp(m_colormapActor);</div><div> }</div><div> m_renderer.ResetCamera();</div><div> m_renderer.Modified();</div><div> m_imageViewer.SetRenderer(m_renderer);</div><div> m_imageViewer.Render();</div><div> }</div></div><div><br></div><div>Any thing wrong?</div><div><br></div><div>Thanks</div><div>Liu Peng</div><div><br></div> 在2016-03-10,"David Gobbi" <david.gobbi@gmail.com> 写道:
<blockquote id="isReplyContent" style="padding-left:1ex; margin: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">
-----原始邮件-----<br>
<b>发件人:</b>"David Gobbi" <david.gobbi@gmail.com> <br>
<b>发送时间:</b>2016年03月10日 星期四<br>
<b>收件人:</b>"Liu_tj" <tjlp@netease.com><br>
<b>抄送:</b>"vtkusers" <vtkusers@vtk.org><br>
<b>主题:</b>Re: Re: Re: Re: Re: [vtkusers] How to map negative grayscale to color?<br>
<br><div dir="ltr"><div>Hi Liu Peng,</div><div><br></div><div>I'm glad to hear it worked for you. I didn't think it would be necessary, because I thought that if you passed an RGB (or RGBA) image to vtkImageViewer2 it would simply display it as-is, without needing any tweaks to internal parts of the Viewer (note: I hardly ever use vtkImageViewer or vtkimageViewer2 myself, I prefer to use the image mappers directly instead).</div><div><br></div><div> - David</div><div><br></div><div><div><div class="gmail_extra"><div class="gmail_quote">On Wed, Mar 9, 2016 at 8:21 AM, Liu_tj <span dir="ltr"><<a href="mailto:tjlp@netease.com" target="_blank">tjlp@netease.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, David,<br><br>I try it again. The conversion from gray scale to RGB works after I set the LookupTable to vtkImageMapToWindowLevelColors returned by vtkImageViewer2::GetWindowLevels().<span class=""><div><br><br></div>
<span>
</span>
<br> 在2016-03-09,"David Gobbi" <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>> 写道:
</span><blockquote style="padding-left:1ex;margin:0px 0px 0px 0.8ex;BORDER-LEFT:#ccc 1px solid"><span class="">
-----原始邮件-----<br>
<b>发件人:</b>"David Gobbi" <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>> <br>
<b>发送时间:</b>2016年03月9日 星期三<br>
<b>收件人:</b>"Liu_tj" <<a href="mailto:tjlp@netease.com" target="_blank">tjlp@netease.com</a>><br>
</span><b>抄送:</b>"vtkusers" <<a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a>><br>
<b>主题:</b>Re: Re: Re: Re: [vtkusers] How to map negative grayscale to color?<div><div class="h5"><br>
<br><div dir="ltr">No, that isn't necessary.<br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 8, 2016 at 9:29 PM, Liu_tj <span dir="ltr"><<a href="mailto:tjlp@netease.com" target="_blank">tjlp@netease.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hi,David,<br><br>Do I need to set the LookupTable to vtkImageMapToWindowLevelColors which is returned by vtkImageViewer2::GetWindowLevels() instead of create a new vtkImageMapToColors?<br><br>BR,<br>Thanks<br><br></div><span>
<span>
</span>
<br> 在2016-03-09,"David Gobbi" <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>> 写道:
</span><blockquote style="padding-left:1ex;margin:0px 0px 0px 0.8ex;BORDER-LEFT:#ccc 1px solid"><span>
-----原始邮件-----<br>
<b>发件人:</b>"David Gobbi" <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>> <br>
</span><b>发送时间:</b>2016年03月9日 星期三<br>
<b>收件人:</b>"Liu_tj" <<a href="mailto:tjlp@netease.com" target="_blank">tjlp@netease.com</a>><br>
<b>主题:</b>Re: Re: Re: [vtkusers] How to map negative grayscale to color?<div><div><br>
<br><div dir="ltr"><div>Hi Liu Peng,</div><div><br></div><div>Do you want to show a gray image underneath, and the color image</div><div>on top? I'm not sure if vtkImageViewer works property if you add</div><div>more than one image.</div><div><br></div><div>You should add a "print" statement of some kind to your code to</div><div>print the values of scalarrange, to be sure they are correct.</div><div><br></div>Don't call colormap.Build() after setting your own values for the table,<div>or it might overwrite the values that you have set. If you call it at all,</div><div>call it immediately after SetNumberOfTableValues(), before you set</div><div>any of your own values.</div><div><br></div><div>The range on the final for() loop should be the following:</div><div>for (int i = (int)(threshhold[1]) + 1; i <= (int)(scalarrange[1]); i++)</div><div><br></div><div>Also, if you want the beyond-threshold values to be transparent</div><div>instead of black, then set the alpha component to zero:</div><div><br></div><div>for (int i = (int)(scalarrange[0]); i < (int)(threshhold[0]); i++)<br></div><div><div>{</div><div> colormap.SetTableValue(i - (int)scalarrange[0], 0.0, 0.0, 0.0, 0.0);</div><div>}</div></div><div><div><br></div><div> - David</div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 8, 2016 at 9:40 AM, Liu_tj <span dir="ltr"><<a href="mailto:tjlp@netease.com" target="_blank">tjlp@netease.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, David,<br><br>I follow your post and it doesn't work. The DICOM image shows no color, just gray image. Could you have a look at my code below? I use a vtkImageView2 to display the DICOM image. The code is c# by Activiz .NET. The scalar range of test image is [-1024,3071]. I want to show the gray scale at [1000,3000] to green. The function GrayToColors() maps gray scale to color, it is called by Display().<br><br>private void Display(vtkRenderWindow aRenderWindow, vtkAlgorithmOutput aData)<br> {<br> if (aData == null)<br> return;<br><br> m_imageViewer = vtkImageViewer2.New();<br> m_imageViewer.SetInputConnection(aData);<br> switch (m_sliceDirection)<br> {<br> case Direction.AXIAL:<br> m_imageViewer.SetSliceOrientationToXY();<br> break;<br> case Direction.CORONAL:<br> m_imageViewer.SetSliceOrientationToYZ();<br> break;<br> case Direction.SAGITTAL:<br> m_imageViewer.SetSliceOrientationToXZ();<br> break;<br> default:<br> break;<br> }<br><br> m_imageViewer.GetSliceRange(ref m_minSliceNumber, ref m_maxSliceNumber);<br> m_interactorStyle = vtkInteractorStyleImage.New();<br> m_interactorStyle.MouseWheelForwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelForwardEvt);<br> m_interactorStyle.MouseWheelBackwardEvt += new vtkObject.vtkObjectEventHandler(interactor_MouseWheelBackwardEvt);<br><br> aRenderWindow.GetInteractor().SetInteractorStyle(m_interactorStyle);<br> aRenderWindow.GetRenderers().InitTraversal();<br><br> m_renderer = aRenderWindow.GetRenderers().GetFirstRenderer();<br> m_renderer.SetBackground(0.0, 0.0, 0.0);<br><br> m_imageViewer.SetRenderWindow(aRenderWindow);<br> m_currentSlice = m_minSliceNumber + (m_maxSliceNumber - m_minSliceNumber) / 2;<br> m_imageViewer.SetSlice(m_currentSlice);<br><br> double[] scalarrange = new double[2];<br> scalarrange = m_imageViewer.GetInput().GetScalarRange();<br> double[] threshhold = new double[2];<br> threshhold[0] = 1000;<br> threshhold[1] = 3000;<br> m_imageViewer.Render();<br> GrayToColors(m_renderer, aData, scalarrange, threshhold);<br><br> m_imageViewer.Render();<br> }<br><br> private void GrayToColors(vtkRenderer renderer, vtkAlgorithmOutput data, double[] scalarrange, double[] threshhold)<br> {<br> vtkLookupTable colormap = vtkLookupTable.New();<br> int number = (int)(scalarrange[1] - scalarrange[0] + 1);<br> colormap.SetRange(scalarrange[0], scalarrange[1]);<br> colormap.SetNumberOfTableValues(number);<br> <br> for (int i = (int)(scalarrange[0]); i < (int)(threshhold[0]); i++)<br> {<br> colormap.SetTableValue(i - (int)scalarrange[0], 0.0, 0.0, 0.0, 1.0);<br> }<br> for (int i = (int)(threshhold[0]); i <= (int)(threshhold[1]); i++)<br> {<br> colormap.SetTableValue(i - (int)scalarrange[0], 0.0, 1.0, 0.0, 1.0);<br> }<br> for (int i = (int)(threshhold[1]); i < (int)(scalarrange[1]); i++)<br> {<br> colormap.SetTableValue(i - (int)scalarrange[0], 0.0, 0.0, 0.0, 1.0);<br> }<br> colormap.Build();<br><br> vtkImageMapToColors colormapper = vtkImageMapToColors.New();<br> colormapper.SetInputConnection(data);<br> colormapper.SetLookupTable(colormap);<br> colormapper.Update();<br><br> vtkImageActor colormapActor = vtkImageActor.New();<br> colormapActor.SetInput(colormapper.GetOutput());<br> renderer.AddActor(colormapActor);<br> renderer.ResetCamera();<br> renderer.Modified();<br> }<br><div><br>Thanks<br></div><span>
<span>
</span>
<br> 在2016-03-08,"David Gobbi" <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>> 写道:
</span><blockquote style="padding-left:1ex;margin:0px 0px 0px 0.8ex;BORDER-LEFT:#ccc 1px solid"><span>
-----原始邮件-----<br>
<b>发件人:</b>"David Gobbi" <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>> <br>
<b>发送时间:</b>2016年03月8日 星期二<br>
<b>收件人:</b>"Liu_tj" <<a href="mailto:tjlp@netease.com" target="_blank">tjlp@netease.com</a>><br>
<b>抄送:</b>"vtkusers" <<a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a>><br>
</span><b>主题:</b>Re: Re: [vtkusers] How to map negative grayscale to color?<div><div><br>
<br><div dir="ltr">Hi Liu Pen,<div><br></div><div>That's because I forgot to include the index argument in the call to SetTableValue:</div><div><br></div><div><div>table->SetRange(-1024, 4095);</div><div>table->SetNumberOfTableValues(4095 + 1024 + 1);</div></div><div><div>for (int i = -1024; i < -10; i++) {</div><div> table->SetTableValue(i + 1024, 0.0, 0.0, 0.0, 1.0);</div><div>}</div></div><div><br></div><div>The table index must start at zero. The call to SetRange(-1024, 4095) causes the scalar value -1024 to map to table index 0. In the "for" loop, i is the scalar value.</div><div><br></div><div> - David</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Mar 8, 2016 at 7:27 AM, Liu_tj <span dir="ltr"><<a href="mailto:tjlp@netease.com" target="_blank">tjlp@netease.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, David, <br><div><br>When I try, a lot of errors are popup: "Can't set the table value for negative index".<br><br>Seems the negative grayscale needs some transformation.<br><br>Thanks<br>Liu Peng<br><br></div><span>
<span>
</span>
<br> 在2016-03-08,"David Gobbi" <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>> 写道:
</span><blockquote style="padding-left:1ex;margin:0px 0px 0px 0.8ex;BORDER-LEFT:#ccc 1px solid"><span>
-----原始邮件-----<br>
<b>发件人:</b>"David Gobbi" <<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>> <br>
<b>发送时间:</b>2016年03月8日 星期二<br>
<b>收件人:</b>"Liu_tj" <<a href="mailto:tjlp@netease.com" target="_blank">tjlp@netease.com</a>><br>
<b>抄送:</b>"vtkusers" <<a href="mailto:vtkusers@vtk.org" target="_blank">vtkusers@vtk.org</a>><br>
<b>主题:</b>Re: [vtkusers] How to map negative grayscale to color?<br>
<br></span><div><div><div dir="ltr">Hi Liu Peng,<div><br></div><div>You can set individual values in the lookup table,</div><div>in order to precisely map certain scalar values to</div><div>specific colors:</div><div><br></div><div>table->SetRange(-1024, 4095);</div><div>table->SetNumberOfTableValues(4095 + 1024 + 1);</div><div>for (int i = -1024; i < -10; i++) {</div><div> table->SetTableValue(0.0, 0.0, 0.0, 1.0);</div><div>}</div><div>for (int i = -10; i <= 200; i++) {</div><div> table->SetTableValue(0.0, 1.0, 0.0, 1.0);</div><div>}</div><div>etcetera.</div><div><br></div><div> - David</div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 7, 2016 at 9:31 AM, Liu_tj <span dir="ltr"><<a href="mailto:tjlp@netease.com" target="_blank">tjlp@netease.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>Hi,<br><br>I try to use the vtkLookupTable to convert the grayscale to rgb color. The image scalar range is [-1024,3071] returned by vtkImageData::GetScalarRange(). Now I want to convert specific grayscale range, for example, [-10,200] to one color, such as green (RGB is 0,1,0). How to do that by vtkLookupTable? I have no idea what method should call: SetNumberOfTableValues(), SetRange(), SetHueRange(), SetValueRange(). What do "Hue" and "Value" stand for?<br><br>BR,<br>Liu Peng<br></div></blockquote></div></div></div></div></div></div></blockquote></blockquote></div></div></div></div></blockquote></blockquote></div></div></div></div></blockquote></blockquote></div></div></div></div></div></blockquote></blockquote></div><br></div></div></div></div>
</blockquote><br><br><span title="neteasefooter"><p> </p></span>