<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi,<div><br></div><div>That is what the BoundingBoxImageLabelMapFilter is suppose to do. It crops an axis aligned bounding box around a label in the label map infrastructure.</div><div><br></div><div>What are you trying to do?</div><div><br></div><div>And why did you try this approach?</div><div><br></div><div>There is the MaskImageFilter[1] that may suit your needs.</div><div><br></div><div>Brad</div><div><br></div><div>[1] <a href="http://www.itk.org/Doxygen/html/classitk_1_1MaskImageFilter.html">http://www.itk.org/Doxygen/html/classitk_1_1MaskImageFilter.html</a></div><div><br><div><div>On Nov 13, 2013, at 8:25 AM, elhadj meljane <<a href="mailto:elhadj.meljane@gmail.com">elhadj.meljane@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><div dir="ltr"><div>Hi Bradley,</div><div>Thanks, it worked when I added a label image. But it crops the item in a smaller image. Is there a way to keep the initial image size: just mask the other items in the initial image ...</div>
<div> </div><div>Thanks.</div><div>Best,</div><div>EM </div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Nov 12, 2013 at 9:50 PM, Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style=""><div class="im">Hello,<div><br></div><div>Around ITK programs you need exception handling to determine the errors thrown.</div>
<div><br></div><div>I added the following around your code:</div><div><br></div><div>try</div><div>{</div><div>...</div><div><div>}</div><div>catch (std::exception &e)</div><div> {</div><div>std::cerr << "Exception: " << e.what() << std::endl;</div>
<div>return 1;</div><div>}</div><div>catch (...)</div><div> {</div><div>std::cerr << "Unknown Exception!" << std::endl;</div><div>throw;</div><div>}</div></div><div><br></div><div>Note that the itk::ExceptionObject class is derived from std::exception so this will catch that too.</div>
<div><br></div><div>The gave me the following output:</div><div><br></div><div><div>Exception: /Users/blowekamp/src/ITK/Modules/Core/Common/src/itkProcessObject.cxx:1380:</div><div>itk::ERROR: BoundingBoxImageLabelMapFilter(0x7f92bb8bce90): Input FeatureImage is required but not set.</div>
</div><div><br></div><div>Which says you are missing an input to this filter.</div><div><br></div><div>You can provide the input label image as the feature image like so:</div><div><br></div><div>toBBILabelMap->SetFeatureImage(reader->GetOutput());</div>
<div><br></div><div>The examples in that modules should be usable. You just need to get your labels correct for the binary/label image. Not too hard to run a ConnectedComponets filter if needed.</div><div><br></div></div>
<div><div class="h5"><div>Brad</div><div><br></div><div><div>On Nov 12, 2013, at 2:43 PM, elhadj meljane <<a href="mailto:elhadj.meljane@gmail.com" target="_blank">elhadj.meljane@gmail.com</a>> wrote:</div><br><blockquote type="cite">
<div dir="ltr"><div> I don't have a label image to use the example: <a href="https://github.com/blowekamp/itkOBBLabelMap/blob/master/test/itkOBBExample.cxx" target="_blank"><font color="#0066cc">https://github.com/blowekamp/</font><font color="#0066cc">itkOBBLabelMap/blob/master/</font><font color="#0066cc">test/itkOBBExample.cxx</font></a></div>
<div> </div><div>However, I used to write the main method ... where only a binary image is used as input. </div><div> </div><div>Thanks!</div><div>EM </div></div><div class="gmail_extra"><br><br><div class="gmail_quote">
On Tue, Nov 12, 2013 at 2:26 PM, elhadj meljane <span dir="ltr"><<a href="mailto:elhadj.meljane@gmail.com" target="_blank">elhadj.meljane@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir="ltr"><div class="gmail_extra">Hello!</div><div class="gmail_extra">
I am using your github extension (I included the files manually in my project)... and wrote the main method below. The code compile but at the run time I got the error: </div>
<div class="gmail_extra"><br>"program.exe has stopped working. A problem caused the program to stop working correctly. Windows will close the program and notify you if a solution is available. "</div><div class="gmail_extra">
When I click to debug with MS Visual Studio, I got the warning: <br>Unhandled exception at 0x01... in program.exe: 0xC00000005: Acces violation reading location 0x18...</div><div class="gmail_extra"> </div><div class="gmail_extra">
Here's the code: </div><div class="gmail_extra"> </div><div class="gmail_extra"><font face="Consolas">
<font color="#0000ff"><font color="#0000ff"><font color="#0000ff"></font></font></font></font><p><font face="Consolas"><font color="#0000ff"><font color="#0000ff"><font color="#0000ff">#include</font></font></font><font><font> </font></font><font color="#a31515"><font color="#a31515"><font color="#a31515">"itkImageFileReader.h"</font></font></font></font></p>
<font color="#a31515" face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">#include</font><font face="Consolas"> </font><font color="#a31515" face="Consolas">"itkImageFileWriter.h"</font></p>
<font color="#a31515" face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">#include</font><font face="Consolas"> </font><font color="#a31515" face="Consolas">"itkBoundingBoxImageLabelMapFilter.h"</font></p>
<font color="#a31515" face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">#include</font><font face="Consolas"> </font><font color="#a31515" face="Consolas">"itkAttributeImageLabelObject.h"</font></p>
<font color="#a31515" face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">#include</font><font face="Consolas"> </font><font color="#a31515" face="Consolas">"itkBinaryImageToShapeLabelMapFilter.h"</font><font face="Consolas"> </font></p>
<div>
<font face="Consolas"><div> <br></div>
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">const</font><font face="Consolas"> </font><font color="#0000ff" face="Consolas">unsigned</font><font face="Consolas"> </font><font color="#0000ff" face="Consolas">int</font><font face="Consolas"> Dimension = 2;</font></p>
<font face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">typedef</font><font face="Consolas"> </font><font color="#0000ff" face="Consolas">unsigned</font><font face="Consolas"> </font><font color="#0000ff" face="Consolas">char</font><font face="Consolas"> LabelPixelType;</font></p>
<font face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">typedef</font><font face="Consolas"> itk::Image< LabelPixelType, Dimension > LabelImageType;</font></p>
<font face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">typedef</font><font face="Consolas"> </font><font color="#0000ff" face="Consolas">unsigned</font><font face="Consolas"> </font><font color="#0000ff" face="Consolas">char</font><font face="Consolas"> OutputPixelType;</font></p>
<font face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">typedef</font><font face="Consolas"> itk::Image< OutputPixelType, Dimension > OutputImageType;</font></p>
<font face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">typedef</font><font face="Consolas"> itk::ImageFileReader< OutputImageType > ReaderType;</font></p>
<font face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">typedef</font><font face="Consolas"> itk::ImageFileWriter< OutputImageType > WriterType;</font></p>
<font face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">typedef</font><font face="Consolas"> itk::AttributeImageLabelObject< LabelPixelType, Dimension, OutputImageType > LabelObjectAttributeType;</font></p>
<font face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">typedef</font><font face="Consolas"> itk::LabelMap<LabelObjectAttributeType> LabelMapAttributeType;</font></p>
<font face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">typedef</font><font face="Consolas"> itk::BinaryImageToShapeLabelMapFilter </font></p>
<font face="Consolas"><p> <OutputImageType, LabelMapAttributeType> LabelMapperAttributeType;</p>
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">typedef</font><font face="Consolas"> itk::LabelMapToLabelImageFilter<LabelMapAttributeType, OutputImageType> LabelMapToLabelImageFilterType;</font></p>
<font face="Consolas">
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font><p><font color="#0000ff" face="Consolas">typedef</font><font face="Consolas"> itk::BoundingBoxImageLabelMapFilter<LabelMapAttributeType> BBILabelMapFilter;</font></p>
<font face="Consolas"><div> <br></div><div> <br></div>
</font><font color="#0000ff" face="Consolas"><font color="#0000ff" face="Consolas"></font></font></div><p><font color="#0000ff" face="Consolas">int</font><font face="Consolas"> main( </font><font color="#0000ff" face="Consolas">int</font><font face="Consolas"> argc, </font><font color="#0000ff" face="Consolas">char</font><font face="Consolas"> *argv[] )</font></p>
<div>
<font face="Consolas"><p>{</p><div> <br></div><p> ReaderType::Pointer reader = ReaderType::New();</p>
</font></div><p><font face="Consolas"> </font><font color="#0000ff" face="Consolas">typedef</font><font face="Consolas"> itk::ImageFileWriter< OutputImageType > WriterType;</font></p>
<font face="Consolas"><div> <br></div>
</font><p><font face="Consolas"> </font><font color="#008000" face="Consolas">//input</font></p>
<div>
<font color="#008000" face="Consolas">
</font><font face="Consolas"><p> reader->SetFileName( argv[1] );</p><div> <br></div>
</font></div><p><font face="Consolas"> </font><font color="#008000" face="Consolas">//label image </font></p>
<div>
<font color="#008000" face="Consolas">
</font><font face="Consolas"><p> LabelMapperAttributeType::Pointer labelerAttribute = LabelMapperAttributeType::New();</p><p> labelerAttribute->SetInput( reader->GetOutput() );</p>
</font><p><font face="Consolas"> labelerAttribute->SetComputePerimeter( </font><font color="#0000ff" face="Consolas">false</font><font face="Consolas"> ); </font></p>
</div><font face="Consolas"><p> labelerAttribute->SetOutputBackgroundValue(0); </p><p> labelerAttribute->Update(); </p><p> LabelMapAttributeType::Pointer labelMapAttribute = labelerAttribute->GetOutput(); </p><div>
<br></div>
</font><p><font face="Consolas"> </font><font color="#008000" face="Consolas">//extract the component with the label 1</font></p>
<div>
<font color="#008000" face="Consolas">
</font><font face="Consolas"><p> BBILabelMapFilter::Pointer toBBILabelMap = BBILabelMapFilter::New();</p><p> toBBILabelMap->SetInput(labelMapAttribute);</p><p> toBBILabelMap->Update();</p>
</font><p><font face="Consolas"> </font><font color="#0000ff" face="Consolas">const</font><font face="Consolas"> LabelObjectAttributeType* labelObjectAttribute = toBBILabelMap->GetOutput()->GetLabelObject(1);</font></p>
<font face="Consolas"><div> <br></div>
</font></div><p><font face="Consolas"> </font><font color="#008000" face="Consolas">//write </font></p>
<font color="#008000" face="Consolas">
</font><font face="Consolas"><p> WriterType::Pointer writer = WriterType::New();</p>
</font><p><font face="Consolas"> writer->SetFileName( </font><font color="#a31515" face="Consolas">"copy_input.jpg"</font><font face="Consolas"> );</font></p>
<font face="Consolas"><p> writer->SetInput( reader->GetOutput());</p><p> writer->Update();</p><div> <br></div>
</font><p><font face="Consolas"> </font><font color="#0000ff" face="Consolas">return</font><font face="Consolas"> 0;</font></p>
<font face="Consolas"><font face="Consolas"><p>}</p><div> <br></div><div> <br></div><div> <br></div></font></font><br></div><div><div class="gmail_extra"> </div><div class="gmail_extra"> </div><div class="gmail_extra">
<br> </div><div class="gmail_quote">On Tue, Nov 12, 2013 at 1:53 PM, Bradley Lowekamp <span dir="ltr"><<a href="mailto:blowekamp@mail.nih.gov" target="_blank">blowekamp@mail.nih.gov</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1px;border-left-style:solid">Hello,<div><br></div><div>It appears that you are trying to use some code from my github extension:</div>
<div><br></div><div><a href="https://github.com/blowekamp/itkOBBLabelMap" target="_blank">https://github.com/blowekamp/itkOBBLabelMap</a></div><div><br></div><div>I am not sure where to begin helping you. You didn't include the run-time error message, and your code fragment is missing key parts. Can you post a minimal compilable example which illustrates the problem? Sometime just narrowing down you code to this part help you figure out your issue.</div>
<div><br></div><div>Do the tests for the extension pass for you?</div><div><br></div><div>Are you able to run the example?</div><div><br></div><div><a href="https://github.com/blowekamp/itkOBBLabelMap/blob/master/test/itkOBBExample.cxx" target="_blank">https://github.com/blowekamp/itkOBBLabelMap/blob/master/test/itkOBBExample.cxx</a></div>
<div><br></div><div>Brad</div><div><br></div><div><br><div><div><div>On Nov 12, 2013, at 1:43 PM, elhadj meljane <<a href="mailto:elhadj.meljane@gmail.com" target="_blank">elhadj.meljane@gmail.com</a>> wrote:</div>
<br></div><blockquote type="cite"><div><div dir="ltr"><div>Hi all, <br>I am trying to use itk to select a component from a binary image. The binary image contains several items and I want to separate them in different images.<br>
<br>I used the code below but it doesn't work. I got an error message at the run time. It looks from the debugger that the line </div>
<div> </div><div>labelerAttribute->Update() </div><div> </div><div>causes the error. I gave a valid file as input and checked that ITK reads correctly this file. I would appreciate your help to fix this! </div><p><br>
#include "itkAttributeImageLabelObject.h"</p><p>const unsigned int Dimension = 2;<br>typedef unsigned char LabelPixelType;<br>typedef itk::Image< LabelPixelType, Dimension > LabelImageType;<br>
typedef unsigned char OutputPixelType;<br> typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<br>typedef itk::ImageFileReader< OutputImageType > ReaderType;<br>typedef itk::ImageFileWriter< OutputImageType > WriterType;<br>
typedef itk::AttributeImageLabelObject< LabelPixelType, Dimension, OutputImageType > LabelObjectAttributeType;<br> typedef itk::LabelMap<LabelObjectAttributeType> LabelMapAttributeType;<br>typedef itk::BinaryImageToShapeLabelMapFilter <br>
<OutputImageType, LabelMapAttributeType> LabelMapperAttributeType;<br>typedef itk::LabelMapToLabelImageFilter<LabelMapAttributeType, OutputImageType> LabelMapToLabelImageFilterType;<br> typedef itk::BoundingBoxImageLabelMapFilter<LabelMapAttributeType> BBILabelMapFilter;<br>
typedef itk::ImageFileWriter< OutputImageType > WriterType;</p><p>ReaderType::Pointer reader = ReaderType::New();</p><p>reader->SetFileName( argv[1] );<br> <br>LabelMapperAttributeType::Pointer labelerAttribute = LabelMapperAttributeType::New();</p>
<div><br>labelerAttribute->SetInput( reader->GetOutput() );<br>labelerAttribute->SetComputePerimeter( false ); <br> labelerAttribute->SetOutputBackgroundValue(0); <br>labelerAttribute->Update();</div><div>
</div>
<div> </div><div>//select the item with the label 1</div><p>const LabelObjectAttributeType* labelObjectAttribute = toBBILabelMap->GetOutput()->GetLabelObject(1);</p><p>BBILabelMapFilter::Pointer toBBILabelMap = BBILabelMapFilter::New();<br>
toBBILabelMap->SetInput(labelMapAttribute);<br>toBBILabelMap->Update();</p><p><br>Thanks.<br>Best <br><span><font color="#888888">EM </font></span></p></div></div>
_______________________________________________<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://kitware.com/products/protraining.php" target="_blank">http://kitware.com/products/protraining.php</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-developers" target="_blank">http://www.itk.org/mailman/listinfo/insight-developers</a><br>
</blockquote></div><br></div></blockquote></div><div class="gmail_extra"><br></div></div></div>
</blockquote></div><br></div>
</blockquote></div><br></div></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://kitware.com/products/protraining.php" target="_blank">http://kitware.com/products/protraining.php</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-developers" target="_blank">http://www.itk.org/mailman/listinfo/insight-developers</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div></body></html>