L_SliceBitmap

Summary

Extracts individual slices from radiographic scanned film.

Syntax

#include "l_bitmap.h"

L_LTIMGCOR_API L_INT L_SliceBitmap(pBitmap, pOptions, pnDeskewAngle, pfnCallback, pUserData, uFlags)

Parameters

pBITMAPHANDLE pBitmap

Pointer to the bitmap handle referencing the bitmap to be sliced.

pSLICEBITMAPOPTIONS pOptions

Pointer to the SLICEBITMAPOPTIONS structure that LEADTOOLS uses to slice the bitmap.

L_INT *pnDeskewAngle

NULL or the address of the variable to be updated with the amount that the function rotates the sliced bitmap. The amount of rotation is expressed in hundredths of degrees. For example, 500 means 5 degrees clockwise. You can pass NULL if you do not need to check the amount of rotation. This field is updated only if SLC_DESKEW is selected from pSLICEBITMAPOPTIONS flag parameter.

BITMAPSLICECALLBACK pfnCallback

Pointer to a callback function used retrieve each slice's data and information.This callback function must return a positive number or an error code (negative number). If it returns an error code, the slicing process will stop, and the code will be passed back as the return code.The callback function must adhere to the function prototype described in the BITMAPSLICECALLBACK function.

L_VOID *pUserData

Void pointer that you can use to pass one or more additional parameters that the callback function needs.To use this feature, assign a value to a variable or create a structure that contains as many fields as you need. Then, in this parameter, pass the address of the variable or structure, casting it to L_VOID *. The callback function, which receives the address in its own pUserData parameter, can cast it to a pointer of the appropriate data type to access your variable or structure.If the additional parameters are not needed, you can pass NULL in this parameter.

L_UINT32 uFlags

Reserved for future use. Must be 0.

Returns

Value Meaning
SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.

Comments

This function does not support signed data images. It returns the error code ERROR_SIGNED_DATA_NOT_SUPPORTED if a signed data image is passed to this function.

This function is designed to extract the individual slices from radiographic scanned film. The image below shows an example of these radiographic images before and after applying the L_SliceBitmap function where we use the output data to draw a white line around each separate slice.

image\BeforeSliceBitmap.gif

Film Before Function Is Called

image\AfterSliceBitmap.gif

Film After Function Is Called

To update a status bar or detect a user interrupt during execution of this function, refer to L_SetStatusCallback.

This function supports 12 and 16-bit grayscale and 48 and 64-bit color images. Support for 12 and 16-bit grayscale and 48 and 64-bit color images is available in the Document and Medical Imaging toolkits.

This function does not support 32-bit grayscale images. It returns the error code ERROR_GRAY32_UNSUPPORTED if a 32-bit grayscale image is passed to this function.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

typedef struct tagSLICEBITMAPUSERINFO 
{ 
   L_TCHAR SlicesFolder[L_MAXPATH]; 
   L_UINT  SlicesCount; 
 
} 
SLICEBITMAPUSERINFO, * pSLICEBITMAPUSERINFO; 
 
L_INT EXT_CALLBACK ExampleSliceCB(pBITMAPHANDLE pBitmap, LPRECT lpSliceRect, L_INT nAngle, L_VOID* pUserData) 
{ 
   pSLICEBITMAPUSERINFO pSlicesUserInfo; 
   L_TCHAR              szDirectory[L_MAXPATH]; 
   L_TCHAR              S[30]; 
   L_INT                nRet; 
 
   UNREFERENCED_PARAMETER(lpSliceRect); 
   UNREFERENCED_PARAMETER(nAngle); 
 
   pSlicesUserInfo = (pSLICEBITMAPUSERINFO)pUserData; 
 
   lstrcpy(szDirectory, pSlicesUserInfo->SlicesFolder); 
   lstrcat(szDirectory, TEXT("\\")); 
   wsprintf(S, TEXT("%d.bmp"), (pSlicesUserInfo->SlicesCount)); 
   lstrcat(szDirectory, S); 
 
   nRet = L_SaveFile(szDirectory, pBitmap, FILE_BMP, 24, 0, SAVEFILE_FIXEDPALETTE, NULL, NULL, NULL); 
   if (nRet == SUCCESS) 
   { 
      pSlicesUserInfo->SlicesCount++; 
      L_FreeBitmap(pBitmap); 
      GlobalFreePtr(pBitmap); 
   } 
 
   return SUCCESS; 
} 
 
L_INT SliceBitmapExample(HWND hWnd) 
{ 
   SLICEBITMAPOPTIONS   Options; 
   SLICEBITMAPUSERINFO  UserData; 
   L_INT                nRet; 
   L_TCHAR              S[30] = TEXT(""); 
   L_TCHAR              Message[512] = TEXT(""); 
   BITMAPHANDLE         LeadBitmap; 
 
   /* Load the bitmap, keeping the bits per pixel of the file */ 
   nRet = L_LoadBitmap(MAKE_IMAGE_PATH(TEXT("slice.tif")), &LeadBitmap, sizeof(BITMAPHANDLE), 0, ORDER_BGR, NULL, NULL); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   // Deskew the sliced image, the deskew angle is located between -5 and 5 degrees 
   Options.uStructSize = sizeof(SLICEBITMAPOPTIONS); 
   Options.uFlags = SLC_DESKEW | SLC_DSKW_LINEAR | SLC_CUTSLICES; 
   Options.uMaxDeskewAngle = 500; 
   Options.crFill = RGB(0, 0, 0); 
 
   lstrcpy(UserData.SlicesFolder, MAKE_IMAGE_PATH(TEXT("Slices"))); 
   UserData.SlicesCount = 0; 
 
   nRet = L_SliceBitmap(&LeadBitmap, &Options, NULL, ExampleSliceCB, (L_VOID*)(&UserData), 0); 
   if (nRet != SUCCESS) 
      return nRet; 
 
   _stprintf_s(Message, MAX_PATH, TEXT("SliceBitmap Example: The number of sliced image is %d\n"), UserData.SlicesCount); 
   _tprintf(_T("%s"), Message); 
 
   return SUCCESS; 
} 
Help Version 23.0.2024.2.29
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2024 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Raster Imaging C API Help

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.