[Insight-users] Sobel Edge Detection: Not working in Windows XP
with VS2005
Dan Mueller
d.mueller at qut.edu.au
Thu Jan 4 17:48:40 EST 2007
Hi all,
I recently tried to use itkSobelEdgeDetectionImageFilter (source code is
at the end of this email).
In *Debug *mode the following error is thrown:
Debug Assertion Failed!
Program: ...
File: C:\Program Files\Microsoft Visual Studio 8\VC\include\vector
Line: 756
Expression: vector subscript out of range
I think this error is related to:
http://public.kitware.com/pipermail/insight-users/2007-January/020483.html.
In *Release *mode the following error is thrown:
itkTestMain.exe - Application Error
The exception unknown software exception (0xc000000d) occurred in
the application at location 0x78138a8a.
My system is as such:
Platform: Windows XP SP2
Computer: Intel Pentium 3.00 GHz, dual core
Compiler: Microsoft Visual Studio 2005 (v8.050727.363 ie. SP1 Beta)
CMake: 2.4.2
ITK: 2.8.1 (compiled in both Debug and Release modes)
I have had no problems compiling and running applications using numerous
other filters on this system. Any ideas as to the cause? Am I missing
something so obvious that I can't see it? I can not debug the issue
because of the vector subscript error described above. I have not tried
the fix proposed in the insight-users post above because this seems to
be for Debug mode only, and my error appears in Release mode also. (FYI:
the cthead1.png image is in the same directory as the produced executable.)
Thanks for your help.
Dan
*<CODE: itkTestMain.cxx>*
/*=========================================================================
itkTestMain.cxx
=========================================================================*/
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkSobelEdgeDetectionImageFilter.h"
int main()
{
// Set input variables
const char* InputImageFilename = "cthead1.png";
const char* OutputImageFilename = "cthead1_SOBEL.mhd";
// Declare types
const unsigned int Dimension = 2;
typedef float PixelType;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageFileWriter< ImageType > WriterType;
typedef itk::SobelEdgeDetectionImageFilter< ImageType, ImageType >
SobelFilterType;
try
{
// Read input image
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( InputImageFilename );
reader->Update();
// Apply Sobel Filter
SobelFilterType::Pointer filter = SobelFilterType::New();
filter->SetInput( reader->GetOutput() );
filter->Update();
// Write output image
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( OutputImageFilename );
writer->SetInput( filter->GetOutput() );
writer->Update();
}
catch (itk::ExceptionObject & err)
{
std::cout << "ExceptionObject caught !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
//Return
return EXIT_SUCCESS;
}
*</CODE**: itkTestMain.cxx**>*
*<CODE: CMakeLists.txt>*
#Set the project
PROJECT(TestMain)
#Include some macros from another file...
INCLUDE(${CMAKE_SOURCE_DIR}/IJMacros.txt)
#Setup required paths
SET(IMAGES_PATH ${CMAKE_SOURCE_DIR}/Images)
SET(SOURCE_PATH ${CMAKE_SOURCE_DIR}/Source)
SET(LIBRARY_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin CACHE PATH "Single
output directory for building all libraries." FORCE)
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/bin CACHE PATH "Single
output directory for building all executables." FORCE)
SET(TESTING_OUTPUT_PATH ${CMAKE_SOURCE_DIR}/Testing/Temporary)
#The following lines are required to use Dart
ENABLE_TESTING()
INCLUDE(Dart)
FIND_PROGRAM(IMAGE_COMPARE ImageCompare)
#Declare any external dependencies that your project may have here.
#examples include: ITK, VTK, JPEG, PNG, OpenGL, ZLIB, Perl, Java
#If you're not sure what name to use, look in the Modules directory of your
#cmake install and check that a file named Find(Package).cmake exists
SET(Required_Packages
ITK
)
#this foreach loads all of the packages that you specified as required.
#It shouldn't need to be modified.
FOREACH(Package ${Required_Packages})
LOADPACKAGE(${Package})
ENDFOREACH(Package)
#Construct VXL/VNL includes
SET(VXL_INCLUDE_DIRS
${ITK_SOURCE_DIR}/Utilities/vxl
${ITK_SOURCE_DIR}/Utilities/vxl/core
${ITK_SOURCE_DIR}/Utilities/vxl/core/vnl
${ITK_SOURCE_DIR}/Utilities/vxl/vcl)
#Set any libraries that your project depends on.
#examples: ITKCommon, VTKRendering, etc
SET(VXL_NUMERICS_LIBRARIES
itkvnl
itkvnl_algo
itknetlib)
SET(ITK_LIBRARIES
ITKIO
ITKCommon
ITKNumerics
ITKBasicFilters
${VXL_NUMERICS_LIBRARIES}
)
#Add Source
SUBDIRS(Source)
#Add Testing
OPTION(BUILD_TESTING "Build the Testing directory." OFF)
IF(BUILD_TESTING)
#SUBDIRS(Testing)
ENDIF(BUILD_TESTING)
*</ CODE**: CMakeLists.txt**>*
Matei Stroila wrote:
> First of all, Happy New Year!
>
> Thanks all for this wonderful software library! It is an exemplary
> model of open source software that helps progress go on.
>
> Now, going back to the VS 2005 settings:
>
> Luis,
>
> I added
>
> #cmakedefine _SECURE_SCL=0
> #cmakedefine _HAS_ITERATOR_DEBUGGING=0
>
> in itkConfigure.h.in.
>
> The itkConfigure.h in the build dir becomes:
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> /*
> * here is where system computed values get stored these values should
> only
> * change when the target compile platform changes
> */
>
> /* what byte order */
> /* #undef CMAKE_WORDS_BIGENDIAN */
> #ifdef CMAKE_WORDS_BIGENDIAN
> #define ITK_WORDS_BIGENDIAN
> #endif
>
> /* what threading system are we using */
> /* #undef CMAKE_USE_PTHREADS */
> #ifdef CMAKE_USE_PTHREADS
> #define ITK_USE_PTHREADS
> #endif
>
> /* #undef CMAKE_USE_SPROC */
> #ifdef CMAKE_USE_SPROC
> #define ITK_USE_SPROC
> #endif
>
> /* #undef CMAKE_HP_PTHREADS */
> #ifdef CMAKE_HP_PTHREADS
> #define ITK_HP_PTHREADS
> #endif
>
> #define CMAKE_USE_WIN32_THREADS
> #ifdef CMAKE_USE_WIN32_THREADS
> #define ITK_USE_WIN32_THREADS
> #endif
>
> /* #undef ITK_BUILD_SHARED_LIBS */
> #ifdef ITK_BUILD_SHARED_LIBS
> #define ITKDLL
> #else
> #define ITKSTATIC
> #endif
>
> /* #undef CMAKE_NO_STD_NAMESPACE */
> /* #undef CMAKE_NO_ANSI_STREAM_HEADERS */
> /* #undef CMAKE_NO_ANSI_STRING_STREAM */
> /* #undef CMAKE_NO_ANSI_FOR_SCOPE */
> #define ITK_CPP_FUNCTION
> /* #undef ITK_USE_CONCEPT_CHECKING */
> /* #undef ITK_EXPLICIT_INSTANTIATION */
> /* #undef USE_FFTWF */
> /* #undef USE_FFTWD */
> /* #undef _SECURE_SCL=0 */
> /* #undef _HAS_ITERATOR_DEBUGGING=0 */
>
> #define ITK_VERSION_MAJOR 3
> #define ITK_VERSION_MINOR 1
> #define ITK_VERSION_PATCH 0
> #define ITK_VERSION_STRING "3.1"
> //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
>
> The _SECURE_SCL and _HAS_ITERATOR_DEBUGGING do not get defined,
> neither in the ITK library nor in projects depending on it.
>
> On the other hand, if I add:
>
> #define _SECURE_SCL 0
> #define _HAS_ITERATOR_DEBUGGING 0
>
> in the itkConfigure.h.in, then they appear as is in itkConfigure.h but
> I get compile errors in
> C:\Program Files\Microsoft Visual Studio 8\VC\include\deque:
>
> Error 21 error C2248: 'std::deque<_Ty>::_Myoff' : cannot access
> protected member declared in class 'std::deque<_Ty>' C:\Program
> Files\Microsoft Visual Studio 8\VC\include\deque 132
>
> So, for now I will keep the definitions in CMakeLists.txt since that
> works well.
>
> Matei
>
>
> On 12/31/06, Luis Ibanez <luis.ibanez at kitware.com> wrote:
>>
>> Hi Matei,
>>
>> When adding cmakedefine statements to itkConfigure.h.in,
>> they will only appear in the file
>>
>> itkConfigure.h
>>
>> that CMake generates in the Binary directory where you are
>> building ITK (and the install directory,... if you are
>> installing ITK after building it).
>>
>>
>> The symbol does not appear in the CMake configuration editor, and
>> it does not appear in the properties of Visual Studio IDE. This
>> is normal. It is actually part of the advantages of defining the
>> symbol in the itkConfigure.h.in file.
>>
>>
>> Since itkConfigure.h is included by almost all ITK files, the symbol
>> will be used all through your build.
>>
>>
>> For a simple verification you can try adding in your
>> code something like:
>>
>>
>> #ifndef _HAS_ITERATOR_DEBUGGING
>> #error ITERATOR_DEBUGING_NOT_DEFINED
>> #endif
>>
>>
>>
>> Please let us know if you find an indication that the symbol does
>> not get defined correctly.
>>
>>
>> Thanks
>>
>>
>> Luis
>>
>>
>>
>> ---------------------
>> Matei Stroila wrote:
>> > I added
>> >
>> > # cmakedefine _HAS_ITERATOR_DEBUGGING=0
>> >
>> > to Insight/itkConfigure.h.in, line 49
>> >
>> > but I don't see it in the CMake configuration editor, neither in the
>> > Properties Window of the ITK projects. It does not look like they are
>> > using it.
>> >
>> > Also, for people intersted in using VS 2005, this define is also
>> necessary:
>> > _SECURE_SCL=0
>> >
>> >
>> > Matei
>> >
>> > On 12/27/06, Luis Ibanez <luis.ibanez at kitware.com> wrote:
>> >
>> >>
>> >> Hi Matei, Karthik
>> >>
>> >>
>> >> Thanks for tracking this issue.
>> >>
>> >>
>> >> Just for the record:
>> >>
>> >> a better place for adding definitions is the file:
>> >>
>> >>
>> >> Insight/itkConfigure.h.in
>> >>
>> >>
>> >> Where you could add the line 49:
>> >>
>> >>
>> >> cmakedefine _HAS_ITERATOR_DEBUGGING=0
>> >>
>> >>
>> >> The advantage of adding the definition here instead of the
>> >> CMakeLists.txt file is that in the itkConfigure.h file, the
>> >> definition is actually passed also to the projects that use
>> >> ITK, while the definitions in CMakeLists.txt are used only
>> >> while building ITK.
>> >>
>> >>
>> >>
>> >> Regards,
>> >>
>> >>
>> >>
>> >> Luis
>> >>
>> >>
>> >> ----------------------
>> >> Matei Stroila wrote:
>> >> > Thank you very much.
>> >> >
>> >> > I added -D_HAS_ITERATOR_DEBUGGING=0 in Insight\CMakeLists.txt :
>> >> >
>> >> > IF(WIN32)
>> >> > IF(NOT BORLAND)
>> >> > IF(NOT CYGWIN)
>> >> > IF(NOT MINGW)
>> >> > ADD_DEFINITIONS(
>> >> > -D_HAS_ITERATOR_DEBUGGING=0
>> >> > )
>> >> > ENDIF(NOT MINGW)
>> >> > ENDIF(NOT CYGWIN)
>> >> > ENDIF(NOT BORLAND)
>> >> > ENDIF(WIN32)
>> >> >
>> >> >
>> >> > Recompiled and my program runs fine in debug.
>> >> >
>> >> >> Please log this issue as an entry in the bug tracker.
>> >> >>
>> >> >
>> >> > Sure, I will do it now.
>> >> >
>> >> > Thanks,
>> >> >
>> >> > Matei
>> >> >
>> >>
>> >
>>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070105/4565d953/attachment-0001.htm
More information about the Insight-users
mailing list