📄 myimagedbdoc.cpp
字号:
D1ColorBin* readhis = NULL;//准备返回的直方图数组;
INT availablcount = 0;//统计在此范围内的记录数;
//读入库内直方图;
CString sqlquery;
sqlquery.Format("select * from %s", tablename);
myImagedataRs = new CADORecordset( &(pFrame->myAdoDb) );
if (!myImagedataRs->Open(sqlquery, CADORecordset::openUnknown))
{
//未正常连接指定表;
CString tempstr;
tempstr.Format("打不开图像数据表!!!");
AfxMessageBox(tempstr,NULL,MB_OK);
return;
}else
{
if (myImagedataRs->GetRecordCount() <= 0)
{
CString tempstr = "表中找不到对应的图像记录!";
AfxMessageBox(tempstr);
return;
}else
{
myImagedataRs->MoveFirst();
INT recordid = 0;//当前定位处记录的ID号;
do
{
BOOL tempbool = myImagedataRs->GetFieldValue("id", recordid);
if (recordid>=minid && recordid<=maxid)
{
availablcount ++;
}
myImagedataRs->MoveNext();
}while (!myImagedataRs->IsEOF());
readhis = new D1ColorBin[availablcount];//直方图数组;
INT pos = 0;//直方图数组下标;
myImagedataRs->MoveFirst();
do
{
BOOL tempbool = myImagedataRs->GetFieldValue("id", recordid);
if (recordid>=minid && recordid<=maxid)
{
LONG len = -1;
tempbool = myImagedataRs->GetFieldValue("his1dlen", readhis[pos].bincount);
readhis[pos].binunits = new D1ColorBinUnit[readhis[pos].bincount];
tempbool = myImagedataRs->GetChunk("his1d", readhis[pos].binunits);
pos++;
}
}while (!myImagedataRs->IsEOF());
}
}
myImagedataRs->Close();
*outhisarr = readhis;//返回直方图数组;
outnumber = availablcount;//数组中的元素个数;
}
void CMyImageDBDoc::OnQueryByHisd1()
{
//第一步:得到当前图像直方图;
//第二步:建立与所有库中图像对应的rank数组;
//第三步:对数组进行排序;
//第四步:排序结果写入表内rank字段;
//得到当前浏览图像的直方图,准备用于计算与其它图像的距离;
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd();
CString curid = pFrame->selID;
D1ColorBin* curhis = GetHisd1FromDB(curid);
//得到库内图像的直方图,结果放在数组中;
D1ColorBin* allhis = NULL;
INT hisnumber = 0;//数组中存储的直方图数目;
GetAllHisd1FromDB(&allhis, hisnumber);
//建立距离数组;
DOUBLE* dis = new DOUBLE[hisnumber];
//当前直方图与库内图像直方图依次计算距离
for (int i=0; i<hisnumber; i++)
{
dis[i] = myColorFeature.GetHisD1Distance( curhis, &(allhis[i]) );
}
//以下排序;
}
void CMyImageDBDoc::OnResetRank()
{
//首先得到数据库及图像的相关信息;
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd();
if (!pFrame->isDbOK)
{
CString tempstr = "先连接数据库!!,:)";
AfxMessageBox(tempstr);
return;
}
CString tablename = pFrame->tableName;
CString sqlquery;
sqlquery.Format("select * from %s", tablename);
myImagedataRs = new CADORecordset( &(pFrame->myAdoDb) );
if (!myImagedataRs->Open(sqlquery, CADORecordset::openUnknown))
{
//未正常连接指定表;
CString tempstr;
tempstr.Format("打不开图像数据表!!!");
AfxMessageBox(tempstr,NULL,MB_OK);
return;
}else
{
if (myImagedataRs->GetRecordCount() <= 0)
{
CString tempstr = "表中无任何图像记录!";
AfxMessageBox(tempstr);
return;
}else
{
myImagedataRs->Edit();
myImagedataRs->MoveFirst();
INT recordid = 0;//当前定位处记录的ID号;
do
{
BOOL tempbool = myImagedataRs->GetFieldValue("id", recordid);
tempbool = myImagedataRs->SetFieldValue("rank", recordid);
myImagedataRs->MoveNext();
}while (!myImagedataRs->IsEOF());
myImagedataRs->MoveFirst();
}
myImagedataRs->Update();
}
myImagedataRs->Close();
//刷新数据表显示;
pFrame->RefreshRs();
}
void CMyImageDBDoc::GetAllHisd1FromDB(D1ColorBin** outhisarr, INT& outnumber)
//读入所有图像的直方图
{
//首先得到数据库及图像的相关信息;
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd();
if (!pFrame->isDbOK)
{
CString tempstr = "先连接数据库!!,:)";
AfxMessageBox(tempstr);
return;
}
CString tablename = pFrame->tableName;
D1ColorBin* readhis = NULL;//准备返回的直方图数组;
//读入库内直方图;
INT recordcount;//库内记录数;
CString sqlquery;
sqlquery.Format("select * from %s", tablename);
myImagedataRs = new CADORecordset( &(pFrame->myAdoDb) );
if (!myImagedataRs->Open(sqlquery, CADORecordset::openUnknown))
{
//未正常连接指定表;
CString tempstr;
tempstr.Format("打不开图像数据表!!!");
AfxMessageBox(tempstr,NULL,MB_OK);
return;
}else
{
if (myImagedataRs->GetRecordCount() <= 0)
{
CString tempstr = "表中找不到对应的图像记录!";
AfxMessageBox(tempstr);
return;
}else
{
myImagedataRs->MoveFirst();
recordcount = myImagedataRs->GetRecordCount();
readhis = new D1ColorBin[recordcount];//直方图数组;
INT pos = 0;//直方图数组下标;
do
{
BOOL tempbool = FALSE;
LONG len = -1;
tempbool = myImagedataRs->GetFieldValue("his1dlen", readhis[pos].bincount);
readhis[pos].binunits = new D1ColorBinUnit[readhis[pos].bincount];
tempbool = myImagedataRs->GetChunk("his1d", readhis[pos].binunits);
pos++;
myImagedataRs->MoveNext();
}while (!myImagedataRs->IsEOF());
}
}
myImagedataRs->Close();
*outhisarr = readhis;//返回直方图数组;
outnumber = recordcount;//数组中的元素个数;
}
void CMyImageDBDoc::OnCancelProcess()
{
if(NULL!=myImageObject)
{
delete myImageObject;
myImageObject = NULL;
}
myImageObject = new CImageObject;
myImageObject->CreateDIBFromBits(imageWidth, imageHeight, imageData);
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd();
pFrame->pImageView->Invalidate(FALSE);
}
void CMyImageDBDoc::OnColorChannel()
{
BeginWaitCursor();
BYTE* processarr = new BYTE[imageWidth*imageHeight*3];
for (INT x=0; x<imageWidth; x++)
{
for (INT y=0; y<imageHeight; y++)
{
LONG pos = (y*imageWidth + x) * 3;
processarr[pos] = 0;//imageData[pos+1]/3;
processarr[pos+1] = imageData[pos+1];//processarr[pos];
processarr[pos+2] = 0;//processarr[pos];
}
}
//用临时数组替换原数组;
for (x=0; x<imageWidth; x++)
{
for (INT y=0; y<imageHeight; y++)
{
LONG pos = (y*imageWidth + x) * 3;
imageData[pos] = processarr[pos];
imageData[pos+1] = processarr[pos+1];
imageData[pos+2] = processarr[pos+2];
}
}
RefreshImageObject();
delete [] processarr;//删除临时数组;
processarr = NULL;
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd();
EndWaitCursor();
pFrame->pImageView->Invalidate(FALSE);
}
void CMyImageDBDoc::OnGreenLuminosity()
//根据David Bourgin,Color space FAQ,仅取绿色通道时目视效果最好。
{
BeginWaitCursor();
BYTE* processarr = new BYTE[imageWidth*imageHeight*3];
for (INT x=0; x<imageWidth; x++)
{
for (INT y=0; y<imageHeight; y++)
{
LONG pos = (y*imageWidth + x) * 3;
processarr[pos] = (BYTE) (imageData[pos+1]/1);
processarr[pos+1] = (BYTE) (processarr[pos]/1);
processarr[pos+2] = (BYTE) (processarr[pos]/1);
}
}
//用临时数组替换原数组;
for (x=0; x<imageWidth; x++)
{
for (INT y=0; y<imageHeight; y++)
{
LONG pos = (y*imageWidth + x) * 3;
imageData[pos] = processarr[pos];
imageData[pos+1] = processarr[pos+1];
imageData[pos+2] = processarr[pos+2];
}
}
RefreshImageObject();
delete [] processarr;//删除临时数组;
processarr = NULL;
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd();
EndWaitCursor();
pFrame->pImageView->Invalidate(FALSE);
}
void CMyImageDBDoc::OnItuLuminosity()
//来自David Bourgin,Color space FAQ
{
BeginWaitCursor();
BYTE* processarr = new BYTE[imageWidth*imageHeight*3];
for (INT x=0; x<imageWidth; x++)
{
for (INT y=0; y<imageHeight; y++)
{
LONG pos = (y*imageWidth + x) * 3;
BYTE tempbyte = (222*imageData[pos+2]+707*imageData[pos+2]+71*imageData[pos]) / 1000;
processarr[pos] = tempbyte;
processarr[pos+1] = tempbyte;
processarr[pos+2] = tempbyte;
}
}
//用临时数组替换原数组;
for (x=0; x<imageWidth; x++)
{
for (INT y=0; y<imageHeight; y++)
{
LONG pos = (y*imageWidth + x) * 3;
imageData[pos] = processarr[pos];
imageData[pos+1] = processarr[pos+1];
imageData[pos+2] = processarr[pos+2];
}
}
RefreshImageObject();
delete [] processarr;//删除临时数组;
processarr = NULL;
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd();
EndWaitCursor();
pFrame->pImageView->Invalidate(FALSE);
}
void CMyImageDBDoc::SegmentByPt()
//执行基于点的分割;
{
if (vtCount<=0)
{
//没有选择用于分割的类;
CString tempstr;
tempstr.Format("请选择用于分割的点类!");
AfxMessageBox(tempstr,NULL,MB_OK);
return;
}
//将各个点值输入不同类确定的高斯滤波器,取最大值输出对应的类;
BeginWaitCursor();
INT* bearr = new INT[imageWidth*imageHeight];//存放每个点所属类;
for (INT x=0; x<imageWidth; x++)
{
for (INT y=0; y<imageHeight; y++)
{
LONG pos = (y*imageWidth + x);
MyLUV temptex = GetMinmaxTexLUV(x, y);
bearr[pos] = DeterPtClass(luvData[pos], temptex, myClassVector, vtCount);//决定每个点所属的类;
}
}
//得到各分割类的RGB值,存入数组;
CRGB* classrgb = new CRGB[vtCount];
for (INT i=0; i<vtCount; i++)
{
INT bred, bgreen, bblue;
FLOAT colorl = (FLOAT) myClassVector[i].colorl;
FLOAT coloru = (FLOAT) myClassVector[i].coloru;
FLOAT colorv = (FLOAT) myClassVector[i].colorv;
myColorSpace.Luv2Rgb(colorl, coloru, colorv
, bred, bgreen, bblue);
classrgb[i].bRed = bred;
classrgb[i].bGreen = bgreen;
classrgb[i].bBlue = bblue;
}
//根据各像素点所属类重设其颜色;
for (x=0; x<imageWidth; x++)
{
for (INT y=0; y<imageHeight; y++)
{
LONG pos = (y*imageWidth + x);
INT tempi = bearr[pos];
imageData[pos*3] = classrgb[tempi].bBlue;
imageData[pos*3+1] = classrgb[tempi].bGreen;
imageData[pos*3+2] = classrgb[tempi].bRed;
}
}
RefreshImageObject();
delete [] bearr;//删除临时数组;
bearr = NULL;
delete [] classrgb;
classrgb = NULL;
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd();
EndWaitCursor();
pFrame->pImageView->Invalidate(FALSE);
}
void CMyImageDBDoc::OnLofLuv()
{
BeginWaitCursor();
for (INT x=0; x<imageWidth; x++)
{
for (INT y=0; y<imageHeight; y++)
{
LONG pos = (y*imageWidth + x);
INT tempbyte = (INT) ( luvData[pos].l * 1 );
imageData[pos*3] = tempbyte;
imageData[pos*3+1] = tempbyte;
imageData[pos*3+2] = tempbyte;
}
}
RefreshImageObject();
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd();
EndWaitCursor();
pFrame->pImageView->Invalidate(FALSE);
}
void CMyImageDBDoc::OnVofHsv()
{
BeginWaitCursor();
BYTE* processarr = new BYTE[imageWidth*imageHeight*3];
MyHSV* hsvbuff = new MyHSV[imageWidth*imageHeight];
myColorSpace.RgbtoHsv(imageData, imageWidth,
imageHeight, hsvbuff);
for (INT x=0; x<imageWidth; x++)
{
for (INT y=0; y<imageHeight; y++)
{
LONG pos = (y*imageWidth + x);
INT tempbyte = (INT) ( (1-hsvbuff[pos].s) * 255 * 0.7 );
processarr[pos*3] = tempbyte;
processarr[pos*3+1] = tempbyte;
processarr[pos*3+2] = tempbyte;
}
}
delete [] hsvbuff;
hsvbuff = NULL;
//用临时数组替换原数组;
for (x=0; x<imageWidth; x++)
{
for (INT y=0; y<imageHeight; y++)
{
LONG pos = (y*imageWidth + x) * 3;
imageData[pos] = processarr[pos];
imageData[pos+1] = processarr[pos+1];
imageData[pos+2] = processarr[pos+2];
}
}
RefreshImageObject();
delete [] processarr;//删除临时数组;
processarr = NULL;
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->GetMainWnd();
EndWaitCursor();
pFrame->pImageView->Invalidate(FALSE);
}
void CMyImageDBDoc::OnNeiError()
{
BeginWaitCursor();
BYTE* processarr = new BYTE[imageWidth*imageHeight*3];
for (INT x=0; x<imageWidth; x++)
{
for (INT y=0; y<imageHeight; y++)
{
LONG pos = (y*imageWidth + x) * 3;
processarr[pos] = imageData[pos];
processarr[pos+1] = imageData[pos+1];
processarr[pos+2] = imageData[pos+2];
}
}
//以下用每个像素点的邻域均值减该像素点值;
INT neiscale = 1;//邻域范围;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -