Commit e9bf3efc authored by green's avatar green Committed by Yann Jacquelet
Browse files

Introduce the local deviation operator (Millet2008) which

	subdivise the image in 16 parts.

	* green/demo/annotating/stddev_color_16: New directory.
	* green/demo/annotating/stddev_color_16/Makefile.am: New Makefile.
	* green/demo/annotating/stddev_color_16/stddev_color_16.cc: New demo.
parent 26fd960b
......@@ -75,6 +75,15 @@
* bin/pgm_to_pbm.cc,
* bin/ppm_negate.cc: New.
2009-12-16 Yann Jacquelet <jacquelet@lrde.epita.fr>
Introduce the local deviation operator (Millet2008) which
subdivise the image in 16 parts.
* green/demo/annotating/stddev_color_16: New directory.
* green/demo/annotating/stddev_color_16/Makefile.am: New Makefile.
* green/demo/annotating/stddev_color_16/stddev_color_16.cc: New demo.
2009-12-16 Yann Jacquelet <jacquelet@lrde.epita.fr>
Group Millet2008 documentation files.
......
#
# Generic Makefile
#
#########
# TOOLS #
#########
INCLUDES= -I$(HOME)/svn/oln/trunk/milena/sandbox/green
#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/demo
BUILD__PATTERN= green/build/demo
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)
// COMPUTING THE STDEV OF THE COLORS
#include <iostream>
#include <sstream>
#include <mln/img_path.hh>
#include <mln/accu/max_site.hh>
#include <mln/accu/stat/histo1d.hh>
#include <mln/core/macros.hh>
#include <mln/core/image/image1d.hh>
#include <mln/core/image/image2d.hh>
#include <mln/core/image/image3d.hh>
#include <mln/debug/println.hh>
#include <mln/data/compute.hh>
#include <mln/data/fill.hh>
#include <mln/data/transform.hh>
#include <mln/data/paste.hh>
#include <mln/fun/v2v/rgb8_to_int_u8.hh>
#include <mln/io/ppm/load.hh>
#include <mln/io/pgm/save.hh>
#include <mln/io/plot/save_image_sh.hh>
#include <mln/math/sqr.hh>
#include <mln/opt/at.hh>
#include <mln/value/rgb8.hh>
#include <mln/value/int_u.hh>
float r(short p, unsigned histo_p, short x, unsigned histo_x)
{
float result = mln::math::sqr(((float)histo_x / histo_p) * (x-p));
return result;
}
unsigned stddev_color(mln::image2d<mln::value::int_u8> input_int_u8,
const char *name_histo,
const char *name_image)
{
typedef mln::point1d t_point1d;
typedef mln::value::rgb8 t_rgb8;
typedef mln::value::int_u8 t_int_u8;
typedef mln::image2d<t_rgb8> t_image2d_rgb8;
typedef mln::image2d<t_int_u8> t_image2d_int_u8;
typedef mln::image1d<unsigned> t_histo1d;
typedef mln::fun::v2v::rgb8_to_int_u8 t_rgb8_to_int_u8;
typedef mln::accu::meta::stat::histo1d t_histo1d_fun;
typedef mln::accu::max_site<t_histo1d> t_max_site_fun;
t_histo1d histo;
std::cout << "histo : " << name_histo << std::endl;
std::cout << "image : " << name_image << std::endl;
histo = mln::data::compute(t_histo1d_fun(), input_int_u8);
mln::io::pgm::save(input_int_u8, name_image);
mln::io::plot::save_image_sh(histo, name_histo);
mln::debug::println(histo);
// Find the peak of the histogram
unsigned v_max = mln::opt::at(histo, 0);
short p_max = 0;
mln_piter_(t_histo1d) p(histo.domain());
for_all(p)
{
if (v_max < histo(p))
{
v_max = histo(p);
p_max = p.ind();
}
}
// Compute the specific stddev
float stddev_low = 0.0;
float stddev_up = 0.0;
float stddev = 0.0;
if (250 > p_max)
for (short i = p_max+1; i < p_max+6; ++i)
stddev_up += r(p_max, mln::opt::at(histo,p_max),
i, mln::opt::at(histo,i));
if (5 < p_max)
for (short i = p_max-1; i > p_max-6; --i)
stddev_low += r(p_max, mln::opt::at(histo,p_max),
i, mln::opt::at(histo,i));
stddev = (250 < p_max)? stddev_low : (5 > p_max)? stddev_up :
(stddev_low + stddev_up)/2;
std::cout << "max_site : " << p_max << std::endl;
std::cout << "h(max_site) : " << v_max << std::endl;
std::cout << "stddev_up : " << stddev_up << std::endl;
std::cout << "stddev_low : " << stddev_low << std::endl;
std::cout << "stddev : " << stddev << std::endl;
return 0;
}
unsigned stddev_color_16(const std::string& image)
{
typedef mln::point1d t_point1d;
typedef mln::value::rgb8 t_rgb8;
typedef mln::value::int_u8 t_int_u8;
typedef mln::image2d<t_rgb8> t_image2d_rgb8;
typedef mln::image2d<t_int_u8> t_image2d_int_u8;
typedef mln::image1d<unsigned> t_histo1d;
typedef mln::fun::v2v::rgb8_to_int_u8 t_rgb8_to_int_u8;
typedef mln::accu::meta::stat::histo1d t_histo1d_fun;
typedef mln::accu::max_site<t_histo1d> t_max_site_fun;
t_image2d_rgb8 input_rgb8;
t_image2d_int_u8 input_int_u8;
mln::io::ppm::load(input_rgb8, image.c_str());
input_int_u8 = mln::data::transform(input_rgb8, t_rgb8_to_int_u8());
// IMAGE SPLITTING PHASE
mln::box2d domain = input_int_u8.domain();
mln::point2d pmin = domain.pmin();
mln::point2d pmax = domain.pmax();
unsigned sz_row = (pmax.row() - pmin.row())/ 4;
unsigned sz_col = (pmax.col() - pmin.col())/ 4;
std::cout << domain << std::endl;
// Divide the domain in nine sub-domains.
for (unsigned i = 0; i < 4; ++i)
for (unsigned j = 0; j < 4; ++j)
{
mln::point2d min(pmin.row()+sz_row*i,pmin.col()+sz_col*j);
mln::point2d max(pmin.row()+sz_row*(i+1),pmin.col()+sz_col*(j+1));
mln::box2d dom(min,max);
std::cout << dom << std::endl;
// Save it
t_image2d_int_u8 input_1o16_int_u8(dom);
std::ostringstream name_histo("");
std::ostringstream name_image("");
name_histo << "histo" << i << "_" << j << ".sh";
name_image << "image" << i << "_" << j << ".ppm";
mln::data::paste(input_int_u8 | dom, input_1o16_int_u8);
stddev_color(input_1o16_int_u8,
name_histo.str().c_str(),
name_image.str().c_str());
}
return 0;
}
int main()
{
// unsigned val = stddev_color_16(ANNOTATING_PHOTO_IMG_PATH "/photo01.ppm");
unsigned val = stddev_color_16(ANNOTATING_LOGO_IMG_PATH "/logo06.ppm");
// std::cout << "nb color : " << val << std::endl;
return 0;
}
Supports Markdown
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