Class: Gsplat::Training::Scene

Inherits:
Object
  • Object
show all
Defined in:
lib/gsplat/training/scene.rb

Overview

In-memory multi-view training scene.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(viewmats:, intrinsics:, images:, points:, colors:, names: nil, scene_scale: nil) ⇒ Scene

rubocop:disable Metrics/ParameterLists



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gsplat/training/scene.rb', line 12

def initialize(viewmats:, intrinsics:, images:, points:, colors:, names: nil, scene_scale: nil)
  # rubocop:enable Metrics/ParameterLists
  @viewmats = viewmats
  @intrinsics = intrinsics
  @images = images
  @points = points
  @colors = colors
  @names = names || Array.new(images.shape[0]) { |index| format("camera_%03d", index) }
  @height = images.shape[1]
  @width = images.shape[2]
  validate!
  @scene_scale = scene_scale || infer_scene_scale
end

Instance Attribute Details

#colorsObject (readonly)

Returns the value of attribute colors.



8
9
10
# File 'lib/gsplat/training/scene.rb', line 8

def colors
  @colors
end

#heightObject (readonly)

Returns the value of attribute height.



8
9
10
# File 'lib/gsplat/training/scene.rb', line 8

def height
  @height
end

#imagesObject (readonly)

Returns the value of attribute images.



8
9
10
# File 'lib/gsplat/training/scene.rb', line 8

def images
  @images
end

#intrinsicsObject (readonly)

Returns the value of attribute intrinsics.



8
9
10
# File 'lib/gsplat/training/scene.rb', line 8

def intrinsics
  @intrinsics
end

#namesObject (readonly)

Returns the value of attribute names.



8
9
10
# File 'lib/gsplat/training/scene.rb', line 8

def names
  @names
end

#pointsObject (readonly)

Returns the value of attribute points.



8
9
10
# File 'lib/gsplat/training/scene.rb', line 8

def points
  @points
end

#scene_scaleObject (readonly)

Returns the value of attribute scene_scale.



8
9
10
# File 'lib/gsplat/training/scene.rb', line 8

def scene_scale
  @scene_scale
end

#viewmatsObject (readonly)

Returns the value of attribute viewmats.



8
9
10
# File 'lib/gsplat/training/scene.rb', line 8

def viewmats
  @viewmats
end

#widthObject (readonly)

Returns the value of attribute width.



8
9
10
# File 'lib/gsplat/training/scene.rb', line 8

def width
  @width
end

Class Method Details

.from_colmap(path, data_factor: 1) ⇒ Scene

Loads a COLMAP sparse model and its corresponding RGB images.

rubocop:disable Metrics/AbcSize

Parameters:

  • path (String)

    dataset root containing sparse and images

  • data_factor (Numeric) (defaults to: 1)

    image/intrinsics downsampling factor

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/gsplat/training/scene.rb', line 32

def self.from_colmap(path, data_factor: 1)
  dataset = IO::Colmap.read(path, data_factor: data_factor)
  records = dataset.images.values.sort_by(&:name)
  views = Numo::SFloat.cast(stack(records.map(&:world_to_camera)))
  intrinsics = Numo::SFloat.cast(
    stack(records.map { |record| dataset.cameras.fetch(record.camera_id).intrinsics })
  )
  image_directory = resolve_image_directory(path, data_factor)
  images = Numo::SFloat.cast(
    stack(records.map { |record| IO::Image.read(File.join(image_directory, record.name)) })
  )
  points = dataset.points3d.values.sort_by(&:id)
  new(
    viewmats: views,
    intrinsics: intrinsics,
    images: images,
    points: Numo::SFloat.cast(stack_rows(points.map(&:xyz))),
    colors: Numo::SFloat.cast(stack_rows(points.map { |point| Numo::DFloat.cast(point.rgb) / 255.0 })),
    names: records.map(&:name)
  )
end

Instance Method Details

#camera_countInteger

Number of registered training views.

Returns:

  • (Integer)


58
59
60
# File 'lib/gsplat/training/scene.rb', line 58

def camera_count
  images.shape[0]
end