Reference Guide
Programming / Document Cleanup / Removing lines
In This Topic
    Removing lines
    In This Topic

    In this tutorial, you will learn how to easily remove lines from your documents as a reason of preprocessing for OCR purposes or others.

    Before / After

    There are two ways to remove lines from your image:

    1. If you want to remove all lines that usually occur in form, let the engine handle finding the lines internally.

      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(), "Removing lines Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
      Else
          'Now you clean up your lines.
          Dim status As GdPictureStatus = oGdPictureImaging.RemoveLines(imageId, LineRemoveOrientation.Horizontal Or LineRemoveOrientation.Horizontal)
          If status <> GdPictureStatus.OK Then
              MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Removing lines Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
          Else
              'After you are done with your processing, you can save the image.
              status = oGdPictureImaging.SaveAsTIFF(imageId, "cleanedImage.tif", TiffCompression.TiffCompressionAUTO)
              If status <> GdPictureStatus.OK Then
                  MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Removing lines 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(), "Removing lines Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
      else
      {
          //Now you clean up your lines.
          GdPictureStatus status = oGdPictureImaging.RemoveLines(imageId, LineRemoveOrientation.Horizontal | LineRemoveOrientation.Horizontal);
          if (status != GdPictureStatus.OK)
          {
              MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Removing lines Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
          else
          {
              //After you are done with your processing, you can save the image.
              status = oGdPictureImaging.SaveAsTIFF(imageId, "cleanedImage.tif", TiffCompression.TiffCompressionAUTO);
              if (status != GdPictureStatus.OK)
              {
                  MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Removing lines Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
              }
          }
          oGdPictureImaging.ReleaseGdPictureImage(imageId);
      }
      oGdPictureImaging.Dispose();
    2. If you know, what kind of lines you have (length, size, connectivity, etc) and you want to specify the details for the engine to only remove lines with those properties.

      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(), "Removing lines Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
      Else
          'Now you clean up your lines.
          Dim maxLineGap As Integer = 10
          Dim maxLineThickness As Integer = 7
          Dim maxLineLength As Integer = 500
          Dim maxInterception As Integer = 5
          Dim reconnectBrokenCharacters As Boolean = True
          Dim status As GdPictureStatus = oGdPictureImaging.RemoveLines(imageId, LineRemoveOrientation.Horizontal, maxLineGap, maxLineThickness, maxLineLength, maxInterception, _
              reconnectBrokenCharacters)
          If status <> GdPictureStatus.OK Then
              MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Removing lines Example", MessageBoxButtons.OK, MessageBoxIcon.Error)
          Else
              'After you are done with your processing, you can save the image.
              status = oGdPictureImaging.SaveAsTIFF(imageId, "cleanedImage.tif", TiffCompression.TiffCompressionAUTO)
              If status <> GdPictureStatus.OK Then
                  MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Removing lines 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(), "Removing lines Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
      }
      else
      {
          //Now you clean up your lines.
          int maxLineGap = 10;
          int maxLineThickness = 7;
          int maxLineLength = 500;
          int maxInterception = 5;
          bool reconnectBrokenCharacters = true;
          GdPictureStatus status = oGdPictureImaging.RemoveLines(imageId, LineRemoveOrientation.Horizontal, maxLineGap, maxLineThickness, maxLineLength, maxInterception, reconnectBrokenCharacters);
          if (status != GdPictureStatus.OK)
          {
              MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Removing lines Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
          }
          else
          {
              //After you are done with your processing, you can save the image.
              status = oGdPictureImaging.SaveAsTIFF(imageId, "cleanedImage.tif", TiffCompression.TiffCompressionAUTO);
              if (status != GdPictureStatus.OK)
              {
                  MessageBox.Show("Error: " + oGdPictureImaging.GetStat().ToString(), "Removing lines Example", MessageBoxButtons.OK, MessageBoxIcon.Error);
              }
          }
          oGdPictureImaging.ReleaseGdPictureImage(imageId);
      }
      oGdPictureImaging.Dispose();