LEADTOOLSカラー変換

フレームを表示

.NETカラー変換は、直接のカラー変換をimageに提供します。汎用YUV変換では、ConversionYuvParametersクラスを使用して、任意のYUV形式からサポートされている任意のカラースペースへの変換を実行できます(ただし、この変換には下記の制限事項があります)。YUVフォーマットを定義した後に、変換他のもののように、通常変換を続行することができます。Convertメソッドを使用して変換を実施し、Stopメソッドを呼び出して、使用済みの変換リソースを解放します。現時点では、任意のカラースペースから汎用的なYUVへの変換は、サポートされません。

汎用的なYUV変換には、以下の規制が現時点ではあります:

  1. Yのサブサンプリングはサポートされていません。
  2. Y要素の数は、両方のUとVの倍数でなければなりません。
  3. 非平面形式で、Y、UとVの垂直方向のサブサンプリングは、サポートされません。
  4. 平面形式でサポートされる配置でない;線幅は、追加のバイトを格納してはいけません。
  5. UとVの水平サブサンプリングは一方を他方の倍数にする必要があります。UとVの垂直サブサンプリングも同様です。

1. 汎用的なYUV変換を用いてRGBにY41Pを変換すること:

[Visual Basic]
                    Imports Leadtools
                    Imports Leadtools.Codecs
                    Imports Leadtools.ColorConversion
                     
                    ' This example converts Y41P to RGB color space using Generic YUV Conversion.
                    Private Function TestConvertGenericY41PToRgb(ByVal yuvBuffer As Byte(), ByVal width As Integer, ByVal height As Integer) As Byte()
                      ' StartUp the ColorConversion.
                      RasterColorConverter.Startup()
               
                      ' Initialize the Lab buffer array
                      Dim rgbBuffer As Byte() = New Byte(yuvBuffer.Length - 1){}
               
                      ' Byte ordering of the format; for Y41P:
                      ' U0 Y0 V0 Y1 U4 Y2 V4 Y3 Y4 Y5 Y6 Y7
                      ' 0    1    2    3    4    5    6    7    8   9    10  11
                      ' Put the Y component order first, then the U and V last as follows:
                      ' Y positions: 1,3,5,7,8,9,10,11
                      ' U positions: 0,4
                      ' V positions: 2,6   
                      Dim offset As Integer() = { 1, 3, 5, 7, 8, 9, 10, 11, 0, 4, 2, 6 }
               
                      ' Initialize a new ConversionParameters class object.
                      Dim convParams As ConversionParameters = New ConversionParameters()
               
                      ' Initialize the YuvParameters class property.
                      Dim yuvParameters As ConversionYuvParameters = ConversionYuvParameters.Empty
               
                      ' Determine the horizontal sub-sampling of U
                      yuvParameters.UH = 4
               
                      ' Determine the vertical sub-sampling of U
                      yuvParameters.UV = 1
               
                      ' Determine the horizontal sub-sampling of V
                      yuvParameters.VH = 4
               
                      ' Determine the vertical sub-sampling of V
                      yuvParameters.VV = 1
               
                      ' Set the byte ordering
                      yuvParameters.Offsets = offset
               
                      ' The YUV values range
                      yuvParameters.Range = ConversionYuvRange.UseFull
               
                      ' This represents the macro pixels(smallest group of pixels allowed), 
                      ' which indicates how many actual pixels are in the macro pixel. 
                      ' This value is important only in non - planar format
                      yuvParameters.MacroPixel = 8
               
                      ' This is a Boolean value that represents the type of the YUV format (Planar = true, or non - Planar = false.)
                      yuvParameters.Planar = False
               
                      convParams.YuvParameters = yuvParameters
               
                      ' Determine the type of conversion to be used in the conversion, for YUVGeneric, only use UseBuiltIn
                      convParams.Method = ConversionMethodFlags.UseBuiltIn
               
                      ' Determine the type of conversion to be activated. For YUVGeneric, only UseBuiltIn
                      convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn
               
                      ' Initialize a new Converter object
                      Dim converter As RasterColorConverter = New RasterColorConverter()
               
                      Try
                        'Initialize the conversion
                        converter.Start(ConversionColorFormat.Yuv, ConversionColorFormat.Rgb, convParams)
               
                        ' Convert the Buffer from Yuv to Rgb
                        converter.Convert(yuvBuffer, 0, rgbBuffer, 0, width, height, 0, 0)
               
                        ' Stop the conversion
                        converter.Stop()
                      Catch ex As Exception
                        MessageBox.Show(ex.Message)
                        Return Nothing
                      End Try
               
                      ' Shutdown the ColorConversion.
                      RasterColorConverter.Shutdown()
               
                      ' return the converted buffer.
                      Return rgbBuffer
                    End Function
             
[C#]
                  using Leadtools;
                  using Leadtools.Codecs;
                  using Leadtools.ColorConversion;
                  
                  // This example converts Y41P to RGB color space using Generic YUV Conversion.
                  private byte[] TestConvertGenericY41PToRgb(byte[] yuvBuffer, int width, int height)
                  {
                     // StartUp the ColorConversion.
                     RasterColorConverter.Startup();
            
                     // Initialize the Lab buffer array
                     byte[] rgbBuffer = new byte[yuvBuffer.Length];
            
                     // Byte ordering of the format; for Y41P:
                     // U0 Y0 V0 Y1 U4 Y2 V4 Y3 Y4 Y5 Y6 Y7
                     // 0    1    2    3    4    5    6    7    8   9    10  11
                     // Put the Y component order first, then the U and V last as follows:
                     // Y positions: 1,3,5,7,8,9,10,11
                     // U positions: 0,4
                     // V positions: 2,6   
                     int[] offset = { 1, 3, 5, 7, 8, 9, 10, 11, 0, 4, 2, 6 };
            
                     // Initialize a new ConversionParameters class object.
                     ConversionParameters convParams = new ConversionParameters();
            
                     // Initialize the YuvParameters class property.
                     ConversionYuvParameters yuvParameters = ConversionYuvParameters.Empty;
            
                     // Determine the horizontal sub-sampling of U
                     yuvParameters.UH = 4;
            
                     // Determine the vertical sub-sampling of U
                     yuvParameters.UV = 1;
            
                     // Determine the horizontal sub-sampling of V
                     yuvParameters.VH = 4;
            
                     // Determine the vertical sub-sampling of V
                     yuvParameters.VV = 1;
            
                     // Set the byte ordering
                     yuvParameters.Offsets = offset;
            
                     // The YUV values range
                     yuvParameters.Range = ConversionYuvRange.UseFull;
            
                     // This represents the macro pixels(smallest group of pixels allowed), 
                     // which indicates how many actual pixels are in the macro pixel. 
                     // This value is important only in non - planar format
                     yuvParameters.MacroPixel = 8;
            
                     // This is a Boolean value that represents the type of the YUV format (Planar = true, or non - Planar = false.)
                     yuvParameters.Planar = false;
            
                     convParams.YuvParameters = yuvParameters;
            
                     // Determine the type of conversion to be used in the conversion, for YUVGeneric, only use UseBuiltIn
                     convParams.Method = ConversionMethodFlags.UseBuiltIn;
            
                     // Determine the type of conversion to be activated. For YUVGeneric, only UseBuiltIn
                     convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn;
            
                     // Initialize a new Converter object
                     RasterColorConverter converter = new RasterColorConverter();
            
                     try
                     {
                        //Initialize the conversion
                        converter.Start(ConversionColorFormat.Yuv, ConversionColorFormat.Rgb, convParams);
            
                        // Convert the Buffer from Yuv to Rgb
                        converter.Convert(yuvBuffer, 0, rgbBuffer, 0, width, height, 0, 0);
            
                        // Stop the conversion
                        converter.Stop();
                     }
                     catch (Exception ex)
                     {
                        MessageBox.Show(ex.Message);
                        return null;
                     }
            
                     // Shutdown the ColorConversion.
                     RasterColorConverter.Shutdown();
            
                     // return the converted buffer.
                     return rgbBuffer;
                  }
                  

2. 汎用的なYUV変換を用いてRGBにYVU9(プレーナ)を変換すること:

[Visual Basic]

                  Imports Leadtools
                  Imports Leadtools.Codecs
                  Imports Leadtools.ColorConversion
             
                  ' This example converts YVU9 (Planar) to RGB color space using Generic YUV Conversion.
                  Private Function TestConvertGenericYVU9ToRGB(ByVal yuvBuffer As Byte(), ByVal width As Integer, ByVal height As Integer) As Byte()
                     ' StartUp the ColorConversion.
                     RasterColorConverter.Startup()
             
                     ' Initialize the Lab buffer array
                     Dim rgbBuffer As Byte() = New Byte(yuvBuffer.Length - 1){}
             
                     ' This array of integers specifies the byte order of the yuv format. For planar formats it takes only a single value that represents the plane sequence in the buffer: 
                     '            YUV, YVU, UYV, UVY, VYU, or VUY.
                     Dim offset As Integer() = { ConversionYuvParameters.PlanarYvu }
             
                     'PlanarYuv means the Y plane comes first in the buffer, then the V plane, and the U plane is last.
                     ' Initialize a new Converter object
                     Dim converter As RasterColorConverter = New RasterColorConverter()
             
                     ' Initialize a new ConversionParameters class object.
                     Dim convParams As ConversionParameters = New ConversionParameters()
             
                     ' Initialize the YuvParameters property class.
                     Dim yuvParameters As ConversionYuvParameters = ConversionYuvParameters.Empty
             
                     ' Set the horizontal sub-sampling of U.
                     yuvParameters.UH = 4
             
                     ' Set the vertical sub-sampling of U.
                     yuvParameters.UV = 4
             
                     ' Set the horizontal sub-sampling of V.
                     yuvParameters.VH = 4
             
                     ' Set the vertical sub-sampling of V.
                     yuvParameters.VV = 4
             
                     ' Pass the byte order array.
                     yuvParameters.Offsets = offset
             
                     ' The range value determines the YUV range values.
                     yuvParameters.Range = ConversionYuvRange.UseFull
             
                     ' This represents the macro pixels(smallest group of pixels allowed), 
                     ' which indicates how many actual pixels are in the macro pixel. 
                     ' This value is important only in non - planar format   
                     yuvParameters.MacroPixel = 16
             
                     ' This is a Boolean value that represents the type of the YUV format (Planar, or non - Planar).
                     yuvParameters.Planar = True
                     convParams.YuvParameters = yuvParameters
             
                     ' Set the type of conversion to be used. For YUVGeneric, use only UseBuiltIn.
                     convParams.Method = ConversionMethodFlags.UseBuiltIn
             
                     ' Set the type of conversion to be activated. For YUVGeneric, use only UseBuiltIn.
                     convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn
                     Try
                        ' Initialize the conversion.
                        converter.Start(ConversionColorFormat.Yuv, ConversionColorFormat.Rgb, convParams)
                        ' Convert the buffer.
                        converter.Convert(yuvBuffer, 0, rgbBuffer, 0, width, height, 0, 0)
                        ' Stop the conversion.
                        converter.Stop()
                     Catch ex As Exception
                        MessageBox.Show(ex.Message)
                        Return Nothing
                     End Try
                     ' Shutdown the ColorConversion.
                     RasterColorConverter.Shutdown()
                     ' return the converted buffer.
                     Return rgbBuffer
                  End Function
             
[C#]
                   using Leadtools;
                   using Leadtools.Codecs;
                   using Leadtools.ColorConversion;
                   
                   // This example converts YVU9 (Planar) to RGB color space using Generic YUV Conversion.
                   private byte[] TestConvertGenericYVU9ToRGB(byte[] yuvBuffer, int width, int height)
                   {
                      // StartUp the ColorConversion.
                      RasterColorConverter.Startup();
             
                      // Initialize the Lab buffer array
                      byte[] rgbBuffer = new byte[yuvBuffer.Length];
             
                      // This array of integers specifies the byte order of the yuv format. For planar formats it takes only a single value that represents the plane sequence in the buffer: 
                      //            YUV, YVU, UYV, UVY, VYU, or VUY.
                      int[] offset = { ConversionYuvParameters.PlanarYvu };
                      //PlanarYuv means the Y plane comes first in the buffer, then the V plane, and the U plane is last.
             
                      // Initialize a new Converter object
                      RasterColorConverter converter = new RasterColorConverter();
             
                      // Initialize a new ConversionParameters class object.
                      ConversionParameters convParams = new ConversionParameters();
             
                      // Initialize the YuvParameters property class.
                      ConversionYuvParameters yuvParameters = ConversionYuvParameters.Empty;
             
                      // Set the horizontal sub-sampling of U.
                      yuvParameters.UH = 4;
             
                      // Set the vertical sub-sampling of U.
                      yuvParameters.UV = 4;
             
                      // Set the horizontal sub-sampling of V.
                      yuvParameters.VH = 4;
             
                      // Set the vertical sub-sampling of V.
                      yuvParameters.VV = 4;
             
                      // Pass the byte order array.
                      yuvParameters.Offsets = offset;
             
                      // The range value determines the YUV range values.
                      yuvParameters.Range = ConversionYuvRange.UseFull;
             
                      // This represents the macro pixels(smallest group of pixels allowed), 
                      // which indicates how many actual pixels are in the macro pixel. 
                      // This value is important only in non - planar format   
             
                      yuvParameters.MacroPixel = 16;
             
                      // This is a Boolean value that represents the type of the YUV format (Planar, or non - Planar).
                      yuvParameters.Planar = true;
             
                      convParams.YuvParameters = yuvParameters;
             
                      // Set the type of conversion to be used. For YUVGeneric, use only UseBuiltIn.
                      convParams.Method = ConversionMethodFlags.UseBuiltIn;
             
                      // Set the type of conversion to be activated. For YUVGeneric, use only UseBuiltIn.
                      convParams.ActiveMethod = ConversionMethodFlags.UseBuiltIn;
             
                      try
                      {
                         // Initialize the conversion.
                         converter.Start(ConversionColorFormat.Yuv, ConversionColorFormat.Rgb, convParams);
             
                         // Convert the buffer.
                         converter.Convert(yuvBuffer, 0, rgbBuffer, 0, width, height, 0, 0);
             
                         // Stop the conversion.
                         converter.Stop();
                      }
                      catch (Exception ex)
                      {
                         MessageBox.Show(ex.Message);
                         return null;
                      }
             
                      // Shutdown the ColorConversion.
                      RasterColorConverter.Shutdown();
             
                      // return the converted buffer.
                      return rgbBuffer;
                   }
             
© 1991-2016のLEAD Technologies, Inc. All Rights Reserved.