OCR SDK Knowledge Base

Article ID: 1131 | Category: Image Processing | Type: Tips & Tricks | Last Modified: 9/11/2015

Garbage

Description

How to remove garbage from the image?

Solution

A. Use RemoveGarbage method of the ImageDocument object.

or

B. Use AddRemoveGarbageRegion method of the ImageModification object and Modify method of the ImageDocument object.

Please see the code snippet in C++ below. The more detailed description of these methods can be found in Help.

// Discard image in order to get correct results after garbage removing
CSafePtr<IPrepareImageMode> prepareImageMode;
FREngine->CreatePrepareImageMode(&prepareImageMode);
prepareImageMode->put_DiscardColorImage(TRUE);

// Open image
CSafePtr <IImageDocument> imageDoc;
FREngine->PrepareAndOpenImage(imageFilePath, prepareImageMode, 0, documentInfo, &imageDoc);

// Create and implement image modification
CSafePtr<IImageModification> imageModification;
FREngine->CreateImageModification(&imageModification);

// The region of modification is equal to whole page
CSafePtr<IRegion> region;
FREngine->CreateRegion(&region);
CSafePtr<IImage> image;
imageDoc->get_BlackWhiteImage(&image);
long width, height;
image->get_Width(&width);
image->get_Height(&height);
region->AddRect(0, 0, width, height);

// Remove black dots on the white background with the garbaze size=100 pixels. The garbage size is a number of pixels in a group of connected pixels. For example, small text objects like dots are about 30x30 pixels (garbaze size=600 pixels), so the garbage, removing should not affect any meaningful data, but cleans the image.
imageModification->AddRemoveGarbageRegion(region, 0, 100);

// Modify the ImageDocument object
imageDoc->Modify(imageModification);

// Put the modified image into IImage object and create FRDocument
imageDoc->get_BlackWhiteImage(&image);
CSafePtr<IFRDocument> frDocument;
FREngine->CreateFRDocument(&frDocument);
frDocument->AddImage(imageDoc);

// Set the parameter to remove garbage
CSafePtr<IPageProcessingParams> pageProcessingParams;
FREngine->CreatePageProcessingParams(&pageProcessingParams);
CSafePtr<IObjectsExtractionParams> objectsExtractionParams;
pageProcessingParams->get_ObjectsExtractionParams(&objectsExtractionParams);
objectsExtractionParams->put_RemoveGarbage(TRUE);

// Process
frDocument->Process(pageProcessingParams, synthesisParamsForPage, synthesisParamsForDocument);

544 people think this is helpful.
Was this information helpful to you?