<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre"></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre"><br></span></p><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre">                </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>ConstIteratorType inputIt( labelImage, labelImage->GetLargestPossibleRegion() ); </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>IteratorType outputIt( bwImage, bwImage->GetLargestPossibleRegion() ); </div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span><span style="color: #aa0d91">for</span> ( inputIt.GoToBegin(), outputIt.GoToBegin(); !inputIt.IsAtEnd(); ++inputIt, ++outputIt) </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>{ </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>InputPixelType curLabel = inputIt.Get();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span><span style="color: #aa0d91">if</span>( curLabel > <span style="color: #1c00cf">0</span> ){</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>outputIt.Set( curLabel );</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">                </span>}</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span class="Apple-tab-span" style="white-space:pre">        </span>} </div><p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; min-height: 14.0px"><span class="Apple-tab-span" style="white-space:pre">        </span><br class="webkit-block-placeholder"></p><div><div>On Feb 10, 2011, at 12:18 PM, Sara Rolfe wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><blockquote type="cite"><div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><br></div> </div><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Thanks Robert, I was hoping there might be a way to do this without iterating through the pixels, but I think you are right that this is the best way to go.<div><br><div><div>On Feb 10, 2011, at 11:09 AM, robert tamburo wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">You could create a blank RGB image, iterate the RGB image, then set pixels one by one. Something like:<br><div><br></div><div>// initialize zero filled RGB image</div><div>rgbImage = RGBImageType::New();</div><div>RGBImageType::PixelType tempPixel;</div> <div>tempPixel.Fill(0);</div> <div>rgbImage->FillBuffer(tempPixel);</div><div><br></div><div>RGBImageType::PixelType rgbPixel;</div><div><br></div><div>// iterate RGB image</div><div>RGBIteratorType it(rgbImage, rgbImage->GetLargestPossibleRegion())</div> <div> it.GoToBegin();</div><div>while(!it.IsAtEnd())</div><div>{</div><div> if(labelImage1->GetPixel(it.GetIndex() != 0)</div><div> {</div><div> // set labelImage1 pixels to green</div><div> rgbPixel[0] = 0; rgbPixel[1] = 255; rgbPixel[2] = 0;</div> <div> rgbImage->SetPixel(it.GetIndex(), rgbPixel);</div><div> }</div><div><div> else if(labelImage2->GetPixel(it.GetIndex() != 0)</div><div> {</div><div> // set labelImage2 pixels to blue</div><div> rgbPixel[0] = 0; rgbPixel[1] = 0; rgbPixel[2] = 255;</div> <div> rgbImage->SetPixel(it.GetIndex(), rgbPixel);</div><div> }</div></div><div> else</div><div> {</div><div> // copy image data for non-label pixels</div><div><div> rgbPixel.Fill(originalImage->GetPixel(it.GetIndex());</div> <div> rgbImage->SetPixel(it.GetIndex(), rgbPixel);</div></div><div> }</div><div>++it;</div><div>}</div><div><br></div><div><div>Caveats: 1) images need to be of the same size and 2) above code was written freehand without testing :)</div> <div><br></div><div><div><div><div class="gmail_quote">On Thu, Feb 10, 2011 at 1:38 PM, Sara Rolfe <span dir="ltr"><<a href="mailto:smrolfe@u.washington.edu" target="_blank">smrolfe@u.washington.edu</a>></span> wrote:<br> <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hello,<div><br></div><div>I'm attempting to overlay an image with color. I've had trouble finding documentation on this, either in ITK or VTK. The way I'm going about it is to scale the values of the image down and then use the add image filter to add the labels on top. I could then use VTK to create a corresponding colormap.</div> <div><br></div><div>However, I'm getting stuck on something that should be very simple. My operations to combine the two images are failing. I think the problem is the <span style="font-family:Monaco;font-size:10px">SubtractConstantFromImageFilter. </span>I've checked the output and it looks like the constant is not being subtracted. The input to this filter is an image with a value of 0 for the background and 255 for the object. I'd like to change these to 0 and 1. The pixel type is unsigned char. I use the following:</div> <div><span style="font-family:Monaco;font-size:10px"><br></span></div><div><span style="font-family:Monaco;font-size:10px"><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre-wrap">        </span>SubFilterType::Pointer subFilter = SubFilterType::New();</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre-wrap">        </span>InputPixelType subValue = <span style="color:#1c00cf">254</span>;</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <span style="white-space:pre-wrap">        </span>subFilter->SetConstant(subValue);</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre-wrap">        </span>subFilter->SetInput( imageInverter->GetOutput() );</div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><span style="white-space:pre-wrap">        </span>subFilter->Update();</div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <br></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font face="Helvetica"><span style="font-size:medium">But the output image is still 0 - 255. Am I missing something simple? </span></font></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font face="Helvetica"><span style="font-size:medium"><br></span></font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <font face="Helvetica"><span style="font-size:medium">Also, is there a better way to accomplish this task, or any examples showing something similar?</span></font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"> <font face="Helvetica"><span style="font-size:medium"><br></span></font></div><div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font face="Helvetica"><span style="font-size:medium">Thanks,</span></font></div> <div style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px"><font face="Helvetica"><span style="font-size:medium">Sara</span></font></div></span></div></div><br>_____________________________________<br> Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br> <br> Visit other Kitware open-source projects at<br> <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br> <br> Kitware offers ITK Training Courses, for more information visit:<br> <a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br> <br> Please keep messages on-topic and check the ITK FAQ at:<br> <a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br> <br> Follow this link to subscribe/unsubscribe:<br> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br> <br></blockquote></div><br></div></div></div></div></blockquote></div><br></div></div></blockquote></div><br></div>_____________________________________<br>Powered by <a href="http://www.kitware.com">www.kitware.com</a><br><br>Visit other Kitware open-source projects at<br><a href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><br><br>Kitware offers ITK Training Courses, for more information visit:<br>http://www.kitware.com/products/protraining.html<br><br>Please keep messages on-topic and check the ITK FAQ at:<br>http://www.itk.org/Wiki/ITK_FAQ<br><br>Follow this link to subscribe/unsubscribe:<br>http://www.itk.org/mailman/listinfo/insight-users<br></blockquote></div><br></body></html>