初学归一化切割和图像分割

解决Matlab编译C++错误:基于归一化切割的图像分割

    最近正在研读一篇文献FROM RARENESS TO COMPACTNESS: CONTRAST-AWARE IMAGE SALIENCY DETECTION,学习基于对比度感知的显著性检测。

    在点击打开链接中,作者大概分析了这篇文章的内容,本人不才尝试用matlab去实现文章讲述的方法。

    在实现bin contrast时,顺便学习基于归一化切割(Normalized Cut)的图像分割,主要的参考文献是Normalized Cuts and Image Segmentation(J.Shi and J.Malik,TPAMI,2000),在百度还有中文翻译(http://wenku.baidu.com/link?url=vZc7NyQS4b9ECZiaTS4UnPPVaMXcD1BMfq-LQb1l46ukjT92GsMo8oD1_00qVUAcAYaGkRgqhr5adh-9dEqMHBR6rWwBnsQ8TrDfKQWOnvy)

   查到类似的matlab算法MATLAB Normalized Cuts Segmentation Codehttp://www.cis.upenn.edu/~jshi/software/

   在Matlab R2011b运行NcutImage.m,第一次学习到matlab原来还能调用C++程序,将cpp文件在matlab command窗口编译成mex文件即可。

   不过在编译中出现一些错误,在NcutImage.m所在的readme.txt说可以忽略一些 C++ non-mex file错误,但出现的错误肯定不能忽略(如下)

mex -largeArrayDims cimgnbmap.cpp
Error cimgnbmap.cpp: 172  illegal statement termination 
Error cimgnbmap.cpp: 172  skipping `unsigned' `int' 
Error cimgnbmap.cpp: 172  undeclared identifier `qi' 
Error cimgnbmap.cpp: 172  type error: pointer expected 
Error cimgnbmap.cpp: 172  operands of = have illegal types `int' and `pointer to unsigned int' 
Error cimgnbmap.cpp: 173  illegal statement termination 
Error cimgnbmap.cpp: 173  skipping `unsigned' `int' 
Error cimgnbmap.cpp: 173  undeclared identifier `qj' 
Error cimgnbmap.cpp: 173  type error: pointer expected 
Error cimgnbmap.cpp: 173  operands of = have illegal types `int' and `pointer to unsigned int' 
Error cimgnbmap.cpp: 180  type error: pointer expected 
Error cimgnbmap.cpp: 183  type error: pointer expected 
Error cimgnbmap.cpp: 188  type error: pointer expected 
Warning cimgnbmap.cpp: 173   possible usage of qj before definition 
Warning cimgnbmap.cpp: 172   possible usage of qi before definition 
13 errors, 2 warnings 
 
  C:\PROGRA~1\MATLAB\R2011B\BIN\MEX.PL: Error: Compile of 'cimgnbmap.cpp' failed. 


   一直在cimgnbmap.cpp寻找问题,最后把qi,qj指针变量先在程序开头声明,然后在程序中间赋值,修改为

unsigned int *qi,*qj;
...
qi = (unsigned int *)mxGetData(out[0]);
qj = (unsigned int *)mxGetData(out[1]);
...


   终于编译成功(mex -largeArrayDims cimgnbmap.cpp)

   后面在Matlab R2011b编译不成功的cpp文件都可以这么修改,在程序开头声明变量,然后在程序中间赋值。





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值