<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Brad,<div><br></div><div>Thanks for your suggestion. When I swap in the MorphologicalWatershedImageFilter it works correctly. I think you're right that there's a bug in the WatershedImageFilter causing this behavior.</div><div><br></div><div>Thanks,</div><div>Sara</div><div><br></div><div><br><div><div>On Oct 11, 2012, at 12:15 PM, Bradley Lowekamp wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=us-ascii"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello Sara,<div><br></div><div>At first glance I don't see any thing wrong with your code. You may have encountered a bug with itk::WatershedImageFilter when it is heavily re-use, but that would require some detailed checking.</div><div><br></div><div>As a quick fix you could try the itk::MorphologicalWatershedImageFilter which is in review instead and see if you get the results you are looking for.</div><div><br></div><div>Brad</div><div><br><div><div>On Oct 11, 2012, at 2:54 PM, Sara Rolfe <<a href="mailto:smrolfe@u.washington.edu">smrolfe@u.washington.edu</a>> 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; "><span class="Apple-style-span" style="font-family: Monaco; font-size: 10px; ">Hello, </span><div style="font-family: Monaco; font-size: 10px; "><br></div><div style="font-family: Monaco; font-size: 10px; ">I am attempting to do a slice-by-slice watershed segmentation of a 3D image. First, I got the watershed segmentation working correctly on a 2D image. Next, I tried to implement it with the SliceBySliceImageFilter. I connected the SliceBySliceImageFilter to a pipeline with the gradient filter as the input filter and the watershed filter as the output. Running gave me a continuous output of the following error:</div><div style="font-family: Monaco; font-size: 10px; "><br></div><div style="font-family: Monaco; font-size: 10px; "><div>WaterShedFilter_SBS(5879,0xa0689720) malloc: *** error for object 0x48c187c: Non-aligned pointer being freed</div><div>*** set a breakpoint in malloc_error_break to debug</div><div>...</div></div><div style="font-family: Monaco; font-size: 10px; "><br></div><div style="font-family: Monaco; font-size: 10px; ">I have read the article on the slice-by-slice filter <a href="http://www.insight-journal.org/browse/publication/133">http://www.insight-journal.org/browse/publication/133</a> and have gotten it working with the gradient filter alone and a pipeline of two gradient filters. However, when I put in the watershed filter alone or with the gradient filter, I get the above error. I'd appreciate any advice. An excerpt of my code is below.</div><div style="font-family: Monaco; font-size: 10px; "><br></div><div style="font-family: Monaco; font-size: 10px; ">Thanks,</div><div style="font-family: Monaco; font-size: 10px; ">Sara</div><div style="font-family: Monaco; font-size: 10px; "><br></div><div style="font-family: Monaco; font-size: 10px; "><br></div><div style="font-family: Monaco; font-size: 10px; "><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: rgb(170, 13, 145); ">const</span> <span style="color: rgb(170, 13, 145); ">int</span> inputDim =<span style="color: rgb(28, 0, 207); ">3</span>; </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: rgb(170, 13, 145); ">const</span> <span style="color: rgb(170, 13, 145); ">int</span> sliceDim =<span style="color: rgb(28, 0, 207); ">2</span>; </div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: rgb(170, 13, 145); ">typedef</span> itk::Image<<span style="color: rgb(170, 13, 145); ">float</span>, inputDim><span class="Apple-tab-span" style="white-space: pre; ">                                                                                                        </span>InputImageType;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: rgb(170, 13, 145); ">typedef</span> itk::Image<<span style="color: rgb(170, 13, 145); ">unsigned</span> <span style="color: rgb(170, 13, 145); ">long</span>, inputDim><span class="Apple-tab-span" style="white-space: pre; ">                                                                                                </span>OutputImageType;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: rgb(170, 13, 145); ">typedef</span> itk::Image<<span style="color: rgb(170, 13, 145); ">float</span>, sliceDim><span class="Apple-tab-span" style="white-space: pre; ">                                                                                                        </span>SliceFloatImageType;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: rgb(170, 13, 145); ">typedef</span> itk::ImageFileReader< InputImageType ><span class="Apple-tab-span" style="white-space: pre; ">                                                                                                </span>ReaderType;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: rgb(170, 13, 145); ">typedef</span> itk::GradientMagnitudeImageFilter< SliceFloatImageType, </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>SliceFloatImageType ><span class="Apple-tab-span" style="white-space: pre; ">                                                                                                                </span>GradientMagnitudeImageFilterType;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: rgb(170, 13, 145); ">typedef</span> itk::WatershedImageFilter<SliceFloatImageType><span class="Apple-tab-span" style="white-space: pre; ">                                                                                        </span>WatershedFilterType;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><span style="color: rgb(170, 13, 145); ">typedef</span> itk::SliceBySliceImageFilter< InputImageType,</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>OutputImageType,GradientMagnitudeImageFilterType,</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>WatershedFilterType ><span class="Apple-tab-span" style="white-space: pre; ">                                                                                                                </span>SliceBySliceFilterType;</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><br></div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><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>InputImageType::Pointer inputImage = reader->GetOutput();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; "><br></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>GradientMagnitudeImageFilterType::Pointer gradientMagnitudeImageFilter = GradientMagnitudeImageFilterType::New();</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><br></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>WatershedFilterType::Pointer watershedFilter = WatershedFilterType::New();</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>watershedFilter->SetThreshold(threshold);</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>watershedFilter->SetLevel(level);</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>watershedFilter->SetInput(gradientMagnitudeImageFilter->GetOutput());</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">        </span><br class="webkit-block-placeholder"></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>SliceBySliceFilterType::Pointer sliceBySliceFilter = SliceBySliceFilterType::New();</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>sliceBySliceFilter -> SetInput(inputImage);</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>sliceBySliceFilter -> SetInputFilter(gradientMagnitudeImageFilter);</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>sliceBySliceFilter -> SetOutputFilter(watershedFilter);</div><div style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 10px/normal Monaco; min-height: 14px; "><span class="Apple-tab-span" style="white-space: pre; ">        </span>sliceBySliceFilter->Update();</div><div><br></div></div></div></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><a href="http://www.kitware.com/products/protraining.php">http://www.kitware.com/products/protraining.php</a><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></div></div></blockquote></div><br></div></body></html>