• gisyong
    了解作者
  • Visual C++
    开发工具
  • 143KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 18
    下载次数
  • 2009-11-24 06:07
    上传日期
本人打包的MRF算法包,可以直接使用,包括源码、头文件和库文件
MRFlib.rar
  • MRFlib
  • include
  • regions-new.h
    1.5KB
  • BP-S.h
    2.3KB
  • GCoptimization.h
    13.6KB
  • typeTruncatedQuadratic2D.h
    896B
  • ICM.h
    1.5KB
  • block.h
    8.7KB
  • LinkedBlockList.h
    1.7KB
  • MaxProdBP.h
    2.3KB
  • energy.h
    11.4KB
  • mrf.h
    11.9KB
  • graph.h
    9.4KB
  • TRW-S.h
    2.7KB
  • lib
  • MRFlib.lib
    407.7KB
  • src
  • LinkedBlockList.cpp
    1.4KB
  • mrf.cpp
    3.1KB
  • MaxProdBP.cpp
    7.7KB
  • ICM.cpp
    8.5KB
  • GCoptimization.cpp
    44.4KB
  • maxflow.cpp
    26.8KB
  • regions-maxprod.cpp
    17.5KB
  • graph.cpp
    11.9KB
  • example.cpp
    9.6KB
  • BP-S.cpp
    25.4KB
  • TRW-S.cpp
    26KB
内容介绍
#include "energy.h" #include "graph.h" #include "GCoptimization.h" #include <stdio.h> #include <time.h> #include <stdlib.h> #include "string.h" #define MAX_INTT 1000000000 /**************************************************************************************/ void GCoptimization::initialize_memory() { m_lookupPixVar = (PixelType *) new PixelType[m_nPixels]; m_labelTable = (LabelType *) new LabelType[m_nLabels]; terminateOnError( !m_lookupPixVar || !m_labelTable ,"Not enough memory"); for ( int i = 0; i < m_nLabels; i++ ) m_labelTable[i] = i; } /**************************************************************************************/ void GCoptimization::commonGridInitialization(PixelType width, PixelType height, int nLabels) { terminateOnError( (width < 0) || (height <0) || (nLabels <0 ),"Illegal negative parameters"); m_width = width; m_height = height; m_nPixels = width*height; m_nLabels = nLabels; m_grid_graph = 1; } /**************************************************************************************/ void GCoptimization::setParameters(int numParam, void *param) { if (numParam != 1 ) printf("\nInvalid number of parameters, can only set one parameter\\that is boolean label order\n"); else { m_random_label_order = *((bool *) param); } } /**************************************************************************************/ void GCoptimization::commonNonGridInitialization(PixelType nupixels, int num_labels) { terminateOnError( (nupixels <0) || (num_labels <0 ),"Illegal negative parameters"); m_nLabels = num_labels; m_nPixels = nupixels; m_grid_graph = 0; m_neighbors = (LinkedBlockList *) new LinkedBlockList[nupixels]; terminateOnError(!m_neighbors,"Not enough memory"); } /**************************************************************************************/ void GCoptimization::commonInitialization() { m_needToFreeV = 0; m_random_label_order = 1; initialize_memory(); } /**************************************************************************************/ /* Use this constructor only for grid graphs */ GCoptimization::GCoptimization(PixelType width,PixelType height,LabelType nLabels,EnergyFunction *eng):MRF(width,height,nLabels,eng) { commonGridInitialization(width,height,nLabels); m_labeling = (LabelType *) new LabelType[m_nPixels]; terminateOnError(!m_labeling,"out of memory"); for ( int i = 0; i < m_nPixels; i++ ) m_labeling[i] = (LabelType) 0; commonInitialization(); } /**************************************************************************************/ /* Use this constructor for general graphs */ GCoptimization::GCoptimization(PixelType nPixels,int nLabels,EnergyFunction *eng):MRF(nPixels,nLabels,eng) { commonNonGridInitialization(nPixels, nLabels); m_labeling = (LabelType *) new LabelType[m_nPixels]; terminateOnError(!m_labeling,"out of memory"); for ( int i = 0; i < nPixels; i++ ) m_labeling[i] = (LabelType) 0; commonInitialization(); } /**************************************************************************************/ void GCoptimization::setData(EnergyTermType* dataArray) { m_datacost = dataArray; } /**************************************************************************************/ void GCoptimization::setData(DataCostFn dataFn) { m_dataFnPix = dataFn; } /**************************************************************************************/ void GCoptimization::setSmoothness(EnergyTermType* V) { m_smoothcost = V; } /**************************************************************************************/ void GCoptimization::setSmoothness(int smoothExp,CostVal smoothMax, CostVal lambda) { int i, j; CostVal cost; m_needToFreeV = 1; m_smoothcost = (CostVal *) new CostVal[m_nLabels*m_nLabels]; if (!m_smoothcost) { fprintf(stderr, "Not enough memory!\n"); exit(1); } for (i=0; i<m_nLabels; i++) for (j=i; j<m_nLabels; j++) { cost = (CostVal) ((smoothExp == 1) ? j - i : (j - i)*(j - i)); if (cost > smoothMax) cost = smoothMax; m_smoothcost[i*m_nLabels + j] = m_smoothcost[j*m_nLabels + i] = cost*lambda; } } /**************************************************************************************/ void GCoptimization::setCues(EnergyTermType* hCue, EnergyTermType* vCue) { m_horizWeights = hCue; m_vertWeights = vCue; } /**************************************************************************************/ void GCoptimization::setSmoothness(SmoothCostGeneralFn cost) { m_smoothFnPix = cost; } /**************************************************************************************/ GCoptimization::EnergyType GCoptimization::dataEnergy() { if ( m_dataType == ARRAY) return(giveDataEnergyArray()); else return(giveDataEnergyFnPix()); return(0); } /**************************************************************************************/ GCoptimization::EnergyType GCoptimization::giveDataEnergyArray() { EnergyType eng = (EnergyType) 0; for ( int i = 0; i < m_nPixels; i++ ) eng = eng + m_datacost(i,m_labeling[i]); return(eng); } /**************************************************************************************/ GCoptimization::EnergyType GCoptimization::giveDataEnergyFnPix() { EnergyType eng = (EnergyType) 0; for ( int i = 0; i < m_nPixels; i++ ) eng = eng + m_dataFnPix(i,m_labeling[i]); return(eng); } /**************************************************************************************/ GCoptimization::EnergyType GCoptimization::smoothnessEnergy() { if ( m_grid_graph ) { if ( m_smoothType != FUNCTION ) { if (m_varWeights) return(giveSmoothEnergy_G_ARRAY_VW()); else return(giveSmoothEnergy_G_ARRAY()); } else return(giveSmoothEnergy_G_FnPix()); } else { if ( m_smoothType != FUNCTION ) return(giveSmoothEnergy_NG_ARRAY()); else return(giveSmoothEnergy_NG_FnPix()); } return(0); } /**************************************************************************************/ GCoptimization::EnergyType GCoptimization::giveSmoothEnergy_NG_FnPix() { EnergyType eng = (EnergyType) 0; int i; Neighbor *temp; for ( i = 0; i < m_nPixels; i++ ) if ( !m_neighbors[i].isEmpty() ) { m_neighbors[i].setCursorFront(); while ( m_neighbors[i].hasNext() ) { temp = (Neighbor *) m_neighbors[i].next(); if ( i < temp->to_node ) eng = eng + m_smoothFnPix(i,temp->to_node, m_labeling[i],m_labeling[temp->to_node]); } } return(eng); } /**************************************************************************************/ GCoptimization::EnergyType GCoptimization::giveSmoothEnergy_NG_ARRAY() { EnergyType eng = (EnergyType) 0; int i; Neighbor *temp; for ( i = 0; i < m_nPixels; i++ ) if ( !m_neighbors[i].isEmpty() ) { m_neighbors[i].setCursorFront(); while ( m_neighbors[i].hasNext() ) { temp = (Neighbor *) m_neighbors[i].next(); if ( i < temp->to_node ) eng = eng + m_smoothcost(m_labeling[i],m_labeling[temp->to_node])*(temp->weight); } } return(eng); } /**************************************************************************************/ GCoptimization::EnergyType GCoptimization::giveSmoothEnergy_G_ARRAY_VW() { EnergyType eng = (EnergyType) 0; int x,y,pix; for ( y = 0; y
评论
    相关推荐
    • MRF.rar
      马尔科夫随机场在图像分析中的应用代码,用C++编写,质量非常高,有很强的实时性。
    • matlabcnhelp.rar
      matlab中文帮助很难找的,快速下载
    • MobilePolice.rar
      移动警察,车牌识别,车牌定位系统源代码,已经运用在移动车载稽查系统中。
    • SVM(matlab).rar
      支持向量机(SVM)实现的分类算法源码[matlab]
    • svm.zip
      用MATLAB编写的svm源程序,可以实现支持向量机,用于特征分类或提取
    • Classification-MatLab-Toolbox.rar
      模式识别matlab工具箱,包括SVM,ICA,PCA,NN等等模式识别算法,很有参考价值
    • VC++人脸定位实例.rar
      一个经典的人脸识别算法实例,提供人脸五官定位具体算法及两种实现流程.
    • QPSK_Simulink.rar
      QPSK的Matlab/Simulink的调制解调仿真系统,给出接收信号眼图及系统仿真误码率,包含载波恢复,匹配滤波,定时恢复等重要模块,帮助理解QPSK的系统
    • LPRBPDemo2009KV.rar
      车牌识别,神经网络算法,识别率高达95%,识别时间低于80ms。
    • MODULATION.RAR
      这个源程序代码包提供了通信系统中BPSK,QPSK,OQPSK,MSK,MSK2,GMSK,QAM,QAM16等调制解调方式 用matlab的实现,以及它们在AWGN和Rayleigh信道下的通信系统实现及误码率性能