When we meet a semantic segmentation task, like medical image segmentation, we usually using a software called ‘snap-itk’. It has a lot of function to help users mark a label of image, saving images and its segmentation with file format of NII. So it’s really powerful but there is a disadvantage on it for the file format NII can not be shown as a brief thumbnail on no matter Windows nor Linux systems. Here I write a simple image and mask tool kit using visual C++, mainly using the transparent property of Class Window on Windows NT system. OK, let’s begin our journey.
For the super large thumbnail of images on windows having meeting my scanning needs of images and maskers, so the rest of the task is just doing a tool that can cover the masker upon the image. Following the principle of simple and brief, i decide to design a image reader and a masker reader. Drag the image onto the image reader to open a image and with the same operation on masker it will open right on the top of image with a fully transparency of front ground label and a half transparency of background.
A image reader is easy to create. Just follow the visual studio windows program wizard. And in the main function
//
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
//
I take advantage of lpCmdLine to find the dragged image path. Like this in function:
//
p = (WCHAR*)lpCmdLine;
//
And p is a global point variable to save the image path information:
//
WCHAR *p = NULL;
//
Then we can reader the target image in windows message call back processing
Function like this:
//
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
memdc = CreateCompatibleDC(hdc); //获取内存设备环境
CImage image;
image.Load(p);
//根据image获得hBitmapt
hbg = image.Detach();
SelectObject(memdc, hbg);
GetObject(hbg, sizeof(BITMAP), (LPVOID)&bm);//获取位图尺寸
BitBlt(ps.hdc, 0, 0, bm.bmWidth, bm.bmHeight, memdc, 0, 0, SRCCOPY);
EndPaint(hWnd, &ps);
}
break;
//
Here we finish our image reader designing, It’s simple. isn’t it?
Secondly phase, designing a mask reader. We hope when it opened, it’s initial position and size is right coincide to the image. So first we design a same image reader as presented upon, and then we set it always on the top and transparent, like this:
//
hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) | WS_EX_LAYERED | WS_EX_TRANSPARENT);
RECT rc;
GetWindowRect(GetDesktopWindow(), &rc);
::SetLayeredWindowAttributes(hWnd, RGB(255, 255, 255), 200, LWA_ALPHA | LWA_COLORKEY);
::SetWindowPos(hWnd, HWND_TOPMOST, 300, 300, 512, 512, 0);
//
On instance initialize function.
The final result presented followed: