VintaSoft Imaging .NET SDK v8.7
Vintasoft.Imaging.ImageProcessing Namespace / ParallelizingProcessingCommand Class
Members Example



In This Topic
    ParallelizingProcessingCommand Class
    In This Topic
    Image processing command that executes another image processing command parallely.
    Object Model
    ParallelizingProcessingCommand ClassProcessingCommandBase ClassRegionOfInterest ClassProcessingCommandResults ClassProcessingCommandResult Class
    Syntax
    'Declaration
     
    Public Class ParallelizingProcessingCommand 
       Inherits ProcessingCommandWithRegion
    public class ParallelizingProcessingCommand : ProcessingCommandWithRegion 
    public __gc class ParallelizingProcessingCommand : public ProcessingCommandWithRegion 
    public ref class ParallelizingProcessingCommand : public ProcessingCommandWithRegion 
    Remarks
    Custom command can be executed parallely if it overrides the ProcessingCommandBase.GetRegionOptimalDecomposition method and method returns rectangles of several image regions.

    Here is a list of standard image processing commands that can be executed parallely:
    MaxThreads property defines on how many threads this command will parallely execute another command.
    Example
    This example shows how to blur image parallely.
    Public Shared Sub Test()
        ' create image
        Using image As New Vintasoft.Imaging.VintasoftImage(3000, 3000)
            ' add noise to an image
            Dim addNoize As New Vintasoft.Imaging.ImageProcessing.Filters.AddNoiseCommand()
            addNoize.ExecuteInPlace(image)
                
            ' blur image - this call prevents the wrong results of next calls
            Dim command As Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase = New Vintasoft.Imaging.ImageProcessing.Filters.BlurCommand(11)
            Using processedImage As Vintasoft.Imaging.VintasoftImage = command.Execute(image)
            End Using
                
            System.Console.WriteLine("Multithread tests of {0} command:", command)
            For maxThreads As Integer = 1 To System.Environment.ProcessorCount
                ' blur image and output an execution time in milliseconds
                
                Dim dt As System.DateTime = System.DateTime.Now
                Using processedImage As Vintasoft.Imaging.VintasoftImage = ExecuteProcessingCommand(command, maxThreads, image)
                End Using
                Dim milliseconds As Integer = CInt((System.DateTime.Now - dt).TotalMilliseconds)
                System.Console.WriteLine("{0} thread(s): {1} ms", maxThreads, milliseconds)
            Next
        End Using
    End Sub
                
    ''' <summary>
    ''' Executes a processing command on specific number of threads.
    ''' </summary>
    Private Shared Function ExecuteProcessingCommand(command As Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase, maxThreadsCount As Integer, image As Vintasoft.Imaging.VintasoftImage) As Vintasoft.Imaging.VintasoftImage
        If maxThreadsCount = 1 Then
            Return command.Execute(image)
        End If
                
        Dim parallelizingCommand As New Vintasoft.Imaging.ImageProcessing.ParallelizingProcessingCommand(command)
        parallelizingCommand.MaxThreads = maxThreadsCount
        Return parallelizingCommand.Execute(image)
    End Function
                
    ' This code example produces the following output:  
        
       Multithread tests of Blur command:
       1 thread(s): 6262 ms
       2 thread(s): 3455 ms
       3 thread(s): 3169 ms
       4 thread(s): 3079 ms
    public static void Test()
    {
        // create image
        using (Vintasoft.Imaging.VintasoftImage image =
            new Vintasoft.Imaging.VintasoftImage(3000, 3000))
        {
            // add noise to an image
            Vintasoft.Imaging.ImageProcessing.Filters.AddNoiseCommand addNoize =
                new Vintasoft.Imaging.ImageProcessing.Filters.AddNoiseCommand();
            addNoize.ExecuteInPlace(image);
                
            // blur image - this call prevents the wrong results of next calls
            Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase command =
                new Vintasoft.Imaging.ImageProcessing.Filters.BlurCommand(11);
            using (Vintasoft.Imaging.VintasoftImage processedImage =
                command.Execute(image))
            {
            }
                
            System.Console.WriteLine("Multithread tests of {0} command:", command);
            for (int maxThreads = 1; maxThreads <= System.Environment.ProcessorCount; maxThreads++)
            {
                // blur image and output an execution time in milliseconds
                
                System.DateTime dt = System.DateTime.Now;
                using (Vintasoft.Imaging.VintasoftImage processedImage =
                    ExecuteProcessingCommand(command, maxThreads, image))
                {
                }
                int milliseconds = (int)(System.DateTime.Now - dt).TotalMilliseconds;
                System.Console.WriteLine("{0} thread(s): {1} ms", maxThreads, milliseconds);
            }
        }
    }
                
    /// <summary>
    /// Executes a processing command on specific number of threads.
    /// </summary>
    private static Vintasoft.Imaging.VintasoftImage ExecuteProcessingCommand(
        Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase command,
        int maxThreadsCount,
        Vintasoft.Imaging.VintasoftImage image)
    {
        if (maxThreadsCount == 1)
            return command.Execute(image);
                
        Vintasoft.Imaging.ImageProcessing.ParallelizingProcessingCommand parallelizingCommand =
            new Vintasoft.Imaging.ImageProcessing.ParallelizingProcessingCommand(command);
        parallelizingCommand.MaxThreads = maxThreadsCount;
        return parallelizingCommand.Execute(image);
    }
                
    /* This code example produces the following output:  
      
     Multithread tests of Blur command:
     1 thread(s): 6262 ms
     2 thread(s): 3455 ms
     3 thread(s): 3169 ms
     4 thread(s): 3079 ms
     
    */
    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.ImageProcessing.ProcessingCommandBase
          Vintasoft.Imaging.ImageProcessing.ProcessingCommandWithRegion
             Vintasoft.Imaging.ImageProcessing.ParallelizingProcessingCommand

    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also