Turi Create  4.0
Image.hpp
1 /* Copyright © 2020 Apple Inc. All rights reserved.
2  *
3  * Use of this source code is governed by a BSD-3-clause license that can
4  * be found in the LICENSE.txt file or at
5  * https://opensource.org/licenses/BSD-3-Clause
6  */
7 
8 #pragma once
9 
10 #include <memory>
11 #include <string>
12 
13 #include <core/util/Span.hpp>
14 
15 namespace turi {
16 namespace neural_net {
17 
18 /// Abstract interface for images that a training pipeline can consume.
19 class Image {
20  public:
21  static std::unique_ptr<Image> CreateFromPath(const std::string& path);
22 
23  virtual ~Image();
24 
25  /// The number of rows of pixels.
26  virtual size_t Height() const = 0;
27 
28  /// The number of columns of pixels.
29  virtual size_t Width() const = 0;
30 
31  /// The size (in elements) of a float buffer large enough to contain this
32  /// image. At present, all images are assumed RGB.
33  size_t Size() const { return 3 * Height() * Width(); }
34 
35  /// Writes the image in CHW order to the provided span or throws if the span does not have the
36  /// expected size.
37  virtual void WriteCHW(Span<float> buffer) const = 0;
38 
39  /// Writes the image in HWC order to the provided span or throws if the span does not have the
40  /// expected size.
41  virtual void WriteHWC(Span<float> buffer) const = 0;
42 };
43 
44 } // namespace neural_net
45 } // namespace turi
size_t Size() const
Definition: Image.hpp:33
virtual void WriteHWC(Span< float > buffer) const =0
virtual void WriteCHW(Span< float > buffer) const =0
Abstract interface for images that a training pipeline can consume.
Definition: Image.hpp:19
virtual size_t Width() const =0
The number of columns of pixels.
virtual size_t Height() const =0
The number of rows of pixels.