module Labcom3

Authors

IMAZU, Setsuo

Version

25.2.0

Date

2024-11-18

Constants

VERSION

Public Instance Methods

is_module_init( ) click to toggle source
引 数

なし

返 値

true: 初期化済, false:未初期化

説 明

モジュール初期化処理がされたかどうか

# File lib/labcom3/Labcom_m.rb, line 27
def is_module_init( )
  return @@mInitialized
end
new_shape( na_type , shape) click to toggle source
引 数
na_type (CONST)

Numo::NArrayクラスが扱うデータタイプ(Numo::Int8,…)

shape (integer[])

配列の次元(C-order)

返 値

Numo::NArray

説 明

Numo::NArrayクラスが扱う空配列を作成する。

# File lib/labcom3/Labcom_m.rb, line 147
def new_shape( na_type , shape)
    return Numo::Int8.new( shape ) if na_type == Numo::Int8 
    return Numo::Int16.new( shape ) if na_type == Numo::Int16
    return Numo::Int32.new( shape ) if na_type == Numo::Int32
    return Numo::Int64.new( shape ) if na_type == Numo::Int64
    return Numo::SFloat.new( shape ) if na_type == Numo::SFloat
    return Numo::DFloat.new( shape ) if na_type == Numo::DFloat
    return Numo::UInt16.new( shape ) if na_type == Numo::UInt16
    return Numo::UInt8.new( shape ) if na_type == Numo::UInt8
    return Numo::UInt32.new( shape ) if na_type == Numo::UInt32
    return Numo::UInt64.new( shape ) if na_type == Numo::UInt64
  return nil
end
set_module_init( ) click to toggle source
引 数

なし

返 値

なし

説 明

モジュール初期化処理

# File lib/labcom3/Labcom_m.rb, line 40
def set_module_init( )
  if not @@mInitialized then
    Labcom.set_retrieve_dir()
    @@mInitialized=true
  end
end
to_bytes_per_sample( image_type ) click to toggle source
引 数
image_type (string)

LABCOMデータ処理が扱うイメージタイプ

返 値

バイト長

例 外

TypeError

説 明

イメージタイプから、その1サンプルのバイト長を算出する。

# File lib/labcom3/Labcom_m.rb, line 173
def to_bytes_per_sample( image_type )
        
  return 2 if image_type == 'YUY2'

  pos = image_type.index('INT')
  pos = image_type.index('FLT') if nil == pos
  
  if nil != pos then
    val = image_type[3..-1].to_i
  else
    pos = image_type.index('GRAY')
    pos = image_type.index('GREY') if nil == pos
  
    if nil != pos then
      val = image_type[4..-1].to_i
    else
      if nil != image_type.index('YUV') then
        val = 16
      end
    end
  end
  if nil == val then
    rgb_r = image_type.index('R')
    rgb_g = image_type.index('G')
    rgb_b = image_type.index('B')
    if nil != rgb_r and nil != rgb_g and nil != rgb_b then
      val = 32
    end
  end
  if nil != val  then
    return 1 if 9 > val 
    return 2 if 17 > val 
    return 4 if 33 > val 
    return 8 if 65 > val 
  end

  raise TypeError, 'Image type( ' + image_type + ' ) is unknown.'
end
to_narray( bin_str, na_type , shape=nil) click to toggle source
引 数
bin_str (binary string)

格納するデータ バイナリ文字列

na_type (CONST)

Numo::NArrayクラスが扱うデータタイプ(Numo::Int8,…)

shape (integer[])

配列の次元(C-order)

返 値

Numo::NArray

説 明

バイナリ文字列をNumo::NArrayクラスが扱う配列に変換する。

# File lib/labcom3/Labcom_m.rb, line 109
def to_narray( bin_str, na_type , shape=nil)
  if nil == shape  then
    return Numo::Int8.from_binary( bin_str ) if na_type == Numo::Int8 
    return Numo::Int16.from_binary( bin_str ) if na_type == Numo::Int16
    return Numo::Int32.from_binary( bin_str ) if na_type == Numo::Int32
    return Numo::Int64.from_binary( bin_str ) if na_type == Numo::Int64
    return Numo::SFloat.from_binary( bin_str ) if na_type == Numo::SFloat
    return Numo::DFloat.from_binary( bin_str ) if na_type == Numo::DFloat
    return Numo::UInt16.from_binary( bin_str ) if na_type == Numo::UInt16
    return Numo::UInt8.from_binary( bin_str ) if na_type == Numo::UInt8
    return Numo::UInt32.from_binary( bin_str ) if na_type == Numo::UInt32
    return Numo::UInt64.from_binary( bin_str ) if na_type == Numo::UInt64
  else
    return Numo::Int16.from_binary( bin_str, shape) if na_type == Numo::Int16
    return Numo::Int32.from_binary( bin_str, shape ) if na_type == Numo::Int32
    return Numo::Int64.from_binary( bin_str, shape ) if na_type == Numo::Int64
    return Numo::SFloat.from_binary( bin_str, shape ) if na_type == Numo::SFloat
    return Numo::DFloat.from_binary( bin_str, shape ) if na_type == Numo::DFloat
    return Numo::UInt16.from_binary( bin_str, shape ) if na_type == Numo::UInt16
    return Numo::UInt8.from_binary( bin_str, shape ) if na_type == Numo::UInt8
    return Numo::UInt32.from_binary( bin_str, shape ) if na_type == Numo::UInt32
    return Numo::UInt64.from_binary( bin_str, shape ) if na_type == Numo::UInt64
  end
  return nil
end
to_narray_type( image_type ) click to toggle source
引 数
image_type (string)

LABCOMデータ処理が扱うイメージタイプ

返 値

Numo::NArrayクラスが扱うデータタイプ

例 外

TypeError

説 明

イメージタイプをNumo::NArrayクラスが扱うデータタイプに変換する。

# File lib/labcom3/Labcom_m.rb, line 59
def to_narray_type( image_type )
  return Numo::Int8 if image_type == 'INT8'
  return Numo::Int16 if image_type == 'INT16'
  return Numo::Int32 if image_type == 'INT32'
  return Numo::Int64 if image_type == 'INT64'
  return Numo::SFloat if image_type == 'FLT32'
  return Numo::DFloat if image_type == 'FLT64'
  return Numo::UInt16 if image_type == 'YUY2'
        
  pos = image_type.index('GRAY')
  pos = image_type.index('GREY') if nil == pos

  if nil != pos then
    val = image_type[4..-1].to_i
  else
    if nil != image_type.index('YUV') then
      val = 16
    end
  end
  if nil == val then
    rgb_r = image_type.index('R')
    rgb_g = image_type.index('G')
    rgb_b = image_type.index('B')
    if nil != rgb_r and nil != rgb_g and nil != rgb_b then
      val = 32
    end
  end
  if nil != val  then
    return Numo::UInt8 if 9 > val 
    return Numo::UInt16 if 17 > val 
    return Numo::UInt32 if 33 > val 
    return Numo::UInt64 if 65 > val 
  end

  raise TypeError, 'Image type( ' + image_type + ' ) is unknown.'
end