[ITK] Fwd: Error in itk::BinaryImageToLabelMapFilter for images with 1 row and N columns
Girish Mallya Udupi
indianzeppelin at gmail.com
Thu Jul 31 05:35:18 EDT 2014
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 imageReaderType::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 imageOtsuThresholdImageFilterType::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
imageBinaryImageToLabelMapFilterType::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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140731/d344cbbd/attachment-0001.html>
More information about the Community
mailing list