[Insight-users] ConnectedThresholdImageFilter does take into accopunt the configuration

Daanen Vincent daanen at koelis.com
Tue Oct 13 08:19:13 EDT 2009


Hi Luis,

> This is really bad    :-)

Yes it is

> If you have code that works in Debug mode,
> but crashes in Release mode you probably have:
> 
>    A) Uninitialized variables
>    B) Dangling pointers
>    C) Out of bounds pointer access
>    D) An application build with inconsistent libraries

Well, this small application is just dedicated to unit-testing the use of
this itk filter. I just 
	- load an image, 
	- write it on disk,
	- process it with ConnectedThresholdImageFilter 
	- write the result on disk

The only pointer I have is the "itkImage::Pointer" 

> None of those diseases are benign...
Yep

> BTW, I this the same application where you are using
> the /FORCE flag to get over some link warnings ?

No, as I mentionned it above, this application is just for unit-testing

> If so, then, here are the dooming consequences of
> silencing the warnings that the linker was giving you.
> 
> It looks like there is more to this problem that
> you have shared with us   :-)
> 
> Please tell us about any compilation and linker
> warnings that you may have observed while
> building this application.

Well, I just recompile itk (Mode Pub On : thanks to incredibuild, this takes
less than 15 minutes).
My compilations options : Static lib (SHARED_LIBS unchecked in cmake) and I
changed compiler flags /MD* in /MT*
And I built Itk (default option is without MFC).

Then I want to built my small application (btw, I remove the /FORCE option
in the linker command) which uses MFC (and a 3rd library with uses MFC) and
I got these linker errors:
1>msvcrtd.lib(ti_inst.obj) : error LNK2005: "private: __thiscall
type_info::type_info(class type_info const &)" (??0type_info@@AAE at ABV0@@Z)
déjà défini(e) dans libcmtd.lib(typinfo.obj)
1>msvcrtd.lib(ti_inst.obj) : error LNK2005: "private: class type_info &
__thiscall type_info::operator=(class type_info const &)"
(??4type_info@@AAEAAV0 at ABV0@@Z) déjà défini(e) dans libcmtd.lib(typinfo.obj)
1>msvcrtd.lib(MSVCR80D.dll) : error LNK2005: _sprintf déjà défini(e) dans
libcmtd.lib(sprintf.obj)
1>msvcrtd.lib(MSVCR80D.dll) : error LNK2005: _tolower déjà défini(e) dans
libcmtd.lib(tolower.obj)
1>msvcrtd.lib(MSVCR80D.dll) : error LNK2005: _malloc déjà défini(e) dans
libcmtd.lib(dbgheap.obj)
1>msvcrtd.lib(MSVCR80D.dll) : error LNK2005: _realloc déjà défini(e) dans
libcmtd.lib(dbgheap.obj)
1>msvcrtd.lib(MSVCR80D.dll) : error LNK2005: _free déjà défini(e) dans
libcmtd.lib(dbgheap.obj)
1>msvcrtd.lib(MSVCR80D.dll) : error LNK2005: _fprintf déjà défini(e) dans
libcmtd.lib(fprintf.obj)
1>msvcrtd.lib(MSVCR80D.dll) : error LNK2005: _fclose déjà défini(e) dans
libcmtd.lib(fclose.obj)
1>msvcrtd.lib(MSVCR80D.dll) : error LNK2005: _floor déjà défini(e) dans
libcmtd.lib(floor_pentium4.obj)
1>msvcrtd.lib(MSVCR80D.dll) : error LNK2005: _fopen déjà défini(e) dans
libcmtd.lib(fopen.obj)
1>msvcrtd.lib(MSVCR80D.dll) : error LNK2005: _printf déjà défini(e) dans
libcmtd.lib(printf.obj)

I tried to remove libcmtd.lib (ignored library) but I got these linker
errors
1>itkvnl.lib(vnl_math.obj) : error LNK2001: symbole externe non résolu
__HUGE
1>nafxcwd.lib(appcore.obj) : error LNK2001: symbole externe non résolu
___argv
1>nafxcwd.lib(appcore.obj) : error LNK2001: symbole externe non résolu
___argc

I tried to remove msvcrtd.lib and I got these linker errors
(IconicRegistrationD.lib is one of our library)
1>IconicRegistrationD.lib(event.obj) : warning LNK4217: symbole défini
localement _sprintf importé dans la fonction _opj_event_msg
1>IconicRegistrationD.lib(event.obj) : warning LNK4217: symbole défini
localement _tolower importé dans la fonction _opj_event_msg
1>IconicRegistrationD.lib(j2k_lib.obj) : warning LNK4217: symbole défini
localement _malloc importé dans la fonction _opj_malloc
1>IconicRegistrationD.lib(j2k_lib.obj) : warning LNK4217: symbole défini
localement _realloc importé dans la fonction _opj_realloc
1>IconicRegistrationD.lib(j2k_lib.obj) : warning LNK4217: symbole défini
localement _free importé dans la fonction _opj_free
1>IconicRegistrationD.lib(j2k.obj) : warning LNK4217: symbole défini
localement _fprintf importé dans la fonction _j2k_dump_image
1>IconicRegistrationD.lib(tcd.obj) : warning LNK4049: symbole défini
localement _fprintf importé
1>IconicRegistrationD.lib(j2k.obj) : warning LNK4217: symbole défini
localement _fclose importé dans la fonction _j2k_create_index
1>IconicRegistrationD.lib(j2k.obj) : warning LNK4217: symbole défini
localement _floor importé dans la fonction _j2k_create_index
1>IconicRegistrationD.lib(tcd.obj) : warning LNK4049: symbole défini
localement _floor importé
1>IconicRegistrationD.lib(dwt.obj) : warning LNK4049: symbole défini
localement _floor importé
1>IconicRegistrationD.lib(t1.obj) : warning LNK4049: symbole défini
localement _floor importé
1>IconicRegistrationD.lib(j2k.obj) : warning LNK4217: symbole défini
localement _fopen importé dans la fonction _j2k_create_index
1>IconicRegistrationD.lib(t2.obj) : warning LNK4217: symbole défini
localement _printf importé dans la fonction _t2_decode_packet
1>IconicRegistrationD.lib(event.obj) : error LNK2019: symbole externe non
résolu __imp___itoa référencé dans la fonction _opj_event_msg


So I built itk with "use MFC as static lib" and ......I do have exactly the
same linker errors ....

So I built my app using cmake and both executables (Debug/release) built.
However:
	- Debug do not crash but I got itk errors in a window
	- Release still crashes ....

I continue investigations....

V


> 
> 
>     Thanks
> 
> 
>          Luis
> 
> 
> --------------------------------------------------------------
> -----------------
> On Mon, Oct 12, 2009 at 8:55 AM, Daanen Vincent 
> <daanen at koelis.com> wrote:
> > Hi All,
> >
> > I still have problems to use  the 
> itk::ConnectedThresholdImageFilter.
> >
> > Luis, I do not have any problem in Debug mode and although 
> the printed
> > values are not the ones I set in the  filter, it seems that 
> the process uses
> > the good ones to filter the image !!
> >
> > But, the same code still crashes in release mode in the 
> Update method...
> >
> > V
> >
> >
> >
> >> -----Message d'origine-----
> >> De : Luis Ibanez [mailto:luis.ibanez at kitware.com]
> >> Envoyé : jeudi 8 octobre 2009 15:43
> >> À : Daanen Vincent
> >> Cc : insight-users at itk.org
> >> Objet : Re: [Insight-users] ConnectedThresholdImageFilter
> >> does take into accopunt the configuration
> >>
> >> Hi Vincent,
> >>
> >> Thanks for the additional information.
> >>
> >> You made an interesting observation,
> >>
> >> It is very strange and suspicious that
> >> the values printed by filter->Print()
> >> do not correspond to the values of
> >> Lower/Upper/DebugOn and that you
> >> are setting.
> >>
> >> It looks like the filter is created in two
> >> separate places and we are looking at
> >> two different pieces of code.
> >>
> >> Any chance that you can run this in
> >> Debug mode ?
> >>
> >> It will be really helpful to locate the
> >> exact line where it is crashing (inside
> >> the Update() method call),  AND to
> >> look at the callstack to trace back
> >> what method call lead to that point.
> >>
> >>
> >>    Please let us know if you can do that,
> >>
> >>
> >>           Thanks
> >>
> >>
> >>                 Luis
> >>
> >>
> >> --------------------------------------------------------
> >> On Thu, Oct 8, 2009 at 9:32 AM, Daanen Vincent
> >> <daanen at koelis.com> wrote:
> >> > Hi Luis,
> >> >
> >> > Thanks for your input.
> >> >
> >> >> An easy way to verify this, would be to pass the image to
> >> >> an itkImageFileWriter<> and to save it to disk.
> >> >
> >> > I follow your requirement and thus, i could write my image
> >> on the disk ...I
> >> > checked the image and it is ok.
> >> >
> >> >> BTW: It is normal for the connected threshold filter not to
> >> >> offer the full connectivity option when ITK has been configured
> >> >> with REVIEW off. The reason is that this is a new feature, that
> >> >> relies on a new Iterator class that is currently in the 
> Code/Review
> >> >> directory.
> >> >
> >> > OK
> >> >
> >> >> In particular, you want to review the code of
> >> >>
> >> >>           TItkInterface::Gmcao2Itk(*l_pImg);
> >> >>
> >> >> and make sure that the ITK image produced by the ImportFilter
> >> >> is held ALL THE TIME by a SmartPointer.
> >> > Yes it is
> >> >
> >> >>
> >> >> Also, please double check the settings of the boolean flag that
> >> >> defines who will be responsible for releasing the memory of
> >> >> the imported image. (Wrongly setting this boolean is also
> >> >> a common mistake when importing images).
> >> >
> >> > The application is responsible for releasing the memory of
> >> >> the imported image and since I can write the imported
> >> image on the disk ,I
> >> > think it's ok.
> >> >
> >> > The crash occurs on the following line:
> >> > l_pFilter->Update();
> >> > So during the filter processing I guess ....
> >> >
> >> > Hereafter the output of the call to l_pFilter->Print() method:
> >> >
> >> > ConnectedThresholdImageFilter (003E7E48)
> >> >  RTTI typeinfo:   class itk::ConnectedThresholdImageFilter<class
> >> > itk::Image<unsigned char,3>,class itk::Image<unsigned char,3> >
> >> >  Reference Count: 1
> >> >  Modified Time: 53
> >> >  Debug: On
> >> >  Observers:none
> >> >  Number Of Required Inputs: 1
> >> >  Number Of Required Outputs: 1
> >> >  Number Of Threads: 2
> >> >  ReleaseDataFlag: Off
> >> >  ReleaseDataBeforeUpdateFlag: Off
> >> >  Input 0: (003EA538)
> >> >  Input 1: (003E81C8)
> >> >  Input 2: (003ECF80)
> >> >  Output 0: (003E7F28)
> >> >  AbortGenerateData: Off
> >> >  Progress: 0
> >> >  Multithreader:
> >> >    RTTI typeinfo:   class itk::MultiThreader
> >> >    Reference Count: 1
> >> >    Modified Time: 27
> >> >    Debug: Off
> >> >    Observers:
> >> >      none
> >> >    Thread Count: 2
> >> >    Global Maximum Number Of Threads: 128
> >> >    Global Default Number Of Threads: 2
> >> >  Upper: 255
> >> >  Lower: 0
> >> >  ReplaceValue: 1
> >> >  Connectivity: 0
> >> >
> >> > As you can see, Lower/Upper = [0 255] but I explicitly set
> >> them to 100/130
> >> > Debug is also OFF but I set it to on just before the call
> >> to Print ...
> >> >
> >> > Any Idea ?
> >> >
> >> > Vincent
> >> >>
> >> >>
> >> >>
> >> >>     Regards,
> >> >>
> >> >>
> >> >>           Luis
> >> >>
> >> >>
> >> >> ------------------
> >> >> On Wed, Oct 7, 2009 at 2:17 AM, Daanen Vincent
> >> >> <daanen at koelis.com> wrote:
> >> >> > Hi Itk users,
> >> >> >
> >> >> > I want to use itk::ConnectedThresholdImageFilter to extract
> >> >> a object from a
> >> >> > 3D image.
> >> >> > I first load the image and convert it from our own image
> >> >> format into itk
> >> >> > image format. The call to CItkInterface::Gmcao2Itk is just
> >> >> a wrapper to
> >> >> > ItkImageimportFilter.
> >> >> > I can say it is ok (I play several tests to check that all
> >> >> the data are
> >> >> > correctly converted...)
> >> >> >
> >> >> > I then instantiate a itk::ConnectedThresholdImageFilter
> >> >> ,set its input, the
> >> >> > thresholds and the seed. (My code is nearly the same that
> >> >> the one in the itk
> >> >> > user guide)
> >> >> >
> >> >> > When I call Update, the software crashes with messages in a
> >> >> window but I
> >> >> > can't read them totally ...:(
> >> >> >
> >> >> > So, before calling update, I print the component on screen
> >> >> (using Print
> >> >> > method) and I can see that the thresholds are not the one I
> >> >> set (low = 0;
> >> >> > high = 255) instead of (L/H = 100/130).
> >> >> > I also saw that there is not method to set the connectivity
> >> >> unless itk is
> >> >> > compiled with ITK_USE_REVIEW. Is this normal ? I can not
> >> see why the
> >> >> > connectivity is link to the REVIEW flag
> >> >> >
> >> >> > How can I find why the filter exit without making its work ?
> >> >> >
> >> >> > Thx for help
> >> >> >
> >> >> > Vince
> >> >> >
> >> >> > PS : the code I wrote. If someone sees something wrong,
> >> >> please tell me
> >> >> >
> >> >> > void Test()
> >> >> > {
> >> >> >
> >> >> > /// Our Own core work
> >> >> >        typedef gmcao::CImage<BYTE,3> TImage;
> >> >> >        CSmartPtr<TImage> l_pImg(new TImage);
> >> >> >
> >> >> >        if
> >> >> (!gmcao::CImageTools<TImage>::ReadImage(*l_pImg,"Img.hdr"))
> >> >> >        {
> >> >> >                std::cout<<"Could not read image"<<std::endl;
> >> >> >                return;
> >> >> >        }
> >> >> >
> >> >> >        typedef CItkInterface<TImage::TValue, TImage::Dim>
> >> >> TItkInterface;
> >> >> >        TItkInterface::TItkImage::Pointer l_pIktImg =
> >> >> > TItkInterface::Gmcao2Itk(*l_pImg);
> >> >> >        if (l_pIktImg.IsNull())
> >> >> >        {
> >> >> >                std::cout<<"Error converting Gmcao ->
> >> >> Itk"<<std::endl;
> >> >> >                return;
> >> >> >        }
> >> >> > ///
> >> >> >
> >> >> > /// Itk filter
> >> >> >        typedef
> >> >> >
> >> >> itk::ConnectedThresholdImageFilter<TItkInterface::TItkImage,TI
> >> >> tkInterface::T
> >> >> > ItkImage> TFilter;
> >> >> >        TFilter::Pointer l_pFilter=TFilter::New();
> >> >> >        if (l_pFilter.IsNull())
> >> >> >        {
> >> >> >                std::cout<<"Could not create 
> filter"<<std::endl;
> >> >> >                return;
> >> >> >        }
> >> >> >
> >> >> >        l_pFilter->SetInput(l_pIktImg);
> >> >> >        l_pFilter->SetLower(100);
> >> >> >        l_pFilter->SetUpper(130);
> >> >> >
> >> >> >        TFilter::IndexType l_Seed;
> >> >> >        l_Seed[0] = l_pImg->GetWidths()[0]>>1;
> >> >> >        l_Seed[1] = l_pImg->GetWidths()[1]>>1;
> >> >> >        l_Seed[2] = l_pImg->GetWidths()[2]>>1;
> >> >> >
> >> >> >        l_pFilter->SetSeed(l_Seed);
> >> >> >
> >> >> >        l_pFilter->DebugOn();
> >> >> >        l_pFilter->Print(std::cout);
> >> >> >
> >> >> >        try
> >> >> >        {               l_pFilter->Update();}
> >> >> >        catch( itk::ExceptionObject &excep )
> >> >> >        {
> >> >> >                std::cerr << "Exception caught !" << std::endl;
> >> >> >                std::cerr << excep << std::endl;
> >> >> >        }
> >> >> > }
> >> >> >
> >> >> > --------------------------------------------
> >> >> > Vincent Daanen, PhD
> >> >> > D&D Manager
> >> >> >
> >> >> > --------------------------------------------
> >> >> > KOELIS
> >> >> > 5, avenue du Grand Sablon 38700 La Tronche
> >> >> > www.koelis.com  -  daanen at koelis.com
> >> >> > Tel .+33(0) 476637588 Fax .+33(0) 476637592
> >> >> > --------------------------------------------
> >> >> >
> >> >> > CONFIDENTIALITY This e-mail and any attachments are
> >> >> confidential and may
> >> >> > also be privileged. If you are not the named recipient,
> >> >> please notify the
> >> >> > sender immediately and do not disclose the contents to
> >> >> another person, use
> >> >> > it for any purpose, or store or copy the information in
> >> any medium.
> >> >> >
> >> >> > "Les problèmes ne peuvent être résolus par ceux dont
> >> >> l'horizon se limite aux
> >> >> > réalités quotidiennes,  mais par ceux qui rêvent de choses
> >> >> qui n'ont jamais
> >> >> > existé et qui se disent : Pourquoi Pas ?" (J-F Kennedy, 1963).
> >> >> >
> >> >> > _____________________________________
> >> >> > Powered by www.kitware.com
> >> >> >
> >> >> > Visit other Kitware open-source projects at
> >> >> > http://www.kitware.com/opensource/opensource.html
> >> >> >
> >> >> > Please keep messages on-topic and check the ITK FAQ at:
> >> >> http://www.itk.org/Wiki/ITK_FAQ
> >> >> >
> >> >> > Follow this link to subscribe/unsubscribe:
> >> >> > http://www.itk.org/mailman/listinfo/insight-users
> >> >> >
> >> >
> >> >
> >
> >



More information about the Insight-users mailing list