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