Class: Naiso::RowAnalyzer

Inherits:
Object
  • Object
show all
Defined in:
lib/naiso/row_analyzer.rb

Overview

이미지 행 분석기

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image) ⇒ RowAnalyzer

Returns a new instance of RowAnalyzer.



11
12
13
14
15
16
17
18
# File 'lib/naiso/row_analyzer.rb', line 11

def initialize(image)
  @image = image
  @width = image.width
  @height = image.height
  @variance = nil
  @complexity = nil
  @img_array = nil
end

Instance Attribute Details

#heightObject (readonly)

Returns the value of attribute height.



9
10
11
# File 'lib/naiso/row_analyzer.rb', line 9

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



9
10
11
# File 'lib/naiso/row_analyzer.rb', line 9

def width
  @width
end

Instance Method Details

#complexityObject

각 행의 콘텐츠 복잡도 (지연 계산)



39
40
41
# File 'lib/naiso/row_analyzer.rb', line 39

def complexity
  @complexity ||= calculate_complexity
end

#img_arrayObject

이미지를 Numo::NArray로 변환 (지연 로딩)



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/naiso/row_analyzer.rb', line 21

def img_array
  @img_array ||= begin
    # Vips 이미지를 메모리 배열로 변환
    bands = @image.bands
    data = @image.write_to_memory

    # 바이트 배열을 NArray로 변환
    arr = Numo::UInt8.from_binary(data)
    arr.reshape(@height, @width, bands)
  end
end

#varianceObject

각 행의 색상 분산 (지연 계산)



34
35
36
# File 'lib/naiso/row_analyzer.rb', line 34

def variance
  @variance ||= calculate_variance
end