LBitmap::Slice

#include "ltwrappr.h"

L_INT LBitmap::Slice(pOptions, pnDeskewAngle, uFlags = 0)

pSLICEBITMAPOPTIONS pOptions;

/* pointer to a structure */

L_INT32 * pnDeskewAngle;

/* address of the deskew angle variable to be updated */

L_UINT32 uFlags;

/* flags */

Extracts individual slices from radiographic scanned film.

Parameter

Description

pOptions

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

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.

uFlags

Reserved for future use. Must be 0.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

Please note that this function is not currently supported in the C++ Class Library. However, this functionality can be implemented by calling the C DLL function directly. The following code sample indicates how to call the C DLL function from your code:

 

/*The following example finds all the slices inside some radiographic scanned film and saves them to the selected folder:*/
typedef struct tagSLICEBITMAPUSERINFO
{
  L_CHAR SlicesFolder[L_MAX_PATH];
  L_UINT  SlicesCount;
 

}SLICEBITMAPUSERINFO, * pSLICEBITMAPUSERINFO;
 

L_INT L_EXPORT EXT_CALLBACK ExampleSliceCB
  (
  pBITMAPHANDLE pBitmap,
  LPRECT lpSliceRect,
  L_INT  nAngle,
  L_VOID * pUserData
  )
{
  pSLICEBITMAPUSERINFO pSlicesUserInfo;
  L_CHAR               szDirectory[L_MAXPATH];
  L_CHAR               S[30];
  L_INT                nRet;
 

   pSlicesUserInfo = (pSLICEBITMAPUSERINFO)pUserData;
  lstrcpy(szDirectory, pSlicesUserInfo->SlicesFolder);
  strcat(szDirectory, TEXT("\\"));
  wsprintf(S,TEXT("%d.bmp"), (pSlicesUserInfo->SlicesCount));
  strcat(szDirectory, S);

  nRet = L_SAVEFILE(szDirectory, pBitmap, FILE_BMP, 24, 0, SAVEFILE_FIXEDPALETTE, NULL, NULL, NULL  );
  if(nRet == SUCCESS)
  {
     pSlicesUserInfo->SlicesCount++;
     L_FREEBITMAP(pBitmap);
     GlobalFree(pBitmap);
  }
  return SUCCESS;
}

void CDemoView::OnExampleSlicebitmap()
{
  SLICEBITMAPOPTIONS      Options;
  SLICEBITMAPUSERINFO     UserData;
  L_INT                   nRet;
  L_CHAR                  S[30] = TEXT("");
  L_CHAR                  Message[512] = TEXT("");
  L_CHAR *SlicesFolder = "e:\\slices";

  Options.uStructSize = sizeof(SLICEBITMAPOPTIONS);
  // Deskew the sliced image, the deskew angle is located between -5 and 5 degrees
  Options.uFlags = SLC_DESKEW|SLC_DSKW_LINEAR|SLC_CUTSLICES;
  Options.uMaxDeskewAngle = 500;
  Options.crFill = RGB(0,0,0);
  memcpy(UserData.SlicesFolder, SlicesFolder, L_MAXPATH);
  UserData.SlicesCount = 0;

  nRet = L_SLICEBITMAP(m_LAniWnd.GetHandle(), &Options, NULL, ExampleSliceCB, (L_VOID *)(&UserData));  
  if(nRet == SUCCESS)
  {
     lstrcpy(Message, TEXT("The number of sliced images is "));
     wsprintf(S, TEXT("%d"), (UserData.SlicesCount));
     strcat(Message, S );
     MessageBox( Message, TEXT("SliceBitmap Example"), MB_OK);
  }
}

 

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 LBitmap::Slice 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 LBase::EnableStatusCallback.

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 only in the Medical toolkits.

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.

Required DLLs and Libraries

LTIMGCOR

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

Platforms

Win32, x64.

See Also

Functions:

LBitmap::SliceCallBack

Topics:

Processing an Image

 

Raster Image Functions: Creating and Maintaining Lists of Images

 

Raster Image Functions: Processing an Image

 

Raster Image Functions: Creating and Using a Region

 

Raster Image Functions: Processing an Image

Example

#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName
class LSliceBitmap  : public LBitmap
{
public:
   LSliceBitmap();
   ~LSliceBitmap();
   virtual L_INT SliceCallBack(LBitmapBase &Bitmap, 
                                 LPRECT lpSliceRect, 
                                 L_INT nAngle);
};
LSliceBitmap::LSliceBitmap()
{
}
LSliceBitmap::~LSliceBitmap()
{
}
L_INT LSliceBitmap::SliceCallBack(LBitmapBase &Bitmap, LPRECT lpSliceRect, L_INT nAngle)
{
   UNREFERENCED_PARAMETER(nAngle);
   UNREFERENCED_PARAMETER(lpSliceRect);
   static   L_INT nCount = 1 ;
   L_TCHAR  szFileName[L_MAXPATH];
   L_INT    nRet;
   LBitmap  UserBitmap;
   wsprintf(szFileName,MAKE_IMAGE_PATH(TEXT("Slice%d.bmp")), (nCount));
   UserBitmap.SetHandle(Bitmap.GetHandle());
   nRet = UserBitmap.Save(szFileName, FILE_BMP, 24, 2, 0);
   if(nRet == SUCCESS)
   {
      (nCount)++;
      UserBitmap.Free();
      GlobalFree(UserBitmap.GetHandle());
   }
   return SUCCESS;
}
L_INT LBitmap__SliceExample(LBitmap *pBitmap)
{
   int nRet = 0;
   LSliceBitmap UserBitmap;
   SLICEBITMAPOPTIONS  Options;
   memset(&Options , 0, sizeof(Options));
   Options.uStructSize     = sizeof(Options);
   Options.uMaxDeskewAngle = 500;
   Options.crFill          =  RGB(0,0,0);
   Options.uFlags          = SLC_DESKEW | SLC_DSKW_LINEAR | SLC_CUTSLICES ;
   UserBitmap.EnableCallBack(TRUE);
   UserBitmap.SetHandle(pBitmap->GetHandle()) ;
   nRet = UserBitmap.Slice(&Options, NULL);
   pBitmap->SetHandle(UserBitmap.GetHandle()) ;
   return SUCCESS;
}