Fawkes API  Fawkes Development Version
color_train_widget.cpp
1 
2 /***************************************************************************
3  * color_train_widget.cpp - Color training widget
4  *
5  * Created: Thu Mar 20 22:19:36 2008
6  * Copyright 2008 Daniel Beck
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL file in the doc directory.
21  */
22 
23 #include "color_train_widget.h"
24 
25 #include "colormap_viewer_widget.h"
26 
27 #include <core/exceptions/software.h>
28 #include <fvutils/color/color_object_map.h>
29 #include <fvutils/color/colorspaces.h>
30 #include <fvutils/color/conversions.h>
31 #include <fvutils/color/yuv.h>
32 #include <fvutils/color/zauberstab.h>
33 #include <fvutils/colormap/bayes/bayes_generator.h>
34 #include <fvutils/colormap/cmfile.h>
35 #include <fvutils/colormap/yuvcm.h>
36 #include <fvutils/draw/drawer.h>
37 #include <fvutils/scalers/lossy.h>
38 #include <fvutils/writers/jpeg.h>
39 
40 using namespace firevision;
41 
42 /** @class ColorTrainWidget "color_train_widget.h"
43  * This widget implements the complete color training process.
44  *
45  * @author Daniel Beck
46  */
47 
48 /** Constructor.
49  * @param parent the parent window
50  */
52 {
53  m_generator = 0;
54  m_zauberstab.reset(new Zauberstab());
55  m_cvw.reset(new ColormapViewerWidget());
56 
57  m_src_buffer = 0;
58  m_draw_buffer = 0;
59 
60  m_wnd_parent = parent;
61  m_btn_reset_selection = 0;
62  m_btn_add_to_colormap = 0;
63  m_btn_reset_colormap = 0;
64  m_btn_load_histos = 0;
65  m_btn_save_histos = 0;
66  m_btn_load_colormap = 0;
67  m_btn_save_colormap = 0;
68  m_spbtn_cm_depth = 0;
69  m_spbtn_cm_width = 0;
70  m_spbtn_cm_height = 0;
71  m_img_segmentation = 0;
72  m_scl_threshold = 0;
73  m_scl_min_prob = 0;
74  m_fcd_filechooser = 0;
75 }
76 
77 /** Destructor. */
79 {
80  delete m_generator;
81 }
82 
83 /** Set the current foreground object.
84  * @param fg_object the foreground object
85  */
86 void
88 {
89  m_fg_object = fg_object;
90 }
91 
92 /** Set the buffer containing the image data.
93  * @param yuv422_buffer the YUV422_PLANAR buffer holding the image data
94  * @param img_width the width of the image
95  * @param img_height the height of the image
96  */
97 void
98 ColorTrainWidget::set_src_buffer(unsigned char *yuv422_buffer,
99  unsigned int img_width,
100  unsigned int img_height)
101 {
102  m_img_width = img_width;
103  m_img_height = img_height;
104  m_src_buffer = yuv422_buffer;
105  m_img_cs = YUV422_PLANAR;
106  m_img_size = colorspace_buffer_size(m_img_cs, m_img_width, m_img_height);
107 
108  if (yuv422_buffer) {
109  m_zauberstab->deleteRegion();
110  m_zauberstab->setBuffer(m_src_buffer, m_img_width, m_img_height);
111  m_zauberstab->setThreshold(10);
112  } else {
113  m_img_segmentation->clear();
114  m_img_segmentation->set("gtk-missing-image");
115  }
116 }
117 
118 /** Set the buffer to draw the selection into.
119  * It is assumed that this buffer has the same dimensions as the buffer holding
120  * the soruce image.
121  * @param buffer the draw buffer
122  */
123 void
124 ColorTrainWidget::set_draw_buffer(unsigned char *buffer)
125 {
126  m_draw_buffer = buffer;
127 }
128 
129 /** The user clicked into the image.
130  * @param x the x-coordinate
131  * @param y the y-coordinate
132  * @param button 1 for left click, 3 for right click @see GdkEventButton
133  */
134 void
135 ColorTrainWidget::click(unsigned int x, unsigned int y, unsigned int button)
136 {
137  if (m_src_buffer == 0 || m_draw_buffer == 0) {
138  return;
139  }
140 
141  if (m_zauberstab->isEmptyRegion()) {
142  if (button == MOUSE_BUTTON_LEFT) //left click
143  {
144  m_zauberstab->findRegion(x, y);
145  }
146  } else {
147  if (button == MOUSE_BUTTON_LEFT) //left click
148  {
149  m_zauberstab->addRegion(x, y);
150  }
151 
152  if (button == MOUSE_BUTTON_RIGHT) //right click
153  {
154  m_zauberstab->deleteRegion(x, y);
155  }
156  }
157 
158  memcpy(m_draw_buffer, m_src_buffer, m_img_size);
159 
160  ZRegion *region = m_zauberstab->getRegion();
161  Drawer * d = new Drawer();
162  d->set_buffer(m_draw_buffer, m_img_width, m_img_height);
163 
164  for (unsigned int s = 0; s < region->slices->size(); s++) {
165  d->draw_rectangle_inverted(region->slices->at(s)->leftX,
166  region->slices->at(s)->y,
167  region->slices->at(s)->rightX - region->slices->at(s)->leftX,
168  1);
169  }
170 
171  delete d;
172 
173  m_signal_update_image();
174 }
175 
176 /** Reset the selection. */
177 void
179 {
180  if (m_zauberstab) {
181  m_zauberstab->deleteRegion();
182  }
183 
184  if (m_src_buffer && m_draw_buffer) {
185  memcpy(m_draw_buffer, m_src_buffer, m_img_size);
186  }
187 
188  m_signal_update_image();
189 }
190 
191 /** Set the button to reset the selection.
192  * @param btn the reset selection button
193  */
194 void
196 {
197  m_btn_reset_selection = btn;
198  m_btn_reset_selection->signal_clicked().connect(
199  sigc::mem_fun(*this, &ColorTrainWidget::reset_selection));
200 }
201 
202 /** Set the button to trigger the generation of the colormap.
203  * @param btn a Button
204  */
205 void
207 {
208  m_btn_add_to_colormap = btn;
209  m_btn_add_to_colormap->signal_clicked().connect(
210  sigc::mem_fun(*this, &ColorTrainWidget::add_to_colormap));
211 }
212 
213 /** Set the button to reset the colormap.
214  * @param btn a Button
215  */
216 void
218 {
219  m_btn_reset_colormap = btn;
220  m_btn_reset_colormap->signal_clicked().connect(
221  sigc::mem_fun(*this, &ColorTrainWidget::reset_colormap));
222 }
223 
224 /** Set the buffon to open a dialog to load histograms.
225  * @param btn a Button
226  */
227 void
229 {
230  m_btn_load_histos = btn;
231  m_btn_load_histos->signal_clicked().connect(
232  sigc::mem_fun(*this, &ColorTrainWidget::load_histograms));
233 }
234 
235 /** Set the buffon to open a dialog to save histograms.
236  * @param btn a Button
237  */
238 void
240 {
241  m_btn_save_histos = btn;
242  m_btn_save_histos->signal_clicked().connect(
243  sigc::mem_fun(*this, &ColorTrainWidget::save_histograms));
244 }
245 
246 /** Set the buffon to open a dialog to load a colormap.
247  * @param btn a Button
248  */
249 void
251 {
252  m_btn_load_colormap = btn;
253  m_btn_load_colormap->signal_clicked().connect(
254  sigc::mem_fun(*this, &ColorTrainWidget::load_colormap));
255 }
256 
257 /** Set the buffon to open a dialog to save a colormap.
258  * @param btn a Button
259  */
260 void
262 {
263  m_btn_save_colormap = btn;
264  m_btn_save_colormap->signal_clicked().connect(
265  sigc::mem_fun(*this, &ColorTrainWidget::save_colormap));
266 }
267 
268 /** Set the image to render the colormap into.
269  * @param img an Image
270  */
271 void
273 {
274  m_cvw->set_colormap_img(img);
275 }
276 
277 /** Set the image to render the segmented image into.
278  * @param img an Image
279  */
280 void
282 {
283  m_img_segmentation = img;
284  m_seg_img_max_width = m_img_segmentation->get_width();
285  m_seg_img_max_height = m_img_segmentation->get_height();
286  m_img_segmentation->signal_size_allocate().connect(
287  sigc::mem_fun(*this, &ColorTrainWidget::resize_seg_image));
288 }
289 
290 void
291 ColorTrainWidget::resize_seg_image(Gtk::Allocation &allocation)
292 {
293  unsigned int new_width = (unsigned int)allocation.get_width();
294  unsigned int new_height = (unsigned int)allocation.get_height();
295 
296  if (new_width != m_seg_img_max_width || new_height != m_seg_img_max_height) {
297  m_seg_img_max_width = new_width;
298  m_seg_img_max_height = new_height;
299  draw_segmentation_result();
300  }
301 }
302 
303 /** Set the scale to control the selection threshold.
304  * @param scl a Scale
305  */
306 void
308 {
309  m_scl_threshold = scl;
310  m_scl_threshold->signal_change_value().connect(
311  sigc::mem_fun(*this, &ColorTrainWidget::set_threshold));
312 }
313 
314 /** Set the scale to control the minimum probability.
315  * @param scl a Scale
316  */
317 void
319 {
320  m_scl_min_prob = scl;
321  m_scl_min_prob->signal_change_value().connect(
322  sigc::mem_fun(*this, &ColorTrainWidget::set_min_prob));
323 }
324 
325 /** Set the filechooser dialog to be used by this widget.
326  * @param dlg a FileChooserDialog
327  */
328 void
329 ColorTrainWidget::set_filechooser_dlg(Gtk::FileChooserDialog *dlg)
330 {
331  m_fcd_filechooser = dlg;
332 }
333 
334 /** Set the widget to choose the layer of the colormap to display.
335  * @param scl a Scale
336  */
337 void
339 {
340  m_cvw->set_layer_selector(scl);
341 }
342 
343 /** Set the widget to adjust the depth of the colormap.
344  * @param depth SpinButton to set the Y-resolution of the color map
345  * @param width SpinButton to set the U-resolution of the color map
346  * @param height SpinButton to set the V-resolution of the color map
347  */
348 void
349 ColorTrainWidget::set_cm_selector(Gtk::SpinButton *depth,
350  Gtk::SpinButton *width,
351  Gtk::SpinButton *height)
352 {
353  m_spbtn_cm_depth = depth;
354  m_spbtn_cm_width = width;
355  m_spbtn_cm_height = height;
356 }
357 
358 /** Access the signal that is emitted whenever a redraw of the image is necessary.
359  * @return reference to a Dispatcher.
360  */
361 Glib::Dispatcher &
363 {
364  return m_signal_update_image;
365 }
366 
367 /** Access the signal that is emitted whenever the colormap has changed.
368  * @return reference to a Dispatcher.
369  */
370 Glib::Dispatcher &
372 {
373  return m_signal_colormap_updated;
374 }
375 
376 /** Open a dialog to load a histogram. */
377 void
379 {
380  if (!m_fcd_filechooser) {
381  return;
382  }
383 
384  m_fcd_filechooser->set_title("Load histograms");
385  m_fcd_filechooser->set_action(Gtk::FILE_CHOOSER_ACTION_OPEN);
386 
387  m_fcd_filechooser->set_transient_for(*m_wnd_parent);
388 
389  int result = m_fcd_filechooser->run();
390 
391  switch (result) {
392  case (Gtk::RESPONSE_OK): {
393  std::string filename = m_fcd_filechooser->get_filename();
394  if (!m_generator) {
395  m_generator = new BayesColormapGenerator();
396  }
397  m_generator->load_histograms(filename.c_str());
398  m_generator->calc();
399  m_signal_colormap_updated();
400 
401  YuvColormap *cur = m_generator->get_current();
402  if (m_spbtn_cm_depth)
403  m_spbtn_cm_depth->set_value(log(cur->depth()) / log(2));
404  if (m_spbtn_cm_width)
405  m_spbtn_cm_width->set_value(log(cur->width()) / log(2));
406  if (m_spbtn_cm_height)
407  m_spbtn_cm_height->set_value(log(cur->height()) / log(2));
408 
409  m_cvw->set_colormap(cur);
410  m_cvw->draw();
411  draw_segmentation_result();
412  break;
413  }
414 
415  case (Gtk::RESPONSE_CANCEL): break;
416 
417  default: break;
418  }
419 
420  m_fcd_filechooser->hide();
421 }
422 
423 /** Open a dialog to save a histogram. */
424 void
426 {
427  if (!m_fcd_filechooser) {
428  return;
429  }
430 
431  m_fcd_filechooser->set_title("Save histograms");
432  m_fcd_filechooser->set_action(Gtk::FILE_CHOOSER_ACTION_SAVE);
433 
434  m_fcd_filechooser->set_transient_for(*m_wnd_parent);
435 
436  int result = m_fcd_filechooser->run();
437 
438  switch (result) {
439  case (Gtk::RESPONSE_OK): {
440  std::string filename = m_fcd_filechooser->get_filename();
441  m_generator->save_histograms(filename.c_str());
442  break;
443  }
444 
445  case (Gtk::RESPONSE_CANCEL): break;
446 
447  default: break;
448  }
449 
450  m_fcd_filechooser->hide();
451 }
452 
453 /** Generate a new colormap by adding the current histograms. */
454 void
456 {
457  if (!m_src_buffer) {
458  return;
459  }
460 
461  unsigned int cm_depth;
462  if (m_spbtn_cm_depth) {
463  cm_depth = (unsigned int)rint(pow(2.0, m_spbtn_cm_depth->get_value()));
464  } else {
465  cm_depth = 1;
466  }
467 
468  unsigned int cm_width;
469  if (m_spbtn_cm_width) {
470  cm_width = (unsigned int)rint(pow(2.0, m_spbtn_cm_width->get_value()));
471  } else {
472  cm_width = 256;
473  }
474 
475  unsigned int cm_height;
476  if (m_spbtn_cm_height) {
477  cm_height = (unsigned int)rint(pow(2.0, m_spbtn_cm_height->get_value()));
478  } else {
479  cm_height = 256;
480  }
481 
482  if (!m_generator || cm_depth != m_generator->get_current()->depth()
483  || cm_width != m_generator->get_current()->width()
484  || cm_height != m_generator->get_current()->height()) {
485  delete m_generator;
486  m_generator = new BayesColormapGenerator(cm_depth, H_UNKNOWN, cm_width, cm_height);
487  m_cvw->set_colormap(m_generator->get_current());
488  }
489 
490  if (m_fg_object == H_UNKNOWN) {
491  printf("CTW::add_to_colormap(): no fg object set\n");
492  return;
493  }
494 
495  m_generator->set_fg_object(m_fg_object);
496  m_generator->reset_undo();
497  m_generator->set_buffer(m_src_buffer, m_img_width, m_img_height);
498  m_generator->set_selection(m_zauberstab->getSelection());
499  m_generator->consider();
500  m_generator->calc();
501  m_signal_colormap_updated();
502 
503  // update colormap image
504  m_cvw->draw(-1);
505 
506  // update segmentation image
507  draw_segmentation_result();
508 }
509 
510 /** Reset the colormap. */
511 void
513 {
514  Gtk::MessageDialog dialog(*m_wnd_parent,
515  "Are you sure you want to reset the colormap?",
516  false,
517  Gtk::MESSAGE_QUESTION,
518  Gtk::BUTTONS_OK_CANCEL);
519 
520  int result = dialog.run();
521 
522  if (result != Gtk::RESPONSE_OK)
523  return;
524 
525  if (m_generator) {
526  m_generator->reset();
527  m_signal_colormap_updated();
528 
529  if (m_cvw) {
530  m_cvw->draw();
531  }
532 
533  draw_segmentation_result();
534  }
535 }
536 
537 /** Open a dialog to load a colormap. */
538 void
540 {
541  if (!m_fcd_filechooser) {
542  return;
543  }
544 
545  m_fcd_filechooser->set_title("Load colormap colormap");
546  m_fcd_filechooser->set_action(Gtk::FILE_CHOOSER_ACTION_OPEN);
547 
548  m_fcd_filechooser->set_transient_for(*m_wnd_parent);
549 
550  int result = m_fcd_filechooser->run();
551 
552  switch (result) {
553  case (Gtk::RESPONSE_OK): {
554  delete m_generator;
555 
556  std::string filename = m_fcd_filechooser->get_filename();
557  ColormapFile cmf;
558  cmf.read(filename.c_str());
559  Colormap * tcm = cmf.get_colormap();
560  YuvColormap *tycm = dynamic_cast<YuvColormap *>(tcm);
561  if (!tycm) {
562  delete tcm;
563  throw fawkes::TypeMismatchException("File does not contain a YUV colormap");
564  }
565  unsigned int cm_depth = tcm->depth();
566  unsigned int cm_width = tcm->width();
567  unsigned int cm_height = tcm->height();
568  m_generator = new BayesColormapGenerator(cm_depth, H_UNKNOWN, cm_width, cm_height);
569  YuvColormap *current = m_generator->get_current();
570  *current = *tycm;
571  delete tcm;
572 
573  if (m_spbtn_cm_depth)
574  m_spbtn_cm_depth->set_value(log(cm_depth) / log(2));
575  if (m_spbtn_cm_width)
576  m_spbtn_cm_width->set_value(log(cm_width) / log(2));
577  if (m_spbtn_cm_height)
578  m_spbtn_cm_height->set_value(log(cm_height) / log(2));
579 
580  m_signal_colormap_updated();
581  m_cvw->set_colormap(m_generator->get_current());
582  m_cvw->draw();
583  draw_segmentation_result();
584  break;
585  }
586 
587  case (Gtk::RESPONSE_CANCEL): break;
588 
589  default: break;
590  }
591 
592  m_fcd_filechooser->hide();
593 }
594 
595 /** Open a dialog to save a colormap. */
596 void
598 {
599  if (!m_fcd_filechooser) {
600  return;
601  }
602 
603  m_fcd_filechooser->set_title("Save colormap colormap");
604  m_fcd_filechooser->set_action(Gtk::FILE_CHOOSER_ACTION_SAVE);
605 
606  m_fcd_filechooser->set_transient_for(*m_wnd_parent);
607 
608  int result = m_fcd_filechooser->run();
609 
610  switch (result) {
611  case (Gtk::RESPONSE_OK): {
612  std::string filename = m_fcd_filechooser->get_filename();
613  YuvColormap *current = m_generator->get_current();
614  ColormapFile cmf(current->depth(), current->width(), current->height());
615  cmf.add_colormap(current);
616  cmf.write(filename.c_str());
617  break;
618  }
619 
620  case (Gtk::RESPONSE_CANCEL): break;
621 
622  default: break;
623  }
624 
625  m_fcd_filechooser->hide();
626 }
627 
628 /** Get the current colormap.
629  * @return the current colormap
630  */
631 YuvColormap *
633 {
634  if (!m_generator) {
635  return 0;
636  }
637 
638  return m_generator->get_current();
639 }
640 
641 bool
642 ColorTrainWidget::set_threshold(Gtk::ScrollType scroll, double value)
643 {
644  unsigned int threshold = (unsigned int)rint(value);
645  m_zauberstab->setThreshold(threshold);
646 
647  return true;
648 }
649 
650 bool
651 ColorTrainWidget::set_min_prob(Gtk::ScrollType scroll, double value)
652 {
653  if (!m_generator) {
654  return true;
655  }
656 
657  m_generator->set_min_probability(value);
658 
659  return true;
660 }
661 
662 void
663 ColorTrainWidget::reset_gui()
664 {
665  m_scl_min_prob->set_value(0.0);
666 }
667 
668 /** Render the result of segmenting the image in the source buffer considering the current
669  * colormap into the specified Image.
670  */
671 void
673 {
674  if (!m_src_buffer || !m_img_segmentation || !m_generator) {
675  return;
676  }
677 
678  unsigned char *seg_buffer = (unsigned char *)malloc(m_img_size);
679  bzero(seg_buffer, m_img_size);
680 
681  Drawer d;
682  d.set_buffer(seg_buffer, m_img_width, m_img_height);
683 
684  YuvColormap *cm = m_generator->get_current();
685 
686  for (unsigned int w = 0; w < m_img_width; ++w) {
687  for (unsigned int h = 0; h < m_img_height; ++h) {
688  unsigned int y = YUV422_PLANAR_Y_AT(m_src_buffer, m_img_width, w, h);
689  unsigned int u = YUV422_PLANAR_U_AT(m_src_buffer, m_img_width, m_img_height, w, h);
690  unsigned int v = YUV422_PLANAR_V_AT(m_src_buffer, m_img_width, m_img_height, w, h);
691 
693  d.color_point(w, h);
694  }
695  }
696 
697  LossyScaler scaler;
698  scaler.set_original_buffer(seg_buffer);
699  scaler.set_original_dimensions(m_img_width, m_img_height);
700  scaler.set_scaled_dimensions(m_seg_img_max_width, m_seg_img_max_height);
701  unsigned int width = scaler.needed_scaled_width();
702  unsigned int height = scaler.needed_scaled_height();
703 
704  unsigned char *scaled_buffer =
705  (unsigned char *)malloc(colorspace_buffer_size(m_img_cs, width, height));
706  scaler.set_scaled_buffer(scaled_buffer);
707  scaler.scale();
708 
709  unsigned char *rgb_buffer = (unsigned char *)malloc(colorspace_buffer_size(RGB, width, height));
710  convert(m_img_cs, RGB, scaled_buffer, rgb_buffer, width, height);
711 
712  Glib::RefPtr<Gdk::Pixbuf> image =
713  Gdk::Pixbuf::create_from_data(rgb_buffer,
714  Gdk::COLORSPACE_RGB,
715  false,
716  8,
717  width,
718  height,
719  3 * width,
720  Gdk::Pixbuf::SlotDestroyData(&free_rgb_buffer));
721 
722  m_img_segmentation->set(image);
723 
724  free(scaled_buffer);
725  free(seg_buffer);
726 }
727 
728 /** Callback to free the rgb buffer
729  * @param rgb_buffer pointer to the buffer
730  */
731 void
732 ColorTrainWidget::free_rgb_buffer(const guint8 *rgb_buffer)
733 {
734  free(const_cast<guint8 *>(rgb_buffer));
735 }
firevision::Zauberstab
Zaubertab selection utility.
Definition: zauberstab.h:67
firevision::YuvColormap::depth
virtual unsigned int depth() const
Get depth of colormap.
Definition: yuvcm.cpp:336
firevision::ZRegion::slices
std::vector< ZSlice * > * slices
slices
Definition: zauberstab.h:58
firevision::ColorObjectMap::get_color
static YUV_t get_color(color_t color)
YUV_t getter.
Definition: color_object_map.cpp:101
ColorTrainWidget::set_draw_buffer
void set_draw_buffer(unsigned char *buffer)
Set the buffer to draw the selection into.
Definition: color_train_widget.cpp:124
ColorTrainWidget::colormap_updated
Glib::Dispatcher & colormap_updated()
Access the signal that is emitted whenever the colormap has changed.
Definition: color_train_widget.cpp:371
ColorTrainWidget::reset_colormap
void reset_colormap()
Reset the colormap.
Definition: color_train_widget.cpp:512
ColorTrainWidget::reset_selection
void reset_selection()
Reset the selection.
Definition: color_train_widget.cpp:178
ColorTrainWidget::set_reset_colormap_btn
void set_reset_colormap_btn(Gtk::Button *btn)
Set the button to reset the colormap.
Definition: color_train_widget.cpp:217
ColorTrainWidget::set_save_colormap_btn
void set_save_colormap_btn(Gtk::Button *btn)
Set the buffon to open a dialog to save a colormap.
Definition: color_train_widget.cpp:261
firevision::YuvColormap
YUV Colormap.
Definition: yuvcm.h:36
firevision::LossyScaler::scale
virtual void scale()
Scale image.
Definition: lossy.cpp:139
ColorTrainWidget::get_colormap
firevision::YuvColormap * get_colormap() const
Get the current colormap.
Definition: color_train_widget.cpp:632
ColorTrainWidget::set_save_histos_btn
void set_save_histos_btn(Gtk::Button *btn)
Set the buffon to open a dialog to save histograms.
Definition: color_train_widget.cpp:239
ColorTrainWidget::set_fg_object
void set_fg_object(firevision::hint_t fg_object)
Set the current foreground object.
Definition: color_train_widget.cpp:87
firevision::Drawer::set_color
void set_color(unsigned char y, unsigned char u, unsigned char v)
Set drawing color.
Definition: drawer.cpp:71
firevision::Colormap::height
virtual unsigned int height() const =0
Get height of colormap.
ColorTrainWidget::load_histograms
void load_histograms()
Open a dialog to load a histogram.
Definition: color_train_widget.cpp:378
firevision::FireVisionDataFile::read
virtual void read(const char *file_name)
Read file.
Definition: fvfile.cpp:290
ColorTrainWidget::set_src_buffer
void set_src_buffer(unsigned char *buffer, unsigned int img_width, unsigned int img_height)
Set the buffer containing the image data.
Definition: color_train_widget.cpp:98
ColorTrainWidget::set_segmentation_img
void set_segmentation_img(Gtk::Image *img)
Set the image to render the segmented image into.
Definition: color_train_widget.cpp:281
firevision::LossyScaler::set_original_buffer
virtual void set_original_buffer(unsigned char *buffer)
Set original image buffer.
Definition: lossy.cpp:109
firevision::ColormapFile::get_colormap
Colormap * get_colormap()
Get a freshly generated colormap based on current file content.
Definition: cmfile.cpp:164
ColorTrainWidget::add_to_colormap
void add_to_colormap()
Generate a new colormap by adding the current histograms.
Definition: color_train_widget.cpp:455
ColorTrainWidget::set_colormap_img
void set_colormap_img(Gtk::Image *img)
Set the image to render the colormap into.
Definition: color_train_widget.cpp:272
firevision::Colormap::depth
virtual unsigned int depth() const =0
Get depth of colormap.
firevision::Drawer::color_point
void color_point(unsigned int x, unsigned int y)
Color the given point.
Definition: drawer.cpp:316
ColorTrainWidget::set_filechooser_dlg
void set_filechooser_dlg(Gtk::FileChooserDialog *dlg)
Set the filechooser dialog to be used by this widget.
Definition: color_train_widget.cpp:329
ColormapViewerWidget
Select a layer from a colormap and render it to a Gtk::Image.
Definition: colormap_viewer_widget.h:33
ColorTrainWidget::set_cm_selector
void set_cm_selector(Gtk::SpinButton *depth, Gtk::SpinButton *width=0, Gtk::SpinButton *height=0)
Set the widget to adjust the depth of the colormap.
Definition: color_train_widget.cpp:349
ColorTrainWidget::draw_segmentation_result
void draw_segmentation_result()
Render the result of segmenting the image in the source buffer considering the current colormap into ...
Definition: color_train_widget.cpp:672
ColorTrainWidget::set_load_histos_btn
void set_load_histos_btn(Gtk::Button *btn)
Set the buffon to open a dialog to load histograms.
Definition: color_train_widget.cpp:228
firevision::YuvColormap::width
virtual unsigned int width() const
Get width of colormap.
Definition: yuvcm.cpp:324
fawkes::TypeMismatchException
Type mismatch.
Definition: software.h:44
firevision::ZRegion
a region is a stack of slices, together with the y-position of the slice at the top
Definition: zauberstab.h:56
ColorTrainWidget::set_cm_layer_selector
void set_cm_layer_selector(Gtk::Scale *scl)
Set the widget to choose the layer of the colormap to display.
Definition: color_train_widget.cpp:338
ColorTrainWidget::set_load_colormap_btn
void set_load_colormap_btn(Gtk::Button *btn)
Set the buffon to open a dialog to load a colormap.
Definition: color_train_widget.cpp:250
firevision::LossyScaler::set_scaled_dimensions
virtual void set_scaled_dimensions(unsigned int width, unsigned int height)
Set dimenins of scaled image buffer.
Definition: lossy.cpp:83
ColorTrainWidget::update_image
Glib::Dispatcher & update_image()
Access the signal that is emitted whenever a redraw of the image is necessary.
Definition: color_train_widget.cpp:362
firevision::FireVisionDataFile::write
virtual void write(const char *file_name)
Write file.
Definition: fvfile.cpp:243
ColorTrainWidget::ColorTrainWidget
ColorTrainWidget(Gtk::Window *parent)
Constructor.
Definition: color_train_widget.cpp:51
firevision::LossyScaler::needed_scaled_width
virtual unsigned int needed_scaled_width()
Minimum needed width of scaled image depending on factor and original image width.
Definition: lossy.cpp:121
ColorTrainWidget::save_colormap
void save_colormap()
Open a dialog to save a colormap.
Definition: color_train_widget.cpp:597
firevision::Drawer::draw_rectangle_inverted
void draw_rectangle_inverted(unsigned int x, unsigned int y, unsigned int w, unsigned int h)
Draw inverted rectangle.
Definition: drawer.cpp:251
ColorTrainWidget::~ColorTrainWidget
virtual ~ColorTrainWidget()
Destructor.
Definition: color_train_widget.cpp:78
ColorTrainWidget::set_min_prob_scl
void set_min_prob_scl(Gtk::Scale *scl)
Set the scale to control the minimum probability.
Definition: color_train_widget.cpp:318
ColorTrainWidget::set_threshold_scl
void set_threshold_scl(Gtk::Scale *scl)
Set the scale to control the selection threshold.
Definition: color_train_widget.cpp:307
firevision::LossyScaler
Lossy image scaler.
Definition: lossy.h:33
ColorTrainWidget::set_add_to_colormap_btn
void set_add_to_colormap_btn(Gtk::Button *btn)
Set the button to trigger the generation of the colormap.
Definition: color_train_widget.cpp:206
firevision::ColormapFile::add_colormap
void add_colormap(Colormap *colormap)
Add colormap.
Definition: cmfile.cpp:89
firevision::YuvColormap::height
virtual unsigned int height() const
Get height of colormap.
Definition: yuvcm.cpp:330
firevision::LossyScaler::set_original_dimensions
virtual void set_original_dimensions(unsigned int width, unsigned int height)
Set original image dimensions.
Definition: lossy.cpp:76
firevision::Colormap
Colormap interface.
Definition: colormap.h:37
firevision::Drawer
Draw to an image.
Definition: drawer.h:32
firevision::ColormapFile
Colormap file.
Definition: cmfile.h:55
ColorTrainWidget::save_histograms
void save_histograms()
Open a dialog to save a histogram.
Definition: color_train_widget.cpp:425
ColorTrainWidget::set_reset_selection_btn
void set_reset_selection_btn(Gtk::Button *btn)
Set the button to reset the selection.
Definition: color_train_widget.cpp:195
ColorTrainWidget::load_colormap
void load_colormap()
Open a dialog to load a colormap.
Definition: color_train_widget.cpp:539
firevision::LossyScaler::set_scaled_buffer
virtual void set_scaled_buffer(unsigned char *buffer)
Set scaled image buffer.
Definition: lossy.cpp:115
firevision::BayesColormapGenerator
Colormap Generator using Bayes method.
Definition: bayes_generator.h:38
firevision::YuvColormap::determine
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const
Determine color class for given YUV value.
Definition: yuvcm.h:99
firevision::Colormap::width
virtual unsigned int width() const =0
Get width of colormap.
firevision::LossyScaler::needed_scaled_height
virtual unsigned int needed_scaled_height()
Minimum needed height of scaled image depending on factor and original image height.
Definition: lossy.cpp:127
firevision::Drawer::set_buffer
void set_buffer(unsigned char *buffer, unsigned int width, unsigned int height)
Set the buffer to draw to.
Definition: drawer.cpp:58
ColorTrainWidget::click
void click(unsigned int x, unsigned int y, unsigned int button=MOUSE_BUTTON_LEFT)
The user clicked into the image.
Definition: color_train_widget.cpp:135