[Insight-users] ITK Image registration within Matlab -> Segmentation Violation

Guitarum guillaume.salvai at sanofi-aventis.com
Wed Oct 13 09:36:46 EDT 2010


Hello,

It works !! Thanks a lot ! :)
Actually, I was compiling my code within Matlab, using the VS compiler.
(option mex -setup).
However, maybe we don't have access to all the options since it only works
with your way ..

Anyway, thanks again!
Guillaume


Patrik Brynolfsson wrote:
> 
> Ok, this is how I compile mex files in VS2010. I know older VS have
> slightly
> different layout, but the principle is the same.
> In the solution explorer right click on your project and select
> Properties/Configuration Properties and do the following:
> 
>    - In General, set target extension to .mexw32 (this might be under
> Linker
>    properties in older VS)
>    - in General, Set configuration type to Dynamic library (.dll)
>    - In C/C++/General, set additional include directories to C:\Program
>    Files\MATLAB\R2010a\extern\include (or wherever your matlab is
> installed)
>    - In C/C++/Preprocessor, add MATLAB_MEX_FILE to Preprocessor
> definitions
>    - In Linker/General, set Additional Library directories to C:\Program
>    Files\MATLAB\R2010a\extern\lib\win32\microsoft  (or wherever your
> matlab is
>    installed)
>    - in Linker/Input, add libmx.lib, libmex.lib, libmat.lib to Additional
>    Dependencies
>    - Add a module definition file in Module definition file. Mine is
> called
>    module.def and is just a text file with the content:
> 
> LIBRARY "name of your mex.file"
> EXPORTS mexFunction
> 
> For me it is something like
> 
> LIBRARY registration.mexw32
> EXPORTS mexFunction
> 
> Place your module.def file where your solution is, i.e. the same folder as
> your .sln file.
> 
> That works for me, give it a try and see if it helps.
> ---
> Patrik Brynolfsson
> 
> 
> 
> 
> 2010/10/12 Guillaume.Salvai at sanofi-aventis.com <
> Guillaume.Salvai at sanofi-aventis.com>
> 
>> Hello,
>>
>> I am using Matlab 7.10.0 (R2010a).
>> I tried to attach VS to the Matlab process and run my .mex32, but I don't
>> have any clue ..
>> The process crashes with an Access Violation (Exception ... (ITKCommon)
>> in
>> Matlab.exe ).
>>
>> I thought a library might missing whith Matlab, but the process wouldn't
>> run at the beginning is it?
>> And as for my VS settings, they are supposed to be the same as when it
>> works without Matlab, but I may miss someting.
>>
>> Thanks for your help,
>> Guillaume
>>
>> ________________________________
>> From: patrik.brynolfsson at gmail.com [mailto:patrik.brynolfsson at gmail.com]
>> On Behalf Of Patrik Brynolfsson
>> Sent: Tuesday, October 12, 2010 5:42 PM
>> To: Salvai, Guillaume R&D/FR
>> Cc: insight-users at itk.org
>> Subject: Re: [Insight-users] ITK Image registration within Matlab ->
>> Segmentation Violation
>>
>> Your code doesn't crash for me, maybe there is something wrong with your
>> VS
>> settings? What version of Matlab are you using?
>> ---
>> Patrik Brynolfsson
>>
>>
>>
>>
>> 2010/10/12 Patrik Brynolfsson <patrik.brynolfsson at radfys.umu.se<mailto:
>> patrik.brynolfsson at radfys.umu.se>>
>> You can debug the code by attatching matlab to  VS. Tools/Attatch to
>> process, select matlab. Then just set a break point and run the code from
>> matlab. Maybe that sheds some light to the problem... ?
>> ---
>> Patrik Brynolfsson
>>
>>
>>
>>
>> 2010/10/12 Guitarum <guillaume.salvai at sanofi-aventis.com<mailto:
>> guillaume.salvai at sanofi-aventis.com>>
>>
>> Hello everybody,
>>
>> I'am attempting to perform an image registration using ITK.
>> First of all, I've done it within Visual Studio, and it works perfectly.
>>
>> Now, I simply want to implement this within Matlab, using mexFunction.
>> I copy what I had done, with no input/output argument for the
>> mexFunction.
>> I added the useful include files and libraries, and it compiles well.
>> However, I got a Segmentation Violation while running the programme
>> .mex32
>>
>> Then I investigate and the problem seems to come from a
>> itkImageRegistration
>> object.
>> Here is a code which sheds light on the problem that I didn't manage to
>> handle ..  (it isn't my entire code, but the rest works well). I comment
>> it
>> explaining the tests I've done.
>>
>> /* BEGINNING */
>>
>> // MEX
>> #include "mex.h"
>>
>> // ITK
>> #include "itkTranslationTransform.h"
>> #include "itkMattesMutualInformationImageToImageMetric.h"
>> #include "itkImageRegistrationMethod.h"
>>
>>
>> const      unsigned int   Dimension = 3;
>> typedef   unsigned char  PixelType;
>> typedef   float          InternalPixelType;
>>
>> typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
>> typedef itk::MattesMutualInformationImageToImageMetric<
>> InternalImageType,
>> InternalImageType > MetricType;
>> typedef itk::TranslationTransform< double, Dimension> TransformType;
>> typedef itk::ImageRegistrationMethod< InternalImageType ,
>> InternalImageType
>> > RegistrationType;
>>
>>
>>  // The program entry point
>>  void mexFunction(int nlhs, mxArray *plhs[],
>>                int nrhs, const mxArray *prhs[])
>>  {
>>
>>   mexPrintf("Begin !\n");
>>
>>   // Test of MetricType. It exists and the function
>> SetNumberOfHistogramBins works.
>>   MetricType::Pointer metric = MetricType::New();
>>   metric->SetNumberOfHistogramBins( 50 );
>>
>>   // Test of transformType. OK.
>>   TransformType::Pointer transform = TransformType::New();
>>   TransformType::ParametersType testTransf(3);
>>   testTransf[0]=1;
>>   testTransf[1]=2;
>>   testTransf[2]=3;
>>   transform->SetParameters(testTransf);
>>
>>   mexPrintf("OK1 !\n");
>>
>>   // That part doesn't crash. So I guess RegistrationType is correctly
>> define.
>>   RegistrationType::ParametersType testReg(3);
>>   testReg[0]=1;
>>   testReg[1]=2;
>>   testReg[2]=3;
>>
>>   mexPrintf("OK2 !\n");
>>
>>   // It crashes here ! Segmentation Violation.
>>   RegistrationType::Pointer reg = RegistrationType::New();
>>
>>  }
>>
>> /*END*/
>>
>> I found that the last code line crashes, although it is a basic object
>> creation.
>> Furthermore, it works for TransformType and MetricType, and those are
>> very
>> similar to Registration Type.
>>
>> I'm somehow a newbie with ITK, so it might be a basic mistake. But I
>> can't
>> find it, besides it works within VC++ ...
>> Does anybody have an idea? I'll be very grateful for any help.
>>
>> Thanks very much in advance,
>> Guillaume
>>
>> --
>> View this message in context:
>> http://old.nabble.com/ITK-Image-registration-within-Matlab--%3E-Segmentation-Violation-tp29940926p29940926.html
>> Sent from the ITK - Users mailing list archive at Nabble.com.
>>
>> _____________________________________
>> Powered by www.kitware.com<http://www.kitware.com>
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.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
>>
>>
>>
> 
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.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
> 
> 

-- 
View this message in context: http://old.nabble.com/ITK-Image-registration-within-Matlab--%3E-Segmentation-Violation-tp29940926p29952803.html
Sent from the ITK - Users mailing list archive at Nabble.com.



More information about the Insight-users mailing list