GdPicture.NET.14
GdPicture14 Namespace / GdPictureSegmenter Class / RunSegmentation Method / RunSegmentation(String) Method
A unique result identifier of the executed segmentation process, that is used to identify the segmentation result. You can define your preferable value. If you leave this parameter null or empty, a new identifier is automatically generated.
Example





In This Topic
RunSegmentation(String) Method
In This Topic
Runs the segmentation process on the image previously set by the SetImage method within the current GdPictureSegmenter object. You are allowed to set the custom result identifier you prefer using this method. The result of this process, identifiable by this custom ID, is internally attached to the current GdPictureSegmenter object as well.
Syntax
'Declaration
 
Public Overloads Function RunSegmentation( _
   ByVal SegmentationResuldID As String _
) As String
public string RunSegmentation( 
   string SegmentationResuldID
)
public function RunSegmentation( 
    SegmentationResuldID: String
): String; 
public function RunSegmentation( 
   SegmentationResuldID : String
) : String;
public: string* RunSegmentation( 
   string* SegmentationResuldID
) 
public:
String^ RunSegmentation( 
   String^ SegmentationResuldID
) 

Parameters

SegmentationResuldID
A unique result identifier of the executed segmentation process, that is used to identify the segmentation result. You can define your preferable value. If you leave this parameter null or empty, a new identifier is automatically generated.

Return Value

A unique result identifier of the executed segmentation process. If the method has been successfully followed, then the custom identifier passed as a parameter is returned, if it is properly defined.

The GetStat method can be subsequently used to determine if this method has been successful.

Remarks
It is recommend to use the GetStat method to identify the specific reason for the method's failure, if any.

Please ensure that you have set the required image before you start the new segmentation process. This method uses the image object previously set by SetImage method. Setting up an image is a mandatory step before running any segmentation process.

Also be aware, that you can only reuse the result ID if you first release it using the ReleaseSegmentationResult method before the next use. Releasing already used segmentation results can improve the memory management if you run more segmentation processes in a row.

Example
How to use the custom result identifier when running more segmentation processes.
Dim caption As String = "Example: RunSegmentation"
Using gdpictureSegmenter As GdPictureSegmenter = New GdPictureSegmenter()
    'Set up the image you want to process.
    Using gdpictureImaging As GdPictureImaging = New GdPictureImaging()
        'The standard open file dialog displays to allow you to select the file.
        Dim image As Integer = gdpictureImaging.CreateGdPictureImageFromFile("")
        If (gdpictureImaging.GetStat() = GdPictureStatus.OK) AndAlso
           (gdpictureSegmenter.SetImage(image) = GdPictureStatus.OK) Then
 
            'Set the segmentation mode.
            gdpictureSegmenter.SegmentationMode = SegmentationMode.ConnectedComponents4
            'Run the segmentation process.
            Dim resultIDComp4 As String = "ConnectedComponents4"
            gdpictureSegmenter.RunSegmentation(resultIDComp4)
            If gdpictureSegmenter.GetStat() = GdPictureStatus.OK Then
                'Check the results ...
                Dim blockCount As Integer = gdpictureSegmenter.GetBlockCount(resultIDComp4)
                'Continue ...
            Else
                MessageBox.Show("The segmentation process has failed with the status: " + gdpictureSegmenter.GetStat().ToString(), caption)
            End If
 
            'Set the segmentation mode.
            gdpictureSegmenter.SegmentationMode = SegmentationMode.ConnectedComponents8
            'Run the segmentation process.
            Dim resultIDComp8 As String = "ConnectedComponents8"
            gdpictureSegmenter.RunSegmentation(resultIDComp8)
            If gdpictureSegmenter.GetStat() = GdPictureStatus.OK Then
                'Check the results ...
                Dim blockCount As Integer = gdpictureSegmenter.GetBlockCount(resultIDComp8)
                'Continue ...
            Else
                MessageBox.Show("The segmentation process has failed with the status: " + gdpictureSegmenter.GetStat().ToString(), caption)
            End If
 
            'Release the used image.
            gdpictureImaging.ReleaseGdPictureImage(image)
 
            'Release resources.
            gdpictureSegmenter.ReleaseSegmentationResult(resultIDComp4)
            gdpictureSegmenter.ReleaseSegmentationResult(resultIDComp8)
        Else
            MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + " or " + gdpictureSegmenter.GetStat().ToString(), caption)
        End If
    End Using
End Using
string caption = "Example: RunSegmentation";
using (GdPictureSegmenter gdpictureSegmenter = new GdPictureSegmenter())
{
    //Set up the image you want to process.
    using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
    {
        //The standard open file dialog displays to allow you to select the file.
        int image = gdpictureImaging.CreateGdPictureImageFromFile("");
        if ((gdpictureImaging.GetStat() == GdPictureStatus.OK) &&
            (gdpictureSegmenter.SetImage(image) == GdPictureStatus.OK))
        {
            //Set the segmentation mode.
            gdpictureSegmenter.SegmentationMode = SegmentationMode.ConnectedComponents4;
 
            //Run the segmentation process.
            string resultIDComp4 = "ConnectedComponents4";
            gdpictureSegmenter.RunSegmentation(resultIDComp4);
            if (gdpictureSegmenter.GetStat() == GdPictureStatus.OK)
            {
                //Check the results ...
                int blockCount = gdpictureSegmenter.GetBlockCount(resultIDComp4);
                //Continue ...
            }
            else
            {
                MessageBox.Show("The segmentation process has failed with the status: " + gdpictureSegmenter.GetStat().ToString(), caption);
            }
 
            //Set the segmentation mode.
            gdpictureSegmenter.SegmentationMode = SegmentationMode.ConnectedComponents8;
 
            //Run the segmentation process.
            string resultIDComp8 = "ConnectedComponents8";
            gdpictureSegmenter.RunSegmentation(resultIDComp8);
            if (gdpictureSegmenter.GetStat() == GdPictureStatus.OK)
            {
                //Check the results ...
                int blockCount = gdpictureSegmenter.GetBlockCount(resultIDComp8);
                //Continue ...
            }
            else
            {
                MessageBox.Show("The segmentation process has failed with the status: " + gdpictureSegmenter.GetStat().ToString(), caption);
            }
 
            //Release the used image.
            gdpictureImaging.ReleaseGdPictureImage(image);
 
            //Release resources.
            gdpictureSegmenter.ReleaseSegmentationResult(resultIDComp4);
            gdpictureSegmenter.ReleaseSegmentationResult(resultIDComp8);
        }
        else
            MessageBox.Show("The error occurred when setting up the image: " + gdpictureImaging.GetStat().ToString() + " or " + gdpictureSegmenter.GetStat().ToString(), caption);
    }
}
See Also