numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
generate_sparse_sample_image.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <Eigen/Core>
23
26
28
37inline void add_constant_circle(Eigen::MatrixXd& image,
38 const Eigen::Vector2d& center, double radius, double value = 1.0) {
39 const num_collect::index_type rows = image.rows();
40 const num_collect::index_type cols = image.cols();
41 Eigen::Vector2d point;
42 for (num_collect::index_type j = 0; j < cols; ++j) {
43 const double x = static_cast<double>(j) / static_cast<double>(cols - 1);
44 point.x() = x;
45 for (num_collect::index_type i = 0; i < rows; ++i) {
46 const double y =
47 static_cast<double>(i) / static_cast<double>(rows - 1);
48 point.y() = y;
49 const double dist = (point - center).norm();
50 if (dist <= radius) {
51 image(i, j) = value;
52 }
53 }
54 }
55}
56
65inline void add_quadratic_circle(Eigen::MatrixXd& image,
66 const Eigen::Vector2d& center, double radius, double center_value = 1.0) {
67 const num_collect::index_type rows = image.rows();
68 const num_collect::index_type cols = image.cols();
69 Eigen::Vector2d point;
70 for (num_collect::index_type j = 0; j < cols; ++j) {
71 const double x = static_cast<double>(j) / static_cast<double>(cols - 1);
72 point.x() = x;
73 for (num_collect::index_type i = 0; i < rows; ++i) {
74 const double y =
75 static_cast<double>(i) / static_cast<double>(rows - 1);
76 point.y() = y;
77 const double dist = (point - center).norm();
78 const double dist_ratio = dist / radius;
79 image(i, j) = std::max(
80 image(i, j), center_value * (1.0 - dist_ratio * dist_ratio));
81 }
82 }
83}
84
96inline void add_smooth_circle(Eigen::MatrixXd& image,
97 const Eigen::Vector2d& center, double radius, double center_value = 1.0) {
98 const num_collect::index_type rows = image.rows();
99 const num_collect::index_type cols = image.cols();
100
102 const double scaling_factor = center_value / rbf(0.0);
103
104 Eigen::Vector2d point;
105 for (num_collect::index_type j = 0; j < cols; ++j) {
106 const double x = static_cast<double>(j) / static_cast<double>(cols - 1);
107 point.x() = x;
108 for (num_collect::index_type i = 0; i < rows; ++i) {
109 const double y =
110 static_cast<double>(i) / static_cast<double>(rows - 1);
111 point.y() = y;
112 const double dist = (point - center).norm();
113 const double dist_ratio = dist / radius;
114 image(i, j) =
115 std::max(image(i, j), scaling_factor * rbf(dist_ratio));
116 }
117 }
118}
119
128 Eigen::MatrixXd& image, num_collect::index_type rows,
130 const Eigen::Vector2d center = Eigen::Vector2d(0.7, 0.6);
131 constexpr double radius = 0.2;
132 image = Eigen::MatrixXd::Zero(rows, cols);
133 add_constant_circle(image, center, radius);
134}
135
144 Eigen::MatrixXd& image, num_collect::index_type rows,
146 const Eigen::Vector2d center1 = Eigen::Vector2d(0.3, 0.4);
147 constexpr double radius1 = 0.1;
148 constexpr double value1 = 0.5;
149
150 const Eigen::Vector2d center2 = Eigen::Vector2d(0.7, 0.6);
151 constexpr double radius2 = 0.2;
152 constexpr double value2 = 1.0;
153
154 image = Eigen::MatrixXd::Zero(rows, cols);
155 add_constant_circle(image, center1, radius1, value1);
156 add_constant_circle(image, center2, radius2, value2);
157}
158
167 Eigen::MatrixXd& image, num_collect::index_type rows,
169 const Eigen::Vector2d center = Eigen::Vector2d(0.7, 0.6);
170 constexpr double radius = 0.2;
171 constexpr double center_value = 1.0;
172
173 image = Eigen::MatrixXd::Zero(rows, cols);
174 add_quadratic_circle(image, center, radius, center_value);
175}
176
185 Eigen::MatrixXd& image, num_collect::index_type rows,
187 const Eigen::Vector2d center = Eigen::Vector2d(0.7, 0.6);
188 constexpr double radius = 0.3;
189 constexpr double center_value = 1.0;
190
191 image = Eigen::MatrixXd::Zero(rows, cols);
192 add_smooth_circle(image, center, radius, center_value);
193}
194
195} // namespace num_prob_collect::regularization
Class of Wendland's Compactly Supported RBF wendland1995.
Definition of index_type type.
std::ptrdiff_t index_type
Type of indices in this library.
Definition index_type.h:33
Namespace of regularization.
Definition namespaces.h:34
void add_constant_circle(Eigen::MatrixXd &image, const Eigen::Vector2d &center, double radius, double value=1.0)
Add a circle with constant value to an image.
void generate_sparse_sample_image_with_one_smooth_circle(Eigen::MatrixXd &image, num_collect::index_type rows, num_collect::index_type cols)
Generate a sparse sample image with one smooth circle.
void add_smooth_circle(Eigen::MatrixXd &image, const Eigen::Vector2d &center, double radius, double center_value=1.0)
Add a circle with values given by a smooth function to an image.
void generate_sparse_sample_image_with_one_quadratic_circle(Eigen::MatrixXd &image, num_collect::index_type rows, num_collect::index_type cols)
Generate a sparse sample image with one quadratic circle.
void generate_sparse_sample_image_with_two_constant_circles(Eigen::MatrixXd &image, num_collect::index_type rows, num_collect::index_type cols)
Generate a sparse sample image with two constant circles.
void generate_sparse_sample_image_with_one_constant_circle(Eigen::MatrixXd &image, num_collect::index_type rows, num_collect::index_type cols)
Generate a sparse sample image with one constant circle.
void add_quadratic_circle(Eigen::MatrixXd &image, const Eigen::Vector2d &center, double radius, double center_value=1.0)
Add a circle with values given by a quadratic function to an image.
Definition of wendland_csrbf class.