Beatmup
metric.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2020, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include "abstract_bitmap.h"
21 #include "../parallelism.h"
22 #include <vector>
23 
24 namespace Beatmup {
25 
26  /**
27  Measures the difference between two bitmaps
28  */
29  class Metric : public AbstractTask, private BitmapContentLock {
30  public:
31  /**
32  Norm (distance) to measure between two images
33  */
34  enum class Norm {
35  L1,
36  L2
37  };
38 
39  private:
43  std::vector<double> results;
44  double result;
45 
46  inline ThreadIndex getMaxThreads() const { return MAX_THREAD_INDEX; }
47  void beforeProcessing(ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline* gpu);
48  void afterProcessing(ThreadIndex threadCount, GraphicPipeline* gpu, bool aborted);
49  bool process(TaskThread& thread);
50 
51  public:
52  Metric();
53 
54  /**
55  Sets input images
56  */
57  void setBitmaps(AbstractBitmap* bitmap1, AbstractBitmap* bitmap2);
58 
59  /**
60  Sets input images and rectangular regions delimiting the measurement areas
61  */
62  void setBitmaps(AbstractBitmap* bitmap1, const IntRectangle& roi1, AbstractBitmap* bitmap2, const IntRectangle& roi2);
63 
64  /**
65  Specifies the norm to use in the measurement
66  */
67  void setNorm(Norm norm) { this->norm = norm; }
68 
69  /**
70  \return the measurement result (after the task is executed)
71  */
72  double getResult() const { return result; }
73 
74  /**
75  \return peak signal-to-noise ratio in dB for two given images
76  */
77  static float psnr(AbstractBitmap& bitmap1, AbstractBitmap& bitmap2);
78  };
79 }
A very basic class for any image.
Task: an operation that can be executed by multiple threads in parallel.
Definition: parallelism.h:90
Makes sure the bitmap content is accessible within an image processing task.
Definition: content_lock.h:34
Internal low-level GPU control API.
Definition: pipeline.h:33
Measures the difference between two bitmaps.
Definition: metric.h:29
IntRectangle roi[2]
Definition: metric.h:41
static float psnr(AbstractBitmap &bitmap1, AbstractBitmap &bitmap2)
Definition: metric.cpp:139
ThreadIndex getMaxThreads() const
Gives the upper limint on the number of threads the task may be performed by.
Definition: metric.h:46
bool process(TaskThread &thread)
Executes the task on CPU within a given thread.
Definition: metric.cpp:120
void afterProcessing(ThreadIndex threadCount, GraphicPipeline *gpu, bool aborted)
Instruction called after the task is executed.
Definition: metric.cpp:101
void setNorm(Norm norm)
Specifies the norm to use in the measurement.
Definition: metric.h:67
void setBitmaps(AbstractBitmap *bitmap1, AbstractBitmap *bitmap2)
Sets input images.
Definition: metric.cpp:72
double result
Definition: metric.h:44
AbstractBitmap * bitmap[2]
Definition: metric.h:40
std::vector< double > results
Definition: metric.h:43
void beforeProcessing(ThreadIndex threadCount, ProcessingTarget target, GraphicPipeline *gpu)
Instruction called before the task is executed.
Definition: metric.cpp:90
Norm
Norm (distance) to measure between two images.
Definition: metric.h:34
double getResult() const
Definition: metric.h:72
Thread executing tasks.
Definition: parallelism.h:154
unsigned char ThreadIndex
number of threads / thread index
Definition: parallelism.h:68
static const ThreadIndex MAX_THREAD_INDEX
maximum possible thread index value
Definition: parallelism.h:71
ProcessingTarget
Definition: basic_types.h:55