//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
//获取程序所在目录
this->file_add = GetCurrentDir() + "\\pinjie.ini" ;
//伪彩控制赋初值
this->int_in_min = this->TrackBar_in_min->Position ;
this->int_in_max = this->TrackBar_in_max->Position ;
this->int_out_min= this->TrackBar_out_min->Position ;
this->int_out_max= this->TrackBar_out_max->Position ;
//直方图变量初始化
for(int i=0; i<256 ; i++ )
{
this->zhifang[i] = 0 ;
}
/*
int angle, order ;
int is_zhuan, zhuan_1, zhuan_2 ;
TIniFile *pIni = NULL ;
AnsiString temp_str ;
int w1,w2 ;
try
{
pIni = new TIniFile( file_add );
temp_str = pIni->ReadString( "system" , "order" , "-1" );
if ( temp_str == "-1" )
{
ShowMessage("读取拼接文件路径出错!");
Application->Terminate() ;
}
order = StrToInt(temp_str) ;
pIni = new TIniFile( file_add );
temp_str = pIni->ReadString( "system" , "a1" , "-1" );
if ( temp_str == "-1" )
{
ShowMessage("读取拼接文件路径出错!");
Application->Terminate() ;
}
angle = StrToInt(temp_str) ;
temp_str = pIni->ReadString( "system" , "w1" , "-1" );
if ( temp_str == "-1" )
{
ShowMessage("读取拼接文件路径出错!");
Application->Terminate() ;
}
w1 = StrToInt(temp_str) ;
temp_str = pIni->ReadString( "system" , "w2" , "-1" );
if ( temp_str == "-1" )
{
ShowMessage("读取拼接文件路径出错!");
Application->Terminate() ;
}
w2 = StrToInt(temp_str) ;
temp_str = pIni->ReadString( "system" , "isxuanzhuan" , "-1" );
if ( temp_str == "-1" )
{
ShowMessage("读取拼接文件路径出错!");
Application->Terminate() ;
}
is_zhuan = StrToInt(temp_str) ;
temp_str = pIni->ReadString( "system" , "xuanzhuan1" , "361" );
if ( temp_str == "361" )
{
ShowMessage("读取拼接文件路径出错!");
Application->Terminate() ;
}
zhuan_1 = StrToInt(temp_str) ;
temp_str = pIni->ReadString( "system" , "xuanzhuan2" , "361" );
if ( temp_str == "361" )
{
ShowMessage("读取拼接文件路径出错!");
Application->Terminate() ;
}
zhuan_2 = StrToInt(temp_str) ;
int aaa=1 ;
}
__finally
{
if(pIni)
delete pIni;
pIni = NULL ;
}
if(order == 0)
{
img1 = cvLoadImage( "c:\\temp1.bmp", 0 );
img2 = cvLoadImage( "c:\\temp2.bmp", 0 );
}
else if(order == 1)
{
img2 = cvLoadImage( "c:\\temp1.bmp", 0 );
img1 = cvLoadImage( "c:\\temp2.bmp", 0 );
}
if(is_zhuan == 1)
{
img1 = this->XuanZhuan(img1,zhuan_1);
img2 = this->XuanZhuan(img2,zhuan_2);
}
int w = img1->width ;
int h = img1->height ;
w = img1->width ;
if(angle==0)
{
img3 = cvCreateImage( cvSize(w1+w2,h ), 8, 1 );
CvRect roi1,roi2;
roi1.x = 0 ;
roi1.y = 0 ;
roi1.width = w1 ;
roi1.height= img1->height ;
// roi2 = roi1 ;
cvSetImageROI( img3 , roi1 );
cvSetImageROI( img1 , roi1 );
cvCopy ( img1, img3 , NULL );
roi1.x = w - w2 ;
roi1.y = 0 ;
roi1.width = w2 ;
roi1.height = h ;
cvSetImageROI( img2 , roi1 );
roi2.x = w1 ;
roi2.y = 0 ;
roi2.width = w2 ;
roi2.height= h ;
cvSetImageROI( img3 , roi2 );
cvCopy ( img2, img3 , NULL );
cvResetImageROI(img3);
}
else if (angle ==1)
{
int h1 = w1 ;
int h2 = w2 ;
img3 = cvCreateImage( cvSize(w,h1+h2 ), 8, 1 );
CvRect roi1,roi2;
roi1.x = 0 ;
roi1.y = 0 ;
roi1.width = w ;
roi1.height= h1 ;
cvSetImageROI( img3 , roi1 );
cvSetImageROI( img1 , roi1 );
cvCopy ( img1, img3 , NULL );
roi1.x = 0 ;
roi1.y = h - h2 ;
roi1.width = w ;
roi1.height = h2 ;
cvSetImageROI( img2 , roi1 );
roi2.x = 0 ;
roi2.y = h1 ;
roi2.width = w ;
roi2.height= h2 ;
cvSetImageROI( img3 , roi2 );
cvCopy ( img2, img3 , NULL );
cvResetImageROI(img3);
}
img4 = cvCreateImage( cvSize(img3->height,img3->width), 8, 1 );
uchar temp_point ;
int hh = img4->height ;
if(angle==0)
{
cvSaveImage( "c:\\temp.bmp", img3 );
cvSaveImage( "c:\\temp.jpg", img3 );
}
else if(angle==1)
{
for( int i=0 ; i<img3->width ; i++ )
for( int j=0 ; j<img3->height; j++ )
{
temp_point = this->GetPointValue(img3,i,j);
this->SetPointValue(img4,j,hh-i-1,temp_point) ;
}
cvSaveImage( "c:\\temp3.bmp", img3 );
cvSaveImage( "c:\\temp3.jpg", img3 );
cvSaveImage( "c:\\temp.bmp", img4 );
cvSaveImage( "c:\\temp.jpg", img4 );
}
cvReleaseImage( & img1 );
cvReleaseImage( & img2 );
cvReleaseImage( & img3 );
cvReleaseImage( & img4 );
*/
}
//---------------------------------------------------------------------------
//============================================================================
__fastcall TForm1::WeiCaiControl()
{
CvScalar s1;
//伪彩控制赋值
this->int_in_min = this->TrackBar_in_min->Position ;
this->int_in_max = this->TrackBar_in_max->Position ;
this->int_out_min= this->TrackBar_out_min->Position ;
this->int_out_max= this->TrackBar_out_max->Position ;
img1 = cvLoadImage(img_name.c_str() , 1 );
for(int i=0;i<img1->height;i++)
for(int j=0;j<img1->width;j++)
{
s1 = cvGet2D(img1,i,j);
//动态编码法
double l1,l2,l3,l4,l5,w,temp;
double max,min;
min = (double)this->int_out_min ;
max = (double)this->int_out_max ;
l1 = (double)this->int_in_min;
l5 = (double)this->int_in_max;
w = (l5-l1)/4;
l2 = l1 + w ;
l3 = l2 + w ;
l4 = l3 + w ;
temp = s1.val[0];
if(temp<l2)
{
s1.val[2] = min ; //红
s1.val[1] = min ; //绿
s1.val[0] = temp*(max/w);//蓝
}
else if(temp>=l2&&temp<l3)
{
s1.val[2] = min ;
s1.val[1] = (temp-l2)*(max/w) ;
s1.val[0] = (l3-temp)*(max/w) ;
}
else if(temp>l3&&temp<=l4)
{
s1.val[2] = (temp-l3)*(max/w) ;
s1.val[1] = max;
s1.val[0] = min;
}
else if(temp>l4)
{
s1.val[2] = max ;
s1.val[1] = (max-temp)*(max/w) ;
s1.val[0] = min ;
}
cvSet2D(img1,i,j,s1);
}
cvShowImage("Image2",img1);
}
//============================================================================
unsigned char __fastcall TForm1::GetPointValue(IplImage *pImg,int x,int y)
{
return ((uchar*)(pImg->imageData + pImg->widthStep*y))[x];
}
//============================================================================
//设定图像某点的灰度值
__fastcall TForm1::SetPointValue(IplImage *pImg,int x,int y,uchar value)
{