SatDump 2.0.0-alpha-76a915210
Loading...
Searching...
No Matches
image_nodes.h
1#pragma once
2
3#include "flowgraph.h"
4#include "image/io.h"
5#include "image/meta.h"
7#include "projection/reprojector.h"
8#include "image/expression.h"
9#include "image/processing.h"
10
11namespace satdump
12{
13 class ImageSink_Node : public NodeInternal
14 {
15 private:
16 std::string path;
17
18 public:
19 ImageSink_Node()
20 : NodeInternal("Image Sink")
21 {
22 inputs.push_back({"Image"});
23 }
24
25 void process()
26 {
27 std::shared_ptr<image::Image> img = std::static_pointer_cast<image::Image>(inputs[0].ptr);
28
29 image::save_img(*img, path);
30
31 has_run = true;
32 }
33
34 void render()
35 {
36 ImGui::SetNextItemWidth(200 * ui_scale);
37 ImGui::InputText("Path", &path);
38 }
39
40 nlohmann::json to_json()
41 {
42 nlohmann::json j;
43 j["path"] = path;
44 return j;
45 }
46
47 void from_json(nlohmann::json j)
48 {
49 path = j["path"];
50 }
51 };
52
53 class ImageSource_Node : public NodeInternal
54 {
55 private:
56 std::string product_path;
57
58 public:
59 ImageSource_Node()
60 : NodeInternal("Image Source")
61 {
62 outputs.push_back({"Image"});
63 }
64
65 void process()
66 {
67 std::shared_ptr<image::Image> img_out = std::make_shared<image::Image>();
68 image::load_img(*img_out, product_path);
69 outputs[0].ptr = img_out;
70
71 has_run = true;
72 }
73
74 void render()
75 {
76 ImGui::SetNextItemWidth(200 * ui_scale);
77 ImGui::InputText("Path", &product_path);
78 }
79
80 nlohmann::json to_json()
81 {
82 nlohmann::json j;
83 j["path"] = product_path;
84 return j;
85 }
86
87 void from_json(nlohmann::json j)
88 {
89 product_path = j["path"];
90 }
91 };
92
93 class ImageGetProj_Node : public NodeInternal
94 {
95 private:
96 std::string path;
97
98 public:
99 ImageGetProj_Node()
100 : NodeInternal("Image Get Projection")
101 {
102 inputs.push_back({"Image"});
103 outputs.push_back({"Projection"});
104 }
105
106 void process()
107 {
108 std::shared_ptr<image::Image> img = std::static_pointer_cast<image::Image>(inputs[0].ptr);
109
110 std::shared_ptr<projection::Projection> ptr = std::make_shared<projection::Projection>(image::get_metadata_proj_cfg(*img));
111 ptr->height = img->height();
112 ptr->width = img->width();
113 outputs[0].ptr = ptr;
114
115 has_run = true;
116 }
117
118 void render() {}
119 nlohmann::json to_json() { return {}; }
120 void from_json(nlohmann::json j) {}
121 };
122
123 class ImageReproj_Node : public NodeInternal
124 {
125 private:
126 std::string path;
127 bool processing = false;
128 float progress = 0;
129
130 public:
131 ImageReproj_Node()
132 : NodeInternal("Reproj Image")
133 {
134 inputs.push_back({"Image"});
135 inputs.push_back({"Projection"});
136 outputs.push_back({"Image"});
137 }
138
139 void process()
140 {
141 processing = true;
142 std::shared_ptr<image::Image> img = std::static_pointer_cast<image::Image>(inputs[0].ptr);
143 std::shared_ptr<projection::Projection> proj = std::static_pointer_cast<projection::Projection>(inputs[1].ptr);
144
145 std::shared_ptr<image::Image> img_out = std::make_shared<image::Image>();
146
147 // TODOREWORK!!!!
149 op.img = img.get();
150 op.output_width = proj->width;
151 op.output_height = proj->height;
152 op.target_prj_info = *proj;
153 // op.target_prj_info["width"] = proj->width;
154 // op.target_prj_info["height"] = proj->height;
155 auto cfg = image::get_metadata_proj_cfg(*op.img);
156 cfg["width"] = img->width();
157 cfg["height"] = img->height();
158 image::set_metadata_proj_cfg(*op.img, cfg);
159 *img_out = projection::reproject(op, &progress);
160
161 outputs[0].ptr = img_out;
162
163 has_run = true;
164 processing = false;
165 }
166
167 void render()
168 {
169 if (processing)
170 ImGui::ProgressBar(progress, {200 * ui_scale, 0});
171 }
172 nlohmann::json to_json() { return {}; }
173 void from_json(nlohmann::json j) {}
174 };
175
176 class ImageExpression_Node : public NodeInternal
177 {
178 private:
179 struct ChConfig
180 {
181 std::string input_name;
182 std::string tokens;
183
184 NLOHMANN_DEFINE_TYPE_INTRUSIVE(ChConfig, input_name, tokens);
185 };
186
187 std::vector<ChConfig> channels;
188 std::string expression;
189
190 public:
191 ImageExpression_Node()
192 : NodeInternal("Image Expression")
193 {
194 outputs.push_back({"Image"});
195 }
196
197 void process()
198 {
199 std::vector<image::ExpressionChannel> ch;
200 for (int i = 0; i < channels.size(); i++)
201 {
202 std::shared_ptr<image::Image> img = std::static_pointer_cast<image::Image>(inputs[i].ptr);
203 ch.push_back({channels[i].tokens, img.get()});
204 logger->warn(channels[i].tokens);
205 }
206
207 std::shared_ptr<image::Image> img_out = std::make_shared<image::Image>();
208 *img_out = image::generate_image_expression(ch, expression);
209 outputs[0].ptr = img_out;
210
211 has_run = true;
212 }
213
214 void render()
215 {
216 ImGui::SetNextItemWidth(200 * ui_scale);
217 ImGui::InputTextMultiline("Expression", &expression);
218
219 for (auto &c : channels)
220 {
221 ImGui::Separator();
222 ImGui::Text("%s", c.input_name.c_str());
223 ImGui::SameLine();
224 ImGui::SetNextItemWidth(200 * ui_scale);
225 ImGui::InputText(std::string("##input" + c.input_name).c_str(), &c.tokens);
226 }
227 ImGui::Separator();
228
229 if (ImGui::Button("Add"))
230 {
231 std::string name = "Img" + std::to_string(channels.size() + 1);
232 addInputDynamic({name});
233 channels.push_back({name, "chimg" + std::to_string(channels.size() + 1)});
234 }
235 }
236
237 nlohmann::json to_json()
238 {
239 nlohmann::json j;
240 j["expression"] = expression;
241 j["channels"] = channels;
242 return j;
243 }
244
245 void from_json(nlohmann::json j)
246 {
247 expression = j["expression"];
248 channels = j["channels"];
249 inputs.clear();
250 for (auto &c : channels)
251 inputs.push_back({c.input_name});
252 }
253 };
254
255 class ImageEqualize_Node : public NodeInternal
256 {
257 private:
258 bool per_channel = false;
259
260 public:
261 ImageEqualize_Node()
262 : NodeInternal("Equalize Image")
263 {
264 inputs.push_back({"Image"});
265 outputs.push_back({"Image"});
266 }
267
268 void process()
269 {
270 std::shared_ptr<image::Image> img = std::static_pointer_cast<image::Image>(inputs[0].ptr);
271 image::equalize(*img, per_channel);
272 outputs[0].ptr = img;
273
274 has_run = true;
275 }
276
277 void render()
278 {
279 ImGui::Checkbox("Per Channel", &per_channel);
280 }
281
282 nlohmann::json to_json()
283 {
284 nlohmann::json j;
285 j["per_channel"] = per_channel;
286 return j;
287 }
288
289 void from_json(nlohmann::json j)
290 {
291 per_channel = j["per_channel"];
292 }
293 };
294}
int get(size_t p)
Standard int get. No bound check! Variants to pass a channel index and X / Y position are also availa...
Definition image.h:351
Image saving/loading.
Image Metadata manipulation.
Various processing functions (blur, equalize...)