Compute Library
 21.02
neon_scale.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-2020 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
25 
26 #include "arm_compute/core/Types.h"
27 #include "utils/ImageLoader.h"
28 #include "utils/Utils.h"
29 
30 using namespace arm_compute;
31 using namespace utils;
32 
33 class NEONScaleExample : public Example
34 {
35 public:
36  bool do_setup(int argc, char **argv) override
37  {
38  PPMLoader ppm;
39 
40  if(argc < 2)
41  {
42  // Print help
43  std::cout << "Usage: ./build/neon_scale[input_image.ppm]\n\n";
44  std::cout << "No input_image provided, creating a dummy 640x480 image\n";
45  // Create an empty grayscale 640x480 image
46  src.allocator()->init(TensorInfo(640, 480, Format::U8));
47  }
48  else
49  {
50  ppm.open(argv[1]);
52  }
53 
54  constexpr int scale_factor = 2;
55 
56  TensorInfo dst_tensor_info(src.info()->dimension(0) / scale_factor, src.info()->dimension(1) / scale_factor,
57  Format::U8);
58 
59  // Configure the destination image
60  dst.allocator()->init(dst_tensor_info);
61 
62  // Configure Scale function object:
66  PixelValue(),
68  false
69  });
70 
71  // Allocate all the images
72  src.allocator()->allocate();
73  dst.allocator()->allocate();
74 
75  // Fill the input image with the content of the PPM image if a filename was provided:
76  if(ppm.is_open())
77  {
78  ppm.fill_image(src);
79  output_filename = std::string(argv[1]) + "_out.ppm";
80  }
81 
82  return true;
83  }
84  void do_run() override
85  {
86  // Run the scale operation:
87  scale.run();
88  }
89  void do_teardown() override
90  {
91  // Save the result to file:
92  if(!output_filename.empty())
93  {
94  save_to_ppm(dst, output_filename); // save_to_ppm maps and unmaps the image to store as PPM
95  }
96  }
97 
98 private:
99  Image src{}, dst{};
100  NEScale scale{};
101  std::string output_filename{};
102 };
103 
104 /** Main program for convolution test
105  *
106  * @param[in] argc Number of arguments
107  * @param[in] argv Arguments ( [optional] Path to PPM image to process )
108  */
109 int main(int argc, char **argv)
110 {
111  return utils::run_example<NEONScaleExample>(argc, argv);
112 }
void save_to_ppm(T &tensor, const std::string &ppm_filename)
Template helper function to save a tensor image to a PPM file.
Definition: Utils.h:547
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
void run() override final
Run the kernels contained in the function.
void open(const std::string &filename) override
Open an image file and reads its metadata (Width, height)
Definition: ImageLoader.h:381
1 channel, 1 U8 per channel
Output values are defined to match the source pixel whose center is nearest to the sample position...
Basic function to run NEScaleKernel.
Definition: NEScale.h:37
Includes all the Neon functions at once.
SimpleTensor< float > src
Definition: DFT.cpp:155
Copyright (c) 2017-2021 Arm Limited.
Samples are taken at pixel center.
bool is_open() override
Return true if the image file is currently open.
Definition: ImageLoader.h:377
Abstract Example class.
Definition: Utils.h:78
void configure(ITensor *input, ITensor *output, const ScaleKernelInfo &info)
Initialize the function&#39;s source, destination, interpolation type and border_mode.
Definition: NEScale.cpp:104
Structure to hold Image information.
Definition: helpers.h:659
int main(int argc, char **argv)
Main program for convolution test.
Definition: neon_scale.cpp:109
void fill_image(T &image)
Fill an image with the content of the currently open image file.
Definition: ImageLoader.h:177
Borders are left undefined.
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:45
void init_image(T &image, Format format)
Initialise an image&#39;s metadata with the dimensions of the image file currently open.
Definition: ImageLoader.h:161
PPM Image loader concrete implementation.
Definition: ImageLoader.h:367