Click here to Skip to main content
15,896,513 members
Articles / Programming Languages / C++

STL like template based coding with the MMX/SSE extension

Rate me:
Please Sign up or sign in to vote.
4.76/5 (17 votes)
17 Nov 20062 min read 114.3K   669   45  
STL like template based coding with the MMX/SSE extension using OpenCV, vigra, and boost.
#include "stllcv/iplvhistogram.hxx"
#include "stllcv/iplvbasicimage.hxx"
#include "highgui.h"

#define PEXORGIMG unsigned char

#if !DebugFileRead
#define Filename argv[1]
#define Filename2 argv[2] 
#define OutImageName argv[3] 
#endif

float iplvMutualInformation(
   CiplvHistogram<1> &hist1
   ,CiplvHistogram<1> &hist2
   ,CiplvHistogram<2> &hist12)
{
	float sum=0;
	float N=hist1.size(0);
	vigra::MultiIterator< 1, float> i1=hist1.traverser_begin() ,iend1=hist1.traverser_end();
		//vigra::MultiIterator< 2, float> i;
        //i3.template dim<1>()++;  // increment outer dimension
        //i3.template dim<0>()++;  // increment inner dimension
	vigra::MultiIterator<2, float> k2 = hist12.traverser_begin(),kend2 =hist12.traverser_end();
    for(; k2 != kend2; ++k2, ++i1)
    {
		vigra::MultiIterator< 1, float> j1=hist2.traverser_begin() ,jend1=hist2.traverser_end();
        vigra::MultiIterator<2, float>::next_type k1 = k2.begin(), kend1 = k2.end();
        for(; k1 != kend1; ++k1, ++j1)
        {
			if(k1[0]>0 && i1[0]>0 && j1[0]>0){
				sum += k1[0]/N * log( k1[0]*N/(i1[0])*(j1[0]) ); // do something with the current element
			}
        }
    }
	return sum;
}


int main( int argc, char** argv )
{


	
	CiplvBasicImage<PEXORGIMG> image1("lena.jpg");
	CiplvBasicImage<PEXORGIMG> image2("lena2.jpg");


	int hist_size = 256; 
	float range_0[]={0,255};
	float* ranges[]={ range_0 };

	CiplvHistogram<1> hist1(&hist_size,ranges);
	CiplvHistogram<1> hist2(&hist_size,ranges);

	cvCalcHist( &image1.pIplImage, hist1.pCvHistogram, 0, 0 );
	cvCalcHist( &image2.pIplImage, hist2.pCvHistogram, 0, 0 );



	float range_1[]={0,255};
	float* ranges2[]={ range_0 ,range_1 };
	int hist_sizes[] = {256,256};
	CiplvHistogram<2> hist12(hist_sizes,ranges2);
	float mutInf= iplvMutualInformation(hist1,hist2,hist12);

	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Japan Japan
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions