Console How to implement DilateCommand and DespeckleCommand for image

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Moderator: Alex

Post Reply
kdhelbig
Posts: 6
Joined: Tue Jun 09, 2020 9:12 pm

Console How to implement DilateCommand and DespeckleCommand for image

Post by kdhelbig »

I'm running an OMR application and need to preprocess a DilateCommand for images.
How can this be done, any short code example or a hint on how to do would be appreciated.
(Running C#)
Regards Klaus.
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Console How to implement DilateCommand and DespeckleCommand for image

Post by Alex »

Hello Klaus,

Please do the following test:
  • Run our Forms Processing Demo.
  • Select "Template matching => Image imprint generator preprocessing..." menu, dialog for preprocesing of image imprint generator" will appear.
  • Check the "Enable image processing" checkbox, add "Dilate filter" to the commands, which must be applied to processing image, and press the "Ok" button.
  • Try to process OMR form and see the result.
Best regards, Alexander
kdhelbig
Posts: 6
Joined: Tue Jun 09, 2020 9:12 pm

Re: Console How to implement DilateCommand and DespeckleCommand for image

Post by kdhelbig »

Hello Alex,
thanks for very fast answer,
with the forms example I did an it works perfect.
After that I tried to implement into the console application without running a form.
I want to run it as 'inPlace', no error occurs, but it seems that image is not dilated (because the result is not the same as in forms applilcation).
How have I to implement the imprint generator preprocessor (I tried to do the same way as in console examples with 'Binarization', may be that is incorrect?)

Regards Klaus.
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Console How to implement DilateCommand and DespeckleCommand for image

Post by Alex »

Hello Klaus,

You need to set the image processing command in key zone recognizer if you want to preprocess image before form recognition. This can be done using the KeyZoneRecognizerCommand.ImagePreprocessing property.

VintaSoft Imaging .NET SDK contains the FormsProcessingConsoleDemo console project, which demonstrates how to recognize filled form using template form or align image according to the template image in .NET.

Please see source codes of this project.

Program.cs file has the CreateImageImprintGenerator method with the following code:

Code: Select all

        private static ImageImprintGeneratorCommand CreateImageImprintGenerator(string imprintGeneratorType)
        {
            // select image imprint generator type 
            switch (imprintGeneratorType)
            {
                case "Line":
                case "":
                    return new ImageImprintGeneratorCommand(new KeyLineRecognizerCommand());

                case "Lpattern":
                    return new ImageImprintGeneratorCommand(new KeyMarkRecognizerCommand());

                case "All":
                    KeyZoneRecognizerCommand[] command = new KeyZoneRecognizerCommand[] { new KeyLineRecognizerCommand(), new KeyMarkRecognizerCommand() };
                    return new ImageImprintGeneratorCommand(command);

                default:
                    Console.WriteLine("Unknown imprint generator type. Using default type: Line.");
                    return new ImageImprintGeneratorCommand(new KeyLineRecognizerCommand());
            }
        }
For preprocessing of source image before key zone recognition you need to modify code of CreateImageImprintGenerator method to the following code:

Code: Select all

        private static ImageImprintGeneratorCommand CreateImageImprintGenerator(string imprintGeneratorType)
        {
            // select image imprint generator type 
            switch (imprintGeneratorType)
            {
                case "Line":
                case "":
                    KeyLineRecognizerCommand keyLineRecognizerCommand = new KeyLineRecognizerCommand();
                    keyLineRecognizerCommand.ImagePreprocessing = new DilateCommand();
                    return new ImageImprintGeneratorCommand(keyLineRecognizerCommand);

                case "Lpattern":
                    return new ImageImprintGeneratorCommand(new KeyMarkRecognizerCommand());

                case "All":
                    KeyZoneRecognizerCommand[] command = new KeyZoneRecognizerCommand[] { new KeyLineRecognizerCommand(), new KeyMarkRecognizerCommand() };
                    return new ImageImprintGeneratorCommand(command);

                default:
                    Console.WriteLine("Unknown imprint generator type. Using default type: Line.");
                    return new ImageImprintGeneratorCommand(new KeyLineRecognizerCommand());
            }
        }
Best regards, Alexander
kdhelbig
Posts: 6
Joined: Tue Jun 09, 2020 9:12 pm

Re: Console How to implement DilateCommand and DespeckleCommand for image

Post by kdhelbig »

Thank you Alex, I think that helps will try it tomorrow.
Regards
Klaus.
kdhelbig
Posts: 6
Joined: Tue Jun 09, 2020 9:12 pm

Re: Console How to implement DilateCommand and DespeckleCommand for image

Post by kdhelbig »

Hi Alex,

that helpt and the Dilate Command is running as expected. Thanks for that.
But: how to add a second/third preprocess command, such as despeckle or the whole ocrpreprocess command.
I couldn't find an 'Add-method' for the 'keyLineRecognizerCommand.ImagePreprocessing', only new.

Regards
Klaus.
kdhelbig
Posts: 6
Joined: Tue Jun 09, 2020 9:12 pm

Re: Console How to implement DilateCommand and DespeckleCommand for image

Post by kdhelbig »

Hi Alex,
is there a 'combined command' example for a bulk of prepressing commands?
Or do I make a step by step excecution of different commands in the following way:
// process image in place
command1.ExecuteInPlace(processedImage);
command2.ExecuteInPlace(processedImage);
Doing this uses the second command the result of first command?
Is this correct, bedause it is 'InPlace' what means 'in memory'.

Regards
Klaus.
Alex
Site Admin
Posts: 2305
Joined: Thu Jul 10, 2008 2:21 pm

Re: Console How to implement DilateCommand and DespeckleCommand for image

Post by Alex »

Hi Klaus,

Code: Select all

that helpt and the Dilate Command is running as expected. Thanks for that.
But: how to add a second/third preprocess command, such as despeckle or the whole ocrpreprocess command.
I couldn't find an 'Add-method' for the 'keyLineRecognizerCommand.ImagePreprocessing', only new.
Sorry for delay. If you need fast response to your question, please send your question to our support at support@vintasoft.com.

You need to use the CompositeCommand class (https://www.vintasoft.com/docs/vsimagin ... mmand.html) if you want to combine several image processing commands.

For using several image processing commands (dilate and despeckle) before key zone recognition you need to modify code of CreateImageImprintGenerator method to the following code:

Code: Select all

        private static ImageImprintGeneratorCommand CreateImageImprintGenerator(string imprintGeneratorType)
        {
            // select image imprint generator type 
            switch (imprintGeneratorType)
            {
                case "Line":
                case "":
                    Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase[] commands =
                         new Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase[] {
                         new Vintasoft.Imaging.ImageProcessing.Filters.DilateCommand(),
                         new Vintasoft.Imaging.ImageProcessing.Document.DespeckleCommand()
                    };
                    KeyLineRecognizerCommand keyLineRecognizerCommand = new KeyLineRecognizerCommand();
                    keyLineRecognizerCommand.ImagePreprocessing = new Vintasoft.Imaging.ImageProcessing.CompositeCommand(commands);
                    return new ImageImprintGeneratorCommand(keyLineRecognizerCommand);

                case "Lpattern":
                    return new ImageImprintGeneratorCommand(new KeyMarkRecognizerCommand());

                case "All":
                    KeyZoneRecognizerCommand[] command = new KeyZoneRecognizerCommand[] { new KeyLineRecognizerCommand(), new KeyMarkRecognizerCommand() };
                    return new ImageImprintGeneratorCommand(command);

                default:
                    Console.WriteLine("Unknown imprint generator type. Using default type: Line.");
                    return new ImageImprintGeneratorCommand(new KeyLineRecognizerCommand());
            }
        }
Best regards, Alexander
kdhelbig
Posts: 6
Joined: Tue Jun 09, 2020 9:12 pm

Re: Console How to implement DilateCommand and DespeckleCommand for image

Post by kdhelbig »

Thank you Alex.
This was what I was looking for. ;)
Real great support!
Regards
Klaus.
Post Reply