www.pudn.com > several_kinds_Histogram.rar > COLSPACON.CPP


//#include "stdafx.h" 
#include"stdafx.h" 
#include"COLSPACON.h" 
 
 
COLSPACON::~COLSPACON() 
{ 
	if(orgin!=0) 
     orgin=0; 
 
	if(dest!=0) 
		dest=0; 
 
} 
void COLSPACON::RGB2RGB() 
{ 
//	for(long i=0;i!=height*width;++i) 
//	{ 
//		double a=(double (orgin[i].red)) /256; 
//		double b=(double (orgin[i].green)) /256; 
//		double c=(double (orgin[i].blue)) /256; 
//		dest[3*i]=a; 
//		dest[3*i+1]=b; 
//		dest[3*i+2]=c; 
//		// cout<widthStep; 
	int imageheight=orgin->height; 
	int imagewidth=orgin->width; 
	uchar *imagedata=(uchar *)orgin->imageData; 
     
	for(int i=0;iwidthStep; 
	int imageheight=orgin->height; 
	int imagewidth=orgin->width; 
	uchar *imagedata=(uchar *)orgin->imageData; 
 
	for(int i=0;i1.0-3) 
		  s=delta/v; 
	  else 
		  s=0; 
     //get the value of the H 
	  if(s<1.0-4) 
		  h=0; 
	  else 
	  { 
		  if(v>=g&&v>=b) //red is the max 
			  h=(g-b)/delta; 
          else if(v>=r&&v>=b)    //green is the max 
	          h=2+(b-r)/delta; 
  
		  else   //blue is max 
			  h=4+(r-g)/delta; 
		  
	  } 
      h*=60; 
	  //convert the value of the h to (0,1) 
	  if(h<0) 
		  h+=360; 
 
	  h/=360; 
 
	    dest[3*index]=h; 
		dest[3*index+1]=s; 
		dest[3*index+2]=v; 
	} 
 
} 
//  for(long i=0;i(orgin[i].red) )/256; 
//	  double g=(static_cast(orgin[i].green) )/256; 
//	  double b=(static_cast(orgin[i].blue) )/256; 
//	  //convert to HSV 
//	  double h,s,v; 
//	  //get the value of the V 
//	  v=max(r,max(g,b)); 
//	  double dmin=min(r,min(g,b)); 
//	  double delta=v-dmin; 
//     //get the value of the S 
//	  if(v>1.0-3) 
//		  s=delta/v; 
//	  else 
//		  s=0; 
//     //get the value of the H 
//	  if(s<1.0-4) 
//		  h=0; 
//	  else 
//	  { 
//		  if(v>=g&&v>=b) //red is the max 
//			  h=(g-b)/delta; 
//          else if(v>=r&&v>=b)    //green is the max 
//	          h=2+(b-r)/delta; 
//  
//		  else   //blue is max 
//			  h=4+(r-g)/delta; 
//		  
//	  } 
//      h*=60; 
//	  //convert the value of the h to (0,1) 
//	  if(h<0) 
//		  h+=360; 
// 
//	  h/=360; 
// 
//	    dest[3*i]=h; 
//		dest[3*i+1]=s; 
//		dest[3*i+2]=v; 
//	/*	cout<widthStep; 
	int imageheight=orgin->height; 
	int imagewidth=orgin->width; 
	uchar *imagedata=(uchar *)orgin->imageData; 
 
	for(int i=0;i(orgin[i].red) )/256; 
//	  double g=(static_cast(orgin[i].green) )/256; 
//	  double b=(static_cast(orgin[i].blue) )/256; 
//	  //convert to HSI 
//	  double H,S,I; 
//	  //get the value of the I 
//	  I=(r+g+b)/3; 
//	  //get the value of the S 
//	  if(I>1.0e-3) 
//	  S=1-min(r,min(g,b))/I; 
//	  else  
//	  S=0; 
// 
//	  //get the value of the H 
//	  if(S>1.0e-3) 
//	  { 
//		H = ((r-g)+(r-b))/2.0; 
//		H = H/sqrt((r-g)*(r-g) + (r-b)*(g-b)); 
//		H = acos(H); 
//		if (b>g) 
//		{ 
//			H = 2*PI - H; 
//		} 
//		H = H/(2*PI); 
//		   
//	  } 
//	  else 
//	  { 
//        H=0.0; 
//	  } 
//	    dest[3*i]=H; 
//		dest[3*i+1]=S; 
//		dest[3*i+2]=I; 
//	/*	cout<widthStep; 
		int imageheight=orgin->height; 
	int imagewidth=orgin->width; 
	uchar *imagedata=(uchar *)orgin->imageData; 
 
	for(int i=0;i1.0e-3) 
	  S=1-min(r,min(g,b))/I; 
	  else  
	  S=0; 
 
	  //get the value of the H 
	  if(S>1.0e-3) 
	  { 
		H = ((r-g)+(r-b))/2.0; 
		H = H/sqrt((r-g)*(r-g) + (r-b)*(g-b)); 
		H = acos(H); 
		if (b>g) 
		{ 
			H = 2*PI - H; 
		} 
		H = H/(2*PI); 
		   
	  } 
	  else 
	  { 
        H=0.0; 
	  } 
	    dest[3*index]=H; 
		dest[3*index+1]=S; 
		dest[3*index+2]=I; 
	/*	cout<