Reference Guide
Programming / Document Cleanup / Low sampled characters: How to use Black Dilation
In This Topic
    Low sampled characters: How to use Black Dilation
    In This Topic

    Oftentimes documents are scanned with a high brightness or are converted to binary images via a bad algorithm. This process results in low sampled, unclear characters. Black Dilation is a solution to this problem.

    Here is the code example you can use.

    Copy Code
    'We assume that GdPicture has been correctly installed and unlocked.
    Dim oGdPictureImaging As New GdPictureImaging()
    'Loading the image from a file.
    Dim imageId As Integer = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif")
    'Checking if the image resource has been loaded correctly.
    If oGdPictureImaging.GetStat() <> GdPictureStatus.OK Then
        MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Black Dilation Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Else
        'Now you can dilate the black content of your image.
        Dim status As GdPictureStatus = oGdPictureImaging.FxBitonalDilate8(imageId)
        If status <> GdPictureStatus.OK Then
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Black Dilation Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
            'After you are done with your processing, you can save the image.
            status = oGdPictureImaging.SaveAsTIFF(imageId, "Dilated_Image.tif", TiffCompression.TiffCompressionAUTO)
            If status <> GdPictureStatus.OK Then
                MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Black Dilation Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        End If
        oGdPictureImaging.ReleaseGdPictureImage(imageId)
    End If
    oGdPictureImaging.Dispose()
    Copy Code
    //We assume that GdPicture has been correctly installed and unlocked.
    GdPictureImaging oGdPictureImaging = new GdPictureImaging();
    //Loading the image from a file.
    int imageId = oGdPictureImaging.CreateGdPictureImageFromFile("input.tif");
    //Checking if the image resource has been loaded correctly.
    if (oGdPictureImaging.GetStat() != GdPictureStatus.OK)
    {
        MessageBox.Show("The image can't be loaded. Error: " + oGdPictureImaging.GetStat().ToString(), "Black Dilation Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
    else
    {
        //Now you can dilate the black content of your image.
        GdPictureStatus status = oGdPictureImaging.FxBitonalDilate8(imageId);
        if (status != GdPictureStatus.OK)
        {
            MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Black Dilation Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        else
        {
            //After you are done with your processing, you can save the image.
            status = oGdPictureImaging.SaveAsTIFF(imageId, "Dilated_Image.tif", TiffCompression.TiffCompressionAUTO);
            if (status != GdPictureStatus.OK)
            {
                MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Black Dilation Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        oGdPictureImaging.ReleaseGdPictureImage(imageId);
    }
    oGdPictureImaging.Dispose();

    There are many overloads to FxBitonalDilate: The basic is FxBitonalDilate, which takes a parameter indicating the size. The larger the size is, the more dilated the black content of the image gets.

    There is also FxBitonalDilateV, which only acts in the vertical direction. FxBitonalDilate4 and FxBitonalDilate8 are two overloads, that use 4 and 8 surrounding pixels in the dilation operation respectively.

    Do play with those functions, so you can get a better sense of what they can accomplish for your documents.