因为要用到特别暗的图像,要分割出目标和背景,所以只有先增强,看到《一种基于Ardely分割算法的夜间图像增强方法》,但去找其引用文献的Ardely的博客却找不到了?本来想看其csdn博客步骤自己编的,但没找到,后来又看到http://blog.csdn.net/programman83/article/details/1349262点击打开链接所以直接用它的了。
/*
main test for bmp parse program
<一种基于Ardely分割算法的夜间图像增强方法>
http://blog.csdn.net/programman83/article/details/1349262
*/
#include "FileFormat.h"
#include
#include
#include
#include
using namespace std;
char* inputFileName="bmpName.txt";
char* inputBMPFileName;
#define MAXNAMELEN 32
long WINAPI WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
HWND hWndMain;
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
bool gDrawFlag;
//program starting.
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInst,LPSTR lpszCmdLine,int nCmdShow)
{
MSG msg;
if(!InitWindowsClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
gDrawFlag=true;
//Core message looping
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
by me
HWND hWnd = GetForegroundWindow();//获得活动窗口的HWND.
RECT rect;
GetWindowRect(hWnd, &rect);//获取当前窗口矩形区域
//HDC hScreenDC = GetDC(GetDesktopWindow()); //为屏幕创建设备描述表(方法1)
HDC hScreenDC = CreateDC("DISPLAY", NULL, NULL, NULL);//为屏幕创建设备描述表(方法2)
HDC MemDC = CreateCompatibleDC(hScreenDC);//用设备内存描述表去创建可在内存中处理图片的DC
SIZE screensize;
screensize.cx = rect.right - rect.left;
screensize.cy = rect.bottom - rect.top;
HBITMAP hBitmap;
hBitmap = CreateCompatibleBitmap(hScreenDC, screensize.cx, screensize.cy);
HGDIOBJ hOldBMP = SelectObject(MemDC, hBitmap);
BitBlt(MemDC, 0, 0, screensize.cx, screensize.cy, hScreenDC, rect.left, rect.top, SRCCOPY);
SelectObject(MemDC, hOldBMP);
DeleteObject(MemDC);
ReleaseDC(hWnd, hScreenDC);
return msg.wParam;
}
///
//main wndProc function: message looping
long WINAPI WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
HDC hDC;
HBRUSH hBrush;
HPEN hPen;
PAINTSTRUCT PtStr;
FILE* inputFile,* inputBMPFile;
FILE* inputFile2;
int outlineTransMode,transType;
float ampVal;
//Read In Value
float portion;
float fa,fb;
BMParse tBMParse;
if(gDrawFlag)
{
if((inputFile=fopen(inputFileName,"rb"))==NULL)
{
cout << "open inputfile error!" << endl;
// MessageBox(hWnd,"open inputfile error!","Msg Box",MB_OK);
//return 0;
}
inputBMPFileName=(char*)malloc(sizeof(char)*MAXNAMELEN);
fscanf(inputFile,"%s\r\n",inputBMPFileName);
inputBMPFileName[strlen(inputBMPFileName)+1]='\0';
if((inputBMPFile=fopen(inputBMPFileName,"rb"))==NULL)
{
cout << "open input bmp file error!" << endl;
// MessageBox(hWnd,"open input bmp file error!","Msg Box",MB_OK);
// return 0;
}
if((inputFile2=fopen("ArguSet.txt","rb"))==NULL)
{
cout << "open inputfile error!" << endl;
// MessageBox(hWnd,"open inputfile error!","Msg Box",MB_OK);
//return 0;
}
fscanf(inputFile2,"%f",&portion);
tBMParse.setReadInFile(inputBMPFile);
tBMParse.showHeadInfo();
tBMParse.parseBMPMatrix();
//-----------------------------------//
}
switch(iMessage)
{
case WM_PAINT:
if(gDrawFlag)
{
//First draw,a black line
hDC=BeginPaint(hWnd,&PtStr);
hPen=(HPEN)GetStockObject(NULL_PEN);//get empty brush
SelectObject(hDC,hPen);
hBrush=(HBRUSH)GetStockObject(BLACK_BRUSH);
SelectObject(hDC,hBrush);
hPen=CreatePen(PS_SOLID,1,RGB(0,0,255));//create pen
SelectObject(hDC,hPen);
/*Core paint program follow here*/
tBMParse.showBMP(hDC);
tBMParse.showHist(hDC,5,tBMParse.getPicHeight()+100);
tBMParse.changeGreenChannelToGrey(hDC,tBMParse.getPicWidth()+5,0);
tBMParse.showHistBackPic(hDC,10+tBMParse.getPicWidth(),tBMParse.getPicHeight()+100);
/*End of Core paint*/
DeleteObject(hPen);
DeleteObject(hBrush);
EndPaint(hWnd,&PtStr);
tBMParse.freeBMPMem();
fclose(inputFile);
fclose(inputBMPFile);
fclose(inputFile2);
gDrawFlag=false;
// MessageBox(hWnd,"HelloWorld!","Msg Box",MB_OK);
}
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hWnd,iMessage,wParam,lParam);
}
}
//Init the Window to show out.
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
HWND hWnd;
hWnd=CreateWindow("WinFill",
"test program for parse bmp file.",
WS_OVERLAPPEDWINDOW,
0,
0,
1280,
700,
NULL,
NULL,
hInstance,
NULL
);
if(!hWnd)
return FALSE;
hWndMain=hWnd;
ShowWindow(hWnd,nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
//Set wndClass Propertity
BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS wndClass;
wndClass.cbClsExtra=0;
wndClass.cbWndExtra=0;
wndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndClass.hIcon=LoadIcon(NULL,"END");
wndClass.hInstance=hInstance;
wndClass.lpfnWndProc=WndProc;
wndClass.lpszClassName="WinFill";
wndClass.lpszMenuName=NULL;
wndClass.style=CS_HREDRAW|CS_VREDRAW;
return RegisterClass(&wndClass);
}
左边是原图 右边是增强结果图 但背景也增强了 不太利于分割。。。而且这个是windows程序 我在C++6.0是运行的。。。
///
另外 我刚刚按照http://blog.csdn.net/listening5/article/details/50240147 给我的VS配置了CUDA:这个人过程写得很详细 配置成功了:
运行deviceQuery 显示: