ImageProcessor - PPilger/text-detection GitHub Wiki

Image processors are used to manipulate an image.

BackgroundProcessor

Creates a binary image by removing the background of the image. The background is calculated using a median filter.

Usage

This processor should rather be used than BinaryProcessor or BinaryColorProcessor. Also see [Image Processing](Image Processing) for further information.

Parameters

medianSize

Defines the size of the median filter.

A reasonable approach is setting medianSize just high enough so that all text disappears. MedianProcessor can be used to figure out the value.

difference

Defines the valid differences between the background and the image.

A reasonable approach is setting a minimum value high enough so that the text can be read well.

BinaryProcessor and BinaryColorProcessor

Creates a binary image by setting a range of color values to white and all others to black.

Usage

BackgroundProcessor should be used instead of this one. Also see [Image Processing](Image Processing) for further information.

Parameters

value, red, green, blue

Every one of these parameters defines the range of valid values for a color channel. Set these parameters as strict as possible (it should still be possible to read it well).

e.g. by calculating the minimum and maximum brightness of some text probes.

and

Defines if all 3 rules have to apply (and = true), or just one (and = false).

ChromaticityProcessor

Sets all pixels with an invalid chromaticity to zero (black). The chromaticity is defined by color value divided by the brightness.

Usage

Can be used to remove objects with a different color than the text.

Parameters

red, green, blue

Every one of these parameters defines the range of valid chromaticities for a color channel. Set these parameters as strict as possible (it should still be possible to read it well).

e.g. by calculating the minimum and maximum chromaticity of some text probes.

DensityProcessor

This processor can erase pixels with invalid density. The density is the average pixel value in a certain area around each pixel.

Usage

It can be used to remove objects with a different density than normal text. e.g. small objects, lines, ...

Parameters

areaSize

Defines the size of the area (areaSize * areaSize) that is used to calculate the density.

A reasonable value is the line height in pixel.

dilSize

As density is higher in the middle of a letter/word, the density-values are expanded, so that pixels at the edge of a letter/word are not erased.

A reasonable approach is setting dilSize equal to areaSize.

density

Defines the valid range of densities.

The best approach is trying to guess and adjust the density value. Using IMinimum is recommended, for the use case described above.

EraseProcessor and MaskProcessor

These processors can merge two binary images.

  • EraseProcessor sets every pixel black where the mask is white.
  • MaskProcessor sets every pixel black where the mask is black.

Usage

EraseProcessor can be used to remove lines in an image. The lines can be detected seperately and then they can be erased in the image.

FirstDerivativeProcessor

Removes areas with invalid first derivatives. The first derivative is computed using a vertical and a horizontal sobel filter (the maximum of these two) on the grayscale image.

Usage

As text has normally high derivatives because of the strong edges. So this processor may be used to remove background objects with weak edges.

Parameters

firstDerivative

Defines the valid range of derivatives.

The best approach is trying to guess and adjust the value. Using IMinimum is recommended, for the use case described above.

dilSize

As the derivatives are only high at the edge of a line (or point), the values are expanded, so that pixels near to an edge also get a good rating.

A reasonable value is the line-height.

LineSegmentsProcessor

This processor detects line segments in an image using hough transform. The output image is a black image with the detected lines drawn on it in white.

Usage

Prepare a binary image where the lines are clearly visible. Then use the LineSegmentsProcessor to detect the lines. At the end you erase the lines in your image using the EraseProcessor.

Parameters

houghThreshold

Defines the threshold for the hough transformation.

length

Defines the minimum line length (shorter lines won't be detected).

gap

Defines the maximum gap between line fragments (all fragments with a valid gap are connected to one line).

MedianProcessor

The purpose of this processor is to determine the parameter medianSize of BackgroundProcessor. See BackgroundProcessor for more details.

Morphological ImageProcessors

These processors do morphological operations on the image.

Usage

  • Use DilateProcessor to let the white area grow.
  • Use ErodeProcessor to let the black area grow.
  • Use OpenProcessor to split an object.
  • Use CloseProcessor to connect two seperated objects.

Parameters

size

Defines the size of the rectangle used as structuring element.

  • Dilate, Erode: floor(size/2) is the amount of pixels the area grows / shrinks in every direction.
  • Open: floor(size/2) is the distance of the link that should be removed.
  • Close: floor(size/2) is the distance of the objects that should be linked.

PerimeterProcessor

This processor can erase pixels with invalid perimeter. The perimeter is calculated using a contour detection.

Usage

As the ContourFeatureDetector also has the ability to remove objects with invalid perimeter, the PerimeterProcessor should only be used if really necessary. It can be used to remove too large or too small objects.

Parameters

perimeter

Defines the valid range of perimeters.

The best approach is trying to guess and adjust the value.

SecondDerivativeProcessor

Removes areas with invalid second derivatives. The second derivative is computed using a laplace filter on the grayscale image.

Usage

As text has normally high second derivatives because of the strong edges. So this processor may be used to remove background objects with weak edges.

Parameters

laplaceSize

Defines the size of the laplace filter.

A reasonable value is 3.

secondDerivative

Defines the valid range of second derivatives.

The best approach is trying to guess and adjust the value. Using IMinimum is recommended, for the use case described above.

dilSize

As the second derivatives are only high at the edge of a line (or point), the values are expanded, so that pixels near to an edge also get a good rating.

A reasonable value is the line-height.

SkelettonProcessor

This processor transforms the image with the skeleton operator (every object is replaced by lines along its center). As a side product the thickness is calculated and can be validated.

Usage

It can be used to remove too thick objects. As the lines are very thin, it is recommended to use a DilateProcessor or OpenProcessor afterwards to close gaps.

Parameters

thickness

Defines the valid range of thickness.

The best approach is trying to guess and adjust the value. Using IMaximum is recommended for the use case described above.

ThicknessProcessor

Erases thick parts in the image. This is done by removing the opened image from the original (the difference between the opened image and the original is the result).

Usage

It can be used to remove too thick objects. It works very well for line detection. For text detection ´SkelettonProcessor` delivers better results.

Parameters

openSize

Defines the size of the open operation.

A reasonable value is the maximum line width in pixel (for line detection) or the size of a letter (for text detection).

dilSize

Defines the size of the dilation operation done after opening. As a result the edge of thick objects get removed too.