diff options
author | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2013-07-18 15:07:42 +0200 |
---|---|---|
committer | Matthias Vogelgesang <matthias.vogelgesang@kit.edu> | 2013-07-18 15:08:59 +0200 |
commit | 79953995d6be8ef572ab20576509c8daa86cabaf (patch) | |
tree | ebe0b1d695836aab8fbbb13649697c2183923e25 /bin | |
parent | 6fcf60b5678e9602486d36462cc246454ae636d0 (diff) | |
download | libuca-79953995d6be8ef572ab20576509c8daa86cabaf.tar.gz libuca-79953995d6be8ef572ab20576509c8daa86cabaf.tar.bz2 libuca-79953995d6be8ef572ab20576509c8daa86cabaf.tar.xz libuca-79953995d6be8ef572ab20576509c8daa86cabaf.zip |
Print some statistics
Diffstat (limited to 'bin')
-rw-r--r-- | bin/gui/control.c | 84 | ||||
-rw-r--r-- | bin/gui/control.glade | 238 |
2 files changed, 271 insertions, 51 deletions
diff --git a/bin/gui/control.c b/bin/gui/control.c index 3d108df..74b8312 100644 --- a/bin/gui/control.c +++ b/bin/gui/control.c @@ -44,6 +44,10 @@ typedef struct { GtkWidget *record_button; GtkWidget *download_button; GtkComboBox *zoom_box; + GtkLabel *mean_label; + GtkLabel *sigma_label; + GtkLabel *max_label; + GtkLabel *min_label; GtkDialog *download_dialog; GtkProgressBar *download_progressbar; @@ -167,6 +171,54 @@ up_scale (ThreadData *data, gpointer buffer) } static void +get_statistics (ThreadData *data, gdouble *mean, gdouble *sigma, guint *_max, guint *_min) +{ + gdouble sum = 0.0; + gdouble squared_sum = 0.0; + guint min = G_MAXUINT; + guint max = 0; + guint n = data->width * data->height; + + if (data->pixel_size == 1) { + guint8 *input = (guint8 *) ring_buffer_get_current_pointer (data->buffer); + + for (gint i = 0; i < n; i++) { + guint8 val = input[i]; + + if (val > max) + max = val; + + if (val < min) + min = val; + + sum += val; + squared_sum += val * val; + } + } + else { + guint16 *input = (guint16 *) ring_buffer_get_current_pointer (data->buffer); + + for (gint i = 0; i < n; i++) { + guint16 val = input[i]; + + if (val > max) + max = val; + + if (val < min) + min = val; + + sum += val; + squared_sum += val * val; + } + } + + *mean = sum / n; + *sigma = sqrt((squared_sum - sum*sum/n) / (n - 1)); + *_min = min; + *_max = max; +} + +static void convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) { if (data->zoom_factor <= 1) @@ -178,10 +230,36 @@ convert_grayscale_to_rgb (ThreadData *data, gpointer buffer) static void update_pixbuf (ThreadData *data) { + GString *string; + gdouble mean; + gdouble sigma; + guint min; + guint max; + gdk_flush (); gtk_image_set_from_pixbuf (GTK_IMAGE (data->image), data->pixbuf); gtk_widget_queue_draw_area (data->image, 0, 0, data->display_width, data->display_height); + egg_histogram_view_update (EGG_HISTOGRAM_VIEW (data->histogram_view), + ring_buffer_get_current_pointer (data->buffer)); + + get_statistics (data, &mean, &sigma, &min, &max); + string = g_string_new_len (NULL, 32); + + g_string_printf (string, "\u03bc = %3.2f", mean); + gtk_label_set_text (data->mean_label, string->str); + + g_string_printf (string, "\u03c3 = %3.2f", sigma); + gtk_label_set_text (data->sigma_label, string->str); + + g_string_printf (string, "min = %i", min); + gtk_label_set_text (data->min_label, string->str); + + g_string_printf (string, "max = %i", max); + gtk_label_set_text (data->max_label, string->str); + + g_string_free (string, TRUE); + if (gtk_toggle_button_get_active (data->histogram_button)) gtk_widget_queue_draw (data->histogram_view); } @@ -237,7 +315,6 @@ preview_frames (void *args) uca_camera_grab (data->camera, buffer, &error); if (error == NULL) { - egg_histogram_view_update (EGG_HISTOGRAM_VIEW (data->histogram_view), buffer); convert_grayscale_to_rgb (data, buffer); gdk_threads_enter (); @@ -605,6 +682,11 @@ create_main_window (GtkBuilder *builder, const gchar* camera_name) td.frame_slider = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "frames-adjustment")); td.count = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "acquisitions-adjustment")); + td.mean_label = GTK_LABEL (gtk_builder_get_object (builder, "mean-label")); + td.sigma_label = GTK_LABEL (gtk_builder_get_object (builder, "sigma-label")); + td.max_label = GTK_LABEL (gtk_builder_get_object (builder, "max-label")); + td.min_label = GTK_LABEL (gtk_builder_get_object (builder, "min-label")); + td.download_dialog = GTK_DIALOG (gtk_builder_get_object (builder, "download-dialog")); td.download_adjustment = GTK_ADJUSTMENT (gtk_builder_get_object (builder, "download-adjustment")); td.download_close_button = GTK_WIDGET (gtk_builder_get_object (builder, "download-close-button")); diff --git a/bin/gui/control.glade b/bin/gui/control.glade index 9784d09..7b497ab 100644 --- a/bin/gui/control.glade +++ b/bin/gui/control.glade @@ -462,44 +462,106 @@ </packing> </child> <child> - <object class="GtkVBox" id="histogram-box"> + <object class="GtkVBox" id="vbox7"> <property name="visible">True</property> <property name="border_width">12</property> <child> - <object class="GtkHBox" id="hbox1"> + <object class="GtkLabel" id="label5"> <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Histogram</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkVBox" id="histogram-box"> + <property name="visible">True</property> + <property name="border_width">12</property> <child> - <object class="GtkLabel" id="label2"> + <object class="GtkHBox" id="hbox1"> <property name="visible">True</property> - <property name="xalign">0</property> - <property name="label" translatable="yes">Minimum:</property> + <child> + <object class="GtkLabel" id="label2"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Minimum:</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkSpinButton" id="spinbutton1"> + <property name="width_request">100</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="invisible_char">•</property> + <property name="adjustment">min-bin-value-adjustment</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="padding">6</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label3"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Maximum:</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkSpinButton" id="spinbutton2"> + <property name="width_request">100</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="invisible_char">•</property> + <property name="adjustment">max-bin-value-adjustment</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="padding">6</property> + <property name="position">3</property> + </packing> + </child> </object> <packing> <property name="expand">False</property> <property name="fill">False</property> + <property name="padding">6</property> <property name="position">0</property> </packing> </child> <child> - <object class="GtkSpinButton" id="spinbutton1"> - <property name="width_request">100</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">•</property> - <property name="adjustment">min-bin-value-adjustment</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="padding">6</property> - <property name="position">1</property> - </packing> + <placeholder/> </child> <child> - <object class="GtkLabel" id="label3"> + <object class="GtkCheckButton" id="histogram-checkbutton"> + <property name="label" translatable="yes">Live Update</property> <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">False</property> + <property name="border_width">6</property> <property name="xalign">0</property> - <property name="label" translatable="yes">Maximum:</property> + <property name="active">True</property> + <property name="draw_indicator">True</property> </object> <packing> <property name="expand">False</property> @@ -507,42 +569,19 @@ <property name="position">2</property> </packing> </child> - <child> - <object class="GtkSpinButton" id="spinbutton2"> - <property name="width_request">100</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">•</property> - <property name="adjustment">max-bin-value-adjustment</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="padding">6</property> - <property name="position">3</property> - </packing> - </child> </object> <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="padding">6</property> - <property name="position">0</property> + <property name="position">1</property> </packing> </child> <child> - <placeholder/> - </child> - <child> - <object class="GtkCheckButton" id="histogram-checkbutton"> - <property name="label" translatable="yes">Live Update</property> + <object class="GtkLabel" id="label19"> <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="receives_default">False</property> - <property name="border_width">6</property> <property name="xalign">0</property> - <property name="active">True</property> - <property name="draw_indicator">True</property> + <property name="label" translatable="yes">Statistics</property> + <attributes> + <attribute name="weight" value="bold"/> + </attributes> </object> <packing> <property name="expand">False</property> @@ -550,6 +589,105 @@ <property name="position">2</property> </packing> </child> + <child> + <object class="GtkTable" id="table1"> + <property name="visible">True</property> + <property name="border_width">12</property> + <property name="n_rows">2</property> + <property name="n_columns">2</property> + <property name="column_spacing">6</property> + <property name="row_spacing">6</property> + <child> + <object class="GtkLabel" id="label20"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Pixel counts:</property> + </object> + <packing> + <property name="x_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label21"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">Distribution:</property> + </object> + <packing> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options">GTK_FILL</property> + </packing> + </child> + <child> + <object class="GtkHBox" id="hbox5"> + <property name="visible">True</property> + <property name="spacing">6</property> + <child> + <object class="GtkLabel" id="mean-label"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">µ = 0.0</property> + </object> + <packing> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="sigma-label"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">σ = 0.0</property> + </object> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="min-label"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">min = 0</property> + </object> + <packing> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="max-label"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">max = 0</property> + </object> + <packing> + <property name="position">3</property> + </packing> + </child> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label26"> + <property name="visible">True</property> + <property name="xalign">0</property> + <property name="label" translatable="yes">0</property> + </object> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + </packing> + </child> + </object> + <packing> + <property name="position">3</property> + </packing> + </child> </object> <packing> <property name="position">1</property> @@ -558,7 +696,7 @@ <child type="tab"> <object class="GtkLabel" id="label1"> <property name="visible">True</property> - <property name="label" translatable="yes">Histogram</property> + <property name="label" translatable="yes">Statistics</property> </object> <packing> <property name="position">1</property> |