FIBITMAP *DLL_CALLCONV FIA_Binary3x3Closing (FIBITMAP * src) { const double vals[9]={1,1,1,1,1,1,1,1,1}; FilterKernel kernel = FIA_NewKernel(1, 1, vals, 9.0); FIABITMAP *dst_FIA = FIA_SetBorder(src, 1, 1, BorderType_Constant, 0); FIBITMAP *dst = FIA_BinaryClosing(dst_FIA, kernel); FIA_Unload (dst_FIA); return dst; }
FIBITMAP *DLL_CALLCONV FIA_BinaryOuterBorder (FIBITMAP * src) { const double vals[9]={1,1,1,1,1,1,1,1,1}; FilterKernel kernel = FIA_NewKernel(1, 1, vals, 9.0); FIABITMAP *dst_FIA = FIA_SetBorder(src, 1, 1, BorderType_Constant, 0); FIBITMAP *dst = FIA_BinaryDilation(dst_FIA, kernel); FIA_Unload (dst_FIA); // FIA_InPlaceConvertToInt32Type (&dst, 0); // FIA_SubtractGreyLevelImages(dst, src); // FIA_InPlaceConvertToStandardType(&dst, 0); FIA_Subtract(dst, src); return dst; }
FIBITMAP *DLL_CALLCONV FIA_BinaryClosing (FIABITMAP * src, FilterKernel kernel) { // Dialation followed by a erosion. FIBITMAP *tmp = FIA_BinaryDilation (src, kernel); FIABITMAP *border_dib = FIA_SetBorder (tmp, kernel.x_radius, kernel.y_radius, BorderType_Constant, 0.0); FreeImage_Unload (tmp); tmp = FIA_BinaryErosion (border_dib, kernel); FIA_Unload (border_dib); return tmp; };
static void TestFIA_ErosionTest(CuTest* tc) { const char *file = TEST_DATA_DIR "\\morpholology_test.bmp"; FIBITMAP *dib1 = FIA_LoadFIBFromFile(file); CuAssertTrue(tc, dib1 != NULL); FIBITMAP *threshold_dib = FreeImage_Threshold(dib1, 20); CuAssertTrue(tc, threshold_dib != NULL); FIBITMAP *threshold_8bit_dib = FreeImage_ConvertTo8Bits(threshold_dib); CuAssertTrue(tc, threshold_8bit_dib != NULL); FIABITMAP *border_dib = FIA_SetBorder(threshold_8bit_dib, 2, 2 , BorderType_Constant, 0.0); PROFILE_START("ErosionFilter"); FilterKernel kernel = FIA_NewKernel(2, 2, kernel_values, 1.0); FIBITMAP* result_dib = FIA_BinaryErosion(border_dib, kernel); CuAssertTrue(tc, result_dib != NULL); PROFILE_STOP("ErosionFilter"); FIA_SaveFIBToFile(result_dib, TEST_DATA_OUTPUT_DIR "\\erosion_result.jpg", BIT24); result_dib = FIA_BinaryInnerBorder(threshold_8bit_dib); FIA_SimpleSaveFIBToFile(result_dib, TEST_DATA_OUTPUT_DIR "morphology/inner_border_result.bmp"); FreeImage_Unload(dib1); FreeImage_Unload(threshold_dib); FreeImage_Unload(threshold_8bit_dib); FIA_Unload(border_dib); FreeImage_Unload(result_dib); }
static void TestFIA_ClosingTest(CuTest* tc) { const char *file = TEST_DATA_DIR "\\morpholology_test.bmp"; FIBITMAP *dib1 = FIA_LoadFIBFromFile(file); CuAssertTrue(tc, dib1 != NULL); FIBITMAP *threshold_dib = FreeImage_Threshold(dib1, 20); CuAssertTrue(tc, threshold_dib != NULL); FIBITMAP *threshold_8bit_dib = FreeImage_ConvertTo8Bits(threshold_dib); CuAssertTrue(tc, threshold_8bit_dib != NULL); FIABITMAP *border_dib = FIA_SetBorder(threshold_8bit_dib, 2, 2 , BorderType_Constant, 0.0); FilterKernel kernel = FIA_NewKernel(2, 2, kernel_values, 1.0); FIBITMAP* result_dib = FIA_BinaryClosing(border_dib, kernel); CuAssertTrue(tc, result_dib != NULL); FIA_SaveFIBToFile(result_dib, TEST_DATA_OUTPUT_DIR "\\closing_result.jpg", BIT24); // Test of convinience 3x3 function result_dib = FIA_Binary3x3Closing(threshold_8bit_dib); FIA_SimpleSaveFIBToFile(result_dib, TEST_DATA_OUTPUT_DIR "morphology/closing3x3_result.bmp"); FreeImage_Unload(dib1); FreeImage_Unload(threshold_dib); FreeImage_Unload(threshold_8bit_dib); FIA_Unload(border_dib); FreeImage_Unload(result_dib); }
FIABITMAP *DLL_CALLCONV FIA_SetZeroBorder (FIBITMAP * src, int xborder, int yborder) { return FIA_SetBorder (src, xborder, yborder, BorderType_Constant, 0.0); }