[ITK] Error in itk::BinaryImageToLabelMapFilter for images with 1 row and N columns
Bradley Lowekamp
blowekamp at mail.nih.gov
Thu Jul 31 09:34:25 EDT 2014
Hello,
Thank you for reporting this. This looks like it may be a bug inside ITK. However it would be good to make this a little more reproducible to aid in debugging.
1) Is the OtsuThreshold required? If you write out the results of the otsu to a file, then just loaded them in this test case will it still have the error?
2) I don't have your data which causes this failure. How big is it? Does it fail with all data this shape? Could you change this test case to have a hard coded image? One that is procedurally created?
Thanks again for reporting this issue.
Brad
On Jul 31, 2014, at 5:35 AM, Girish Mallya Udupi <indianzeppelin at gmail.com> wrote:
> Hi all,
>
> I am new to both C++ and ITK, and have been fiddling with test code for learning purposes.
>
> The following is a simple piece of code to read in a grayscale image, threshold it to get a binary image, and get a label map out of it. I use MS VS2010 and ITK v4.5.1.
>
>
> typedef itk::Image< unsigned char, 2 > ScalarImageType;
>
> typedef itk::ImageFileWriter< ScalarImageType > WriterType;
> typedef itk::ImageFileReader< ScalarImageType > ReaderType;
>
> typedef itk::OtsuThresholdImageFilter< ScalarImageType, ScalarImageType > OtsuThresholdImageFilterType;
> typedef itk::BinaryImageToLabelMapFilter< ScalarImageType > BinaryImageToLabelMapFilterType;
>
> // read a grayscale image
> ReaderType::Pointer reader = ReaderType::New();
> reader->SetFileName("test_grey.jpg");
> try
> {
> reader->Update();
> }
> catch( itk::ExceptionObject &err )
> {
> std::cerr << "ExceptionObject caught !" << std::endl;
> std::cerr << err << std::endl;
> return(FALSE);
> }
>
> // threshold the grayscale image
> OtsuThresholdImageFilterType::Pointer otsuThresImgFilter = OtsuThresholdImageFilterType::New();
> otsuThresImgFilter->SetInput(reader->GetOutput());
> otsuThresImgFilter->SetInsideValue(255);
> otsuThresImgFilter->SetOutsideValue(0);
> try
> {
> otsuThresImgFilter->Update();
> }
> catch( itk::ExceptionObject &err )
> {
> std::cerr << "ExceptionObject caught !" << std::endl;
> std::cerr << err << std::endl;
> return(FALSE);
> }
>
> // get a label map from the binary image
> BinaryImageToLabelMapFilterType::Pointer binarytoLabelmapFilter = BinaryImageToLabelMapFilterType::New();
> binarytoLabelmapFilter->SetInput(otsuThresImgFilter->GetOutput());
> try
> {
> binarytoLabelmapFilter->Update();
> }
> catch( itk::ExceptionObject &err )
> {
> std::cerr << "ExceptionObject caught !" << std::endl;
> std::cerr << err << std::endl;
> return(FALSE);
> }
>
> This works fine for all images, except those which have only 1 row and N columns (interestingly, 1 x 1 images go through fine).
>
> So, for 1 x N images, the program crashes in release mode. In debug mode, I get the "vector subscript out of range" error. Stepping through the code, I found that the crash happens on the line binarytoLabelmapFilter->Update(); of my code.
>
> Call stack:
>
>
> msvcr100d.dll!_CrtDbgBreak() Line 85 C
> msvcr100d.dll!_VCrtDbgReportW(int nRptType, const wchar_t * szFile, int nLine, const wchar_t * szModule, const wchar_t * szFormat, char * arglist) Line 502 C
> msvcr100d.dll!_CrtDbgReportWV(int nRptType, const wchar_t * szFile, int nLine, const wchar_t * szModule, const wchar_t * szFormat, char * arglist) Line 241 + 0x1d bytes C++
> msvcr100d.dll!_CrtDbgReportW(int nRptType, const wchar_t * szFile, int nLine, const wchar_t * szModule, const wchar_t * szFormat, ...) Line 258 + 0x1d bytes C++
> msvcp100d.dll!std::_Debug_message(const wchar_t * message, const wchar_t * file, unsigned int line) Line 13 + 0x16 bytes C++
> HelloWorld.exe!std::vector<std::vector<itk::BinaryImageToLabelMapFilter<itk::Image<unsigned char,2>,itk::LabelMap<itk::LabelObject<unsigned long,2> > >::runLength,std::allocator<itk::BinaryImageToLabelMapFilter<itk::Image<unsigned char,2>,itk::LabelMap<itk::LabelObject<unsigned long,2> > >::runLength> >,std::allocator<std::vector<itk::BinaryImageToLabelMapFilter<itk::Image<unsigned char,2>,itk::LabelMap<itk::LabelObject<unsigned long,2> > >::runLength,std::allocator<itk::BinaryImageToLabelMapFilter<itk::Image<unsigned char,2>,itk::LabelMap<itk::LabelObject<unsigned long,2> > >::runLength> > > >::operator[](unsigned int _Pos) Line 932 + 0x17 bytes C++
> HelloWorld.exe!itk::BinaryImageToLabelMapFilter<itk::Image<unsigned char,2>,itk::LabelMap<itk::LabelObject<unsigned long,2> > >::ThreadedGenerateData(const itk::ImageRegion<2> & outputRegionForThread, unsigned int threadId) Line 190 + 0x1c bytes C++
> HelloWorld.exe!itk::ImageSource<itk::LabelMap<itk::LabelObject<unsigned long,2> > >::ThreaderCallback(void * arg) Line 295 + 0x25 bytes C++
> HelloWorld.exe!itk::MultiThreader::SingleMethodProxy(void * arg) Line 375 + 0xe bytes C++
> msvcr100d.dll!_callthreadstartex() Line 314 + 0xf bytes C
> msvcr100d.dll!_threadstartex(void * ptd) Line 297 C
> kernel32.dll!773f338a()
> [Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
> ntdll.dll!77a49f72()
> ntdll.dll!77a49f45()
> Being a novice, I am not sure if it is an issue in ITK or if it is due to something I am doing wrong.
>
>
>
>
> --
> Regards,
> Girish
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140731/8eb8b998/attachment-0002.html>
More information about the Community
mailing list