Commit b9a5b97f authored by Yann Jacquelet's avatar Yann Jacquelet
Browse files

Work on Millet hsv descriptors.

	* green/exp/annotating/hsv: New directory.
	* green/Exp/annotating/hsv/hsv.cc: New source file.
parent d1693388
......@@ -75,6 +75,29 @@
* bin/pgm_to_pbm.cc,
* bin/ppm_negate.cc: New.
2010-06-21 Yann Jacquelet <jacquelet@lrde.epita.fr>
Work on Millet hsv descriptors.
* green/exp/annotating/hsv: New directory.
* green/Exp/annotating/hsv/hsv.cc: New source file.
2010-06-21 Yann Jacquelet <jacquelet@lrde.epita.fr>
Work on histograms view as density.
* green/exp/annotating/histo: New directory.
* green/exp/annotating/histo/histo.cc: New Makefile.am.
* green/exp/annotating/histo/histo.cc: New source.
2010-06-21 Yann Jacquelet <jacquelet@lrde.epita.fr>
Test error quantification as a color descriptor in our database.
* green/exp/annotating/error: New directory.
* green/exp/annotating/error/Makefile.am: New Makefile.
* green/exp/annotating/error/error.cc: New source.
2010-06-21 Yann Jacquelet <jacquelet@lrde.epita.fr>
Benchmark few descriptors.
......@@ -87,6 +110,7 @@
Test on image database the achromatism descriptor.
* green/exp/annotating/achromatism: New directory.
* green/exp/annotating/achromatism/Makefile.am: New Makefile.
* green/exp/annotating/achromatism/achromatism.am: New source.
* green/exp/annotating/achromatism/text-color.txt: New image class.
......
#
# Generic Makefile
#
#########
# TOOLS #
#########
LOADLIBES= -lboost_filesystem
INCLUDES1= -I$(HOME)/git/olena/milena/sandbox/green
INCLUDES2= -I$(HOME)/git/olena/milena
INCLUDES= $(INCLUDES1) $(INCLUDES2)
#CXXFLAGS= -ggdb -O0 -Wall -W -pedantic -ansi -pipe $(INCLUDES)
#CXXFLAGS= -DNDEBUG -O1 -Wall -W -pedantic -ansi -pipe $(INCLUDES)
CXXFLAGS= -DNDEBUG -O3 -Wall -W -pedantic -ansi -pipe $(INCLUDES)
ECHO= echo
RM= rm
MKDIR= mkdir -p
CP= cp
SOURCE_PATTERN= green/exp
BUILD__PATTERN= green/build/exp
ifeq ($(findstring $(BUILD__PATTERN),$(PWD)), $(BUILD__PATTERN))
# Case where make is done from build directory.
SOURCE_DIR= $(subst $(BUILD__PATTERN),$(SOURCE_PATTERN),$(PWD))
BUILD__DIR= $(PWD)/
else
# Case where make is done from source directory.
SOURCE_DIR= $(PWD)/
BUILD__DIR= $(subst $(SOURCE_PATTERN),$(BUILD__PATTERN),$(PWD))
endif
SRC= $(notdir $(wildcard $(SOURCE_DIR)/*.cc))
OLD= $(notdir $(wildcard $(SOURCE_DIR)/*~))
OBJ= $(patsubst %.cc,%.o,$(SRC))
SOURCE_MAKEFILE=Makefile.am
BUILD__MAKEFILE=Makefile
TARGET_FILE= $(notdir $(PWD))
SOURCE_FILES= $(notdir $(wildcard $(SOURCE_DIR)/*.*))
BUILD__FILES= $(filter-out $(SRC) $(SOURCE_MAKEFILE), $(SOURCE_FILES))
BUILD__F_PATH= $(addprefix $(BUILD__DIR)/,$(BUILD__FILES))
SOURCE_F_PATH= $(addprefix $(SOURCE_DIR)/,$(SOURCE_FILES))
BUILD__M_PATH= $(addprefix $(BUILD__DIR)/,$(BUILD__MAKEFILE))
SOURCE_M_PATH= $(addprefix $(SOURCE_DIR)/,$(SOURCE_MAKEFILE))
TARGET_F_PATH= $(addprefix $(BUILD__DIR)/,$(TARGET_FILE))
OBJ_F_PATH= $(addprefix $(BUILD__DIR)/,$(OBJ))
SRC_F_PATH= $(addprefix $(SOURCE_DIR)/,$(SRC))
OLD_F_PATH= $(addprefix $(SOURCE_DIR)/,$(OLD))
#############
# BOOTSTRAP #
#############
bootstrap: $(BUILD__DIR) $(BUILD__F_PATH) $(BUILD__M_PATH)
# Create, if nessary, the destination directory
$(BUILD__DIR):
$(MKDIR) $(BUILD__DIR)
# Copy, if nessary, all the files, except the Makefile.am
$(BUILD__F_PATH): $(SOURCE_F_PATH)
$(CP) $(addprefix $(SOURCE_DIR),$(@F)) $@
# Copy if nessary, the Makefile.am into Makefile
$(BUILD__M_PATH): $(SOURCE_M_PATH)
$(CP) $(SOURCE_M_PATH) $(BUILD__M_PATH)
#######
# ALL #
#######
# We assume that the call is done from the build directory.
# With the directive vpath, hidden files are found in the source directory.
all: $(TARGET_F_PATH)
$(TARGET_F_PATH): $(OBJ_F_PATH)
$(LINK.cc) $< $(LOADLIBES) $(LDLIBS) -o $@
$(OBJ_F_PATH):$(SRC_F_PATH)
$(COMPILE.cc) $(OUTPUT_OPTION) $<
#########
# CLEAN #
#########
# Force every time the deletion
clean: clean_target clean_obj clean_dst clean_old #clean_make
clean_target:
-@$(RM) $(TARGET_F_PATH) &> /dev/null
clean_obj:
-@$(RM) $(OBJ_F_PATH) &> /dev/null
clean_dst:
-@$(RM) $(BUILD_F_PATH) &> /dev/null
clean_make:
-@$(RM) $(BUILD_M_PATH) &> /dev/null
clean_old:
-@$(RM) $(OLD_F_PATH) &> /dev/null
#########
# PRINT #
#########
print: print_tools print_bootstrap
print_tools:
@$(ECHO) "HOME = $(HOME)"
@$(ECHO) "INCLUDES = $(INCLUDES)"
@$(ECHO) "CXXFLAGS = $(CXXFLAGS)"
@$(ECHO) "ECHO = $(ECHO)"
@$(ECHO) "RM = $(RM)"
@$(ECHO) "MKDIR = $(MKDIR)"
@$(ECHO) "CP = $(CP)"
@$(ECHO)
print_bootstrap:
@$(ECHO) "PWD = $(PWD)"
@$(ECHO) "SOURCE_PATTERN = $(SOURCE_PATTERN)"
@$(ECHO) "BUILD__PATTERN = $(BUILD__PATTERN)"
@$(ECHO) "SOURCE_DIR = $(SOURCE_DIR)"
@$(ECHO) "BUILD__DIR = $(BUILD__DIR)"
@$(ECHO) "SOURCE_MAKEFILE = $(SOURCE_MAKEFILE)"
@$(ECHO) "BUILD__MAKEFILE = $(BUILD__MAKEFILE)"
@$(ECHO) "TARGET_FILE = $(TARGET_FILE)"
@$(ECHO) "SOURCE_FILES = $(SOURCE_FILES)"
@$(ECHO) "SOURCE_F_PATH = $(SOURCE_F_PATH)"
@$(ECHO) "BUILD__FILES = $(BUILD__FILES)"
@$(ECHO) "BUILD__F_PATH = $(BUILD__F_PATH)"
@$(ECHO) "BUILD__M_PATH = $(BUILD__M_PATH)"
@$(ECHO) "SOURCE_M_PATH = $(SOURCE_M_PATH)"
@$(ECHO) "SRC = $(SRC)"
@$(ECHO) "OBJ = $(OBJ)"
@$(ECHO) "OLD = $(OLD)"
@$(ECHO) "SRC_F_PATH = $(SRC_F_PATH)"
@$(ECHO) "OBJ_F_PATH = $(OBJ_F_PATH)"
@$(ECHO) "OLD_F_PATH = $(OLD_F_PATH)"
@$(ECHO)
// HSV TEST CF MILLET 2008
#include <iostream>
#include <sstream>
#include <boost/filesystem.hpp>
#include <mln/img_path.hh>
#include <mln/accu/stat/histo1d.hh>
#include <mln/arith/minus.hh>
#include <mln/arith/div.hh>
#include <mln/core/image/image1d.hh>
#include <mln/core/image/image2d.hh>
#include <mln/core/image/dmorph/image_if.hh>
#include <mln/data/convert.hh>
#include <mln/data/compute.hh>
#include <mln/data/stretch.hh>
#include <mln/data/transform.hh>
#include <mln/literal/zero.hh>
#include <mln/literal/colors.hh>
#include <mln/literal/grays.hh>
#include <mln/math/max.hh>
#include <mln/math/min.hh>
#include <mln/math/sqr.hh>
#include <mln/math/sqrt.hh>
#include <mln/opt/at.hh>
#include <mln/geom/nsites.hh>
#include <mln/fun/v2v/rgb_to_hue_map.hh>
#include <mln/fun/v2v/rgb_to_saturation_map.hh>
#include <mln/fun/v2v/rgb_to_value_map.hh>
#include <mln/io/ppm/load.hh>
#include <mln/io/pgm/save.hh>
#include <mln/io/plot/save_image_sh.hh>
#include <mln/value/rgb8.hh>
//============================================================================//
// HISTOGRAM
//============================================================================//
template <typename I>
mln_value(I) count_histo(const mln::Image<I>& histo_)
{
const I& histo = exact(histo_);
mln_precondition(histo.is_valid());
mln_value(I) result = mln::literal::zero;
mln_piter(I) p(histo.domain());
for_all(p)
result += histo(p);
return result;
}
template <typename I>
mln_value(I) sum_frequency_histo(const mln::Image<I>& histo_)
{
const I& histo = exact(histo_);
mln_precondition(histo.is_valid());
mln_value(I) sum = mln::literal::zero;
mln_piter(I) p(histo.domain());
for_all(p)
sum += histo(p);
return sum;
}
template <typename I>
mln_value(I) count_null_frequency_histo(const mln::Image<I>& histo_)
{
const I& histo = exact(histo_);
mln_precondition(histo.is_valid());
mln_value(I) count = mln::literal::zero;
mln_piter(I) p(histo.domain());
for_all(p)
if (0 == histo(p))
count++;
return count;
}
template <typename I>
mln_coord(mln_site_(I)) peak_histo(const mln::Image<I>& histo_)
{
const I& histo = exact(histo_);
mln_precondition(histo.is_valid());
// Find the peak of the histogram
mln_value(I) v_max = mln::opt::at(histo, mln::literal::zero);
mln_coord(mln_site_(I)) p_max = mln::literal::zero;
mln_piter(I) p(histo.domain());
for_all(p)
{
if (v_max < histo(p))
{
v_max = histo(p);
p_max = p.ind();
}
}
return p_max;
}
template <typename I>
mln_value(I) max_frequency_histo(const mln::Image<I>& histo_)
{
const I& histo = exact(histo_);
mln_precondition(histo.is_valid());
// Find the value of the peak from the histogram
mln_value(I) max = mln::opt::at(histo, mln::literal::zero);
mln_piter(I) p(histo.domain());
for_all(p)
{
max = mln::math::max(histo(p),max);
}
return max;
}
template <typename I>
float mean_histo(const mln::Image<I>& histo_)
{
const I& histo = exact(histo_);
mln_precondition(histo.is_valid());
// Find the mean of the histogram
float sum = 0;
float mean = 0;
mln_piter(I) p(histo.domain());
for_all(p)
{
sum += histo(p);
mean += p.ind()*histo(p);
}
mean = mean / sum;
return mean;
}
template <typename I>
float cmp_equi_frequency_histo(const mln::Image<I>& histo_)
{
const I& histo = exact(histo_);
mln_precondition(histo.is_valid());
// Find the mean of the histogram
float sum = 0;
float var = 0;
mln_piter(I) p(histo.domain());
for_all(p)
{
sum += histo(p);
var += mln::math::sqr(histo(p) - (1/256.0));
}
var = var / sum;
return var;
}
template <typename I>
float var_histo(const mln::Image<I>& histo_, float mean)
{
const I& histo = exact(histo_);
mln_precondition(histo.is_valid());
// Find the mean of the histogram
float sum = 0;
float var = 0;
mln_piter(I) p(histo.domain());
for_all(p)
{
sum += histo(p);
var += mln::math::sqr(p.ind() - mean) * histo(p);
}
var = var / sum;
return var;
}
template <typename I>
float mean_frequency_histo(const mln::Image<I>& histo_)
{
const I& histo = exact(histo_);
mln_precondition(histo.is_valid());
// Find the mean of the histogram
float sum = 0;
float mean = 0;
mln_piter(I) p(histo.domain());
for_all(p)
{
sum++;
mean += histo(p);
}
mean = mean / sum;
return mean;
}
template <typename I>
float stddev_frequency_histo(const mln::Image<I>& histo_, float mean)
{
const I& histo = exact(histo_);
mln_precondition(histo.is_valid());
// Find the var of the histogram
float sum = 0;
float var = 0;
mln_piter(I) p(histo.domain());
for_all(p)
{
sum++;
var += mln::math::sqr(histo(p)-mean);
}
var = mln::math::sqrt(var / sum);
return var;
}
//============================================================================//
// HUE TEST
//============================================================================//
mln::value::rgb8 label_val(const mln::value::int_u8 val)
{
mln::value::rgb8 result;
if (82 > val)
result = mln::literal::black;
else if (179 > val)
result= mln::literal::medium_gray;
else
result = mln::literal::white;
return result;
}
mln::value::rgb8 label_orange_or_brown(const mln::value::rgb8 color,
const mln::value::int_u8 sat,
const mln::value::int_u8 val)
{
mln::value::rgb8 result;
if (mln::literal::orange == color)
{
unsigned dist_orange = mln::math::abs(sat - 184)
+ mln::math::abs(val - 65);
unsigned dist_brown = mln::math::abs(sat - 255)
+ mln::math::abs(val - 125);
if (dist_orange < dist_brown)
result = mln::literal::orange;
else
result = mln::literal::brown;
}
else
result = color;
return result;
}
mln::value::rgb8 label_yellow_or_green(const mln::value::rgb8 color,
const mln::value::int_u8 val)
{
mln::value::rgb8 result;
if (mln::literal::yellow == color)
{
// Is it green or yellow ?
if (80 > val)
result = mln::literal::green;
else
result = mln::literal::yellow;
}
else
return color;
return result;
}
mln::value::rgb8 label_hue(const mln::value::int_u8 hue)
{
mln::value::rgb8 result;
if (10 > hue)
result = mln::literal::red;
else if (32 > hue)
result = mln::literal::orange;
else if (53 > hue)
result = mln::literal::yellow;
else if (74 > hue)
result = mln::literal::green; // chartreuse
else if (96 > hue)
result = mln::literal::green;
else if (116 > hue)
result = mln::literal::green;// turquoise, aigue-marine
else if (138 > hue)
result = mln::literal::green; // cyan
else if (159 > hue)
result = mln::literal::blue; // azur
else if (181 > hue)
result = mln::literal::blue;
else if (202 > hue)
result = mln::literal::violet;
else if (223 > hue)
result = mln::literal::pink;
else // if (244 > hue)
result = mln::literal::red;
return result;
}
float hue_test(const std::string input,
const std::string output,
const std::string tmp,
const short threshold)
{
typedef mln::fun::v2v::rgb_to_hue_map<8> t_rgb_to_hue_map;
mln::image2d<mln::value::rgb8> input_rgb8;
mln::image2d<mln::value::int_u8> map;
mln::image1d<unsigned> histo;
mln::image1d<float> histo_float;
float cnt1;
float cnt2;
float prop;
short peak;
mln::value::rgb8 color;
float sum;
mln::point1d inf;
mln::point1d sup;
mln::io::ppm::load(input_rgb8, input.c_str());
map = mln::data::transform(input_rgb8, t_rgb_to_hue_map());
histo = mln::data::compute(mln::accu::meta::stat::histo1d(), map);
sum = sum_frequency_histo(histo);
histo_float = mln::data::convert(float(), histo) / sum;
peak = mean_histo(histo); //peak_histo(histo);
color = label_hue(peak);
inf = mln::point1d(mln::math::max(0, peak-threshold));
sup = mln::point1d(mln::math::min(255, peak+threshold));
cnt1 = count_histo(histo_float|mln::box1d(inf,sup));
cnt2 = count_histo(histo_float);
prop = ((100.0 * cnt1) / cnt2);
mln::io::plot::save_image_sh(histo_float, output.c_str());
mln::io::pgm::save(map, tmp.c_str());
// std::cout << "peak = " << peak << std::endl;
// std::cout << "color = " << color << std::endl;
return prop;
}
//============================================================================//
// SATURATION TEST
//============================================================================//
float saturation_test(const std::string input,
const std::string output,
const std::string tmp,
const short threshold)
{
typedef mln::fun::v2v::rgb_to_saturation_map<8> t_rgb_to_saturation_map;
mln::image2d<mln::value::rgb8> input_rgb8;
mln::image2d<mln::value::int_u8> map;
mln::image1d<unsigned> histo;
mln::image1d<float> histo_float;
float cnt1;