CIB image toolbox technical manual

6. Image processing algorithms: Filters

6.1. Affine transform filters

CroppingFilter
DocumentCropper
DocumentDeskewer
FlippingFilter
ResizeFilter
RotationFilter
DocumentCleaner
RotateAndMirrorFilter

CroppingFilter

This filter allows cropping of defined area of original image. Area for cropping can be defined in two ways:

  • By separated borders,
  • By single line.

In both cases you should keep in mind coordinate system of image. Pixel with coordinates (0;0) is located in top left corner of image:

Cropping filter

For example definitions

<ProcessingProfile>
...
 <CroppingFilter>   <IsResizingToSourceSizeRequired>1</IsResizingToSourceSizeRequired>    <CroppingArea>100;500;100;500</CroppingArea>  </CroppingFilter>
...
</ProcessingProfile>
<ProcessingProfile>
...  <CroppingFilter>    <IsResizingToSourceSizeRequired>1</IsResizingToSourceSizeRequired>   <Top>100</Top>   <Bottom>500</Bottom> <Left>100</Left> <Right>500</Right> </CroppingFilter>
...
</ProcessingProfile>

are equal.

Also filter can be used for cropping quadrangular areas. In this case user should define area as set of four clockwise points in format x0;y0;x1;y1;x2;y2;x3;y3:

<ProcessingProfile>
... <CroppingFilter>  <IsResizingToSourceSizeRequired>1</IsResizingToSourceSizeRequired>
 <CroppingArea>100;100;500;250;500;500;150;500</CroppingArea>
</CroppingFilter>
...
</ProcessingProfile>

In addition with usage of flag IsResizingToSourceSizeRequired (if it is not equal 0) result of cropping can be resized to size of original image.

Also you can define background color:

<BackgroundColor>0;0;0</BackgroundColor>


DocumentCropper

The filter auto-crops an input image.

This algorithm has no parameters.

Example

<step command="ipl"expected-result-code="0" name="ImageProcessingStep_page_1” timeout="0">
<properties>
<property name="WorkSpace">.\</property>
<property name="OperationName">DocumentCropper</property>
<property name="OutputFileName">cropedImage.png</property>
<property name="OutputDirectory">.\</property>
<property name="InputFilename">inputs\Versatel.png</property>
<property name="TraceFilename">file.log</property>
</properties>
</step>

DocumentDeskewer

The filter deskews an input image.

Parameters:

Property Name

Description

Default value

Profile:DocumentDeskewer/DetectOrientation

Detects image orientation and rotates it to the correct position (possible degrees of rotation only multiple of 90).

1

 

<step command="ipl" expected-result-code="0" name="ImageProcessingStep_page_1” timeout="0">
<properties>
<property name="WorkSpace">.\</property>
<property name="OperationName">DocumentDeskewer</property>
<property name="OutputFileName">deskewedImage.png</property>
<property name="OutputDirectory">.\</property>
<property name="InputFilename">inputs\Versatel.png</property>
<property name="TraceFilename">file.log</property>
</properties>
</step>

FlippingFilter

Flips an input image.

Parameters:

Property Name

Description

Default value

FlippingDirectionCode

Code of flipping operation direction:

  • 0 means flipping around the x-axis;
  • positive value (for example, 1) means flipping around y-axis;
  • negative value (for example, -1) means flipping around both axes.

 

1


ResizeFilter

Image resizing filter.

Parameters of image resizing can be set in two ways:

By scaling. In this case we should set parameter "ResizeFilter/ResizingParameter" to required scale value:

<ProcessingProfile>
...
 <ResizeFilter>  <ResizingParameter>0.5</ResizingParameter>
</ResizeFilter>
...
\endcod
</ProcessingProfile>e
-# By defining of target size. In this case we should set parameter
"ResizeFilter/ResizingParameter"
to required size value:
\code{.xml}
<ProcessingProfile>
... <ResizeFilter>   <ResizingParameter>W;H</ResizingParameter>  </ResizeFilter>
...
</ProcessingProfile>

where W is target width, H – height. If W or H is equal to 0 then this value will be calculated depends on other size and source image geometry. For example:

<ProcessingProfile>
...  <ResizeFilter>
    <ResizingParameter>0;1000</ResizingParameter>
</ResizeFilter>
...
</ProcessingProfile>

In this case width will be calculated:

height = 1000;

width = sourceImage.Width * (height / sourceImage.Height);

If W or H is less than 0 or empty then corresponding size will not be changed. For example samples

<ProcessingProfile>
...  <ResizeFilter>    <ResizingParameter>-1;1000</ResizingParameter>  </ResizeFilter>
...
</ProcessingProfile>

and

<ProcessingProfile>
...  <ResizeFilter>   <ResizingParameter>;1000</ResizingParameter>
</ResizeFilter>
...
</ProcessingProfile>

are equal and create image with width <sourceImage.Width>x1000 pixels.


RotationFilter

Interface for image clockwise rotation filter.

Property name

Description

Default value

RotationAngle

Rotation angle (in degrees)

0.0


DocumentCleaner

The DocumentCleaner gets an input image and tries to eliminate fog and uneven light so that the output looks almost like a scan.

Parameters of this filter can be described in profile:

<ProcessingProfile>
...  <DocumentCleaner>    <BrightSpots>0</BrightSpots>
</DocumentCleaner>
...
</ProcessingProfile>

Property name

Description

Default value

BrightSpots

Enable this if the input image contains bright spots, for better performance of the algorithm.

false


RotateAndMirrorFilter

Filter for rotation and image mirroring.

Parameters of this filter can be described in profile:

<ProcessingProfile>
... <RotateAndMirrorFilter>   <Degrees>0</Degrees>  <Mirror>false</Mirror>
</RotateAndMirrorFilter>
...
</ProcessingProfile>

Property name

Description

Default value

Degrees

Degrees of rotation to be applied, only multiple of 90.

0

Mirror

If enabled, image will be mirrored.

false