Commit 972bf3c4 authored by Davis King's avatar Davis King

Made the box colors in imglab spread more evenly over the color space.

parent 511c05ad
......@@ -20,7 +20,7 @@
#include <dlib/dir_nav.h>
const char* VERSION = "1.11";
const char* VERSION = "1.12";
const int JPEG_QUALITY = 90;
......
......@@ -19,27 +19,6 @@ using namespace dlib;
extern const char* VERSION;
rgb_alpha_pixel string_to_color(
const std::string& str
)
{
if (str.size() == 0)
{
return rgb_alpha_pixel(255,0,0,255);
}
else
{
// make up a random color based on the string label.
hsi_pixel pix;
pix.h = static_cast<unsigned char>(dlib::hash(str)&0xFF);
pix.s = 255;
pix.i = 150;
rgb_alpha_pixel result;
assign_pixel(result, pix);
return result;
}
}
// ----------------------------------------------------------------------------------------
metadata_editor::
......@@ -78,6 +57,7 @@ metadata_editor(
overlay_label_name.set_text("Next Label: ");
overlay_label.set_width(200);
display.set_image_clicked_handler(*this, &metadata_editor::on_image_clicked);
display.set_overlay_rects_changed_handler(*this, &metadata_editor::on_overlay_rects_changed);
display.set_overlay_rect_selected_handler(*this, &metadata_editor::on_overlay_rect_selected);
overlay_label.set_text_modified_handler(*this, &metadata_editor::on_overlay_label_changed);
......@@ -479,7 +459,8 @@ on_lb_images_clicked(
// ----------------------------------------------------------------------------------------
std::vector<dlib::image_display::overlay_rect> get_overlays (
const dlib::image_dataset_metadata::image& data
const dlib::image_dataset_metadata::image& data,
color_mapper& string_to_color
)
{
std::vector<dlib::image_display::overlay_rect> temp(data.boxes.size());
......@@ -521,7 +502,7 @@ load_image(
if (display_equialized_image)
equalize_histogram(img);
display.set_image(img);
display.add_overlay(get_overlays(metadata.images[idx]));
display.add_overlay(get_overlays(metadata.images[idx], string_to_color));
}
// ----------------------------------------------------------------------------------------
......@@ -569,7 +550,7 @@ load_image_and_set_size(
if (display_equialized_image)
equalize_histogram(img);
display.set_image(img);
display.add_overlay(get_overlays(metadata.images[idx]));
display.add_overlay(get_overlays(metadata.images[idx], string_to_color));
}
// ----------------------------------------------------------------------------------------
......@@ -600,12 +581,21 @@ on_overlay_rects_changed(
// ----------------------------------------------------------------------------------------
void metadata_editor::
on_image_clicked(
const point& /*p*/, bool /*is_double_click*/, unsigned long /*btn*/
)
{
display.set_default_overlay_rect_color(string_to_color(trim(overlay_label.text())));
}
// ----------------------------------------------------------------------------------------
void metadata_editor::
on_overlay_label_changed(
)
{
display.set_default_overlay_rect_label(trim(overlay_label.text()));
display.set_default_overlay_rect_color(string_to_color(trim(overlay_label.text())));
}
// ----------------------------------------------------------------------------------------
......
......@@ -4,7 +4,54 @@
#define DLIB_METADATA_EdITOR_H__
#include <dlib/gui_widgets.h>
#include "dlib/data_io.h"
#include <dlib/data_io.h>
#include <dlib/pixel.h>
#include <map>
// ----------------------------------------------------------------------------------------
class color_mapper
{
public:
dlib::rgb_alpha_pixel operator() (
const std::string& str
)
{
auto i = colors.find(str);
if (i != colors.end())
{
return i->second;
}
else
{
using namespace dlib;
hsi_pixel pix;
pix.h = reverse(colors.size());
std::cout << "new h: "<< (unsigned int)pix.h << std::endl;
pix.s = 255;
pix.i = 150;
rgb_alpha_pixel result;
assign_pixel(result, pix);
colors[str] = result;
return result;
}
}
private:
// We use a bit reverse here because it causes us to evenly spread the colors as we
// allocated them. First the colors are maximally different, then become interleaved
// and progressively more similar as they are allocated.
unsigned char reverse(unsigned char b)
{
// reverse the order of the bits in b.
b = ((b * 0x0802LU & 0x22110LU) | (b * 0x8020LU & 0x88440LU)) * 0x10101LU >> 16;
return b;
}
std::map<std::string, dlib::rgb_alpha_pixel> colors;
};
// ----------------------------------------------------------------------------------------
......@@ -39,6 +86,7 @@ private:
void save_metadata_to_file (const std::string& file);
void load_image(unsigned long idx);
void load_image_and_set_size(unsigned long idx);
void on_image_clicked(const dlib::point& p, bool is_double_click, unsigned long btn);
void on_overlay_rects_changed();
void on_overlay_label_changed();
void on_overlay_rect_selected(const dlib::image_display::overlay_rect& orect);
......@@ -59,6 +107,7 @@ private:
unsigned long keyboard_jump_pos;
time_t last_keyboard_jump_pos_update;
bool display_equialized_image = false;
color_mapper string_to_color;
};
// ----------------------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment