Commit 1548ee09 authored by Yann Jacquelet's avatar Yann Jacquelet
Browse files

Work on the rgb version of kmean.

	* green/mln/clustering/kmean3d.hh: New library code.

	* green/demo/clustering/kmean3d: New directory.
	* green/demo/clustering/kmean3d/Makefile.am: New makefile.
	* green/demo/clustering/kmean3d/kmean3d.cc: New demo code.

git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@4616 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 0af4017b
2009-10-07 Yann Jacquelet <jacquelet@lrde.epita.fr>
Work on the rgb version of kmean.
* green/mln/clustering/kmean3d.hh: New library code.
* green/demo/clustering/kmean3d: New directory.
* green/demo/clustering/kmean3d/Makefile.am: New makefile.
* green/demo/clustering/kmean3d/kmean3d.cc: New demo code.
2009-10-07 Yann Jacquelet <jacquelet@lrde.epita.fr>
Put a bug into light in mean_values.hh
......
#
# Generic Makefile
#
#########
# TOOLS #
#########
INCLUDES= -I$(HOME)/svn/oln/trunk/milena/sandbox/green
CXXFLAGS= -ggdb -O0 -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)
// DEMO ON KMEAN3D
#include <mln/clustering/kmean3d.hh>
#include <iostream>
#include <sstream>
#include <mln/img_path.hh>
#include <mln/pw/value.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/label_8.hh>
#include <mln/value/rgb8.hh>
#include <mln/core/macros.hh>
#include <mln/core/image/image2d.hh>
#include <mln/core/image/dmorph/image_if.hh>
#include <mln/data/transform.hh>
#include <mln/fun/v2v/rgb8_to_rgbn.hh>
#include <mln/io/ppm/load.hh>
#include <mln/io/pgm/load.hh>
#include <mln/io/pgm/save.hh>
#include <mln/io/ppm/save.hh>
#include <mln/io/plot/save_image_sh.hh>
void do_demo(const std::string& image,
const unsigned k_center,
const unsigned n_times,
const unsigned watch_dog)
{
typedef mln::clustering::kmean3d<double,5> t_kmean;
typedef mln::value::label_8 t_label_8;
typedef mln::value::rgb8 t_rgb8;
typedef mln::value::rgb<5> t_rgb5;
typedef mln::image2d<t_rgb8> t_image2d_rgb8;
typedef mln::image2d<t_rgb5> t_image2d_rgb5;
t_image2d_rgb8 house_rgb8;
t_image2d_rgb5 house_rgb5;
mln::io::ppm::load(house_rgb8, image.c_str());
house_rgb5=mln::data::transform(house_rgb8,mln::fun::v2v::rgb8_to_rgbn<5>());
t_kmean kmean(house_rgb5, k_center, watch_dog, n_times);
mln::trace::quiet = false;
//kmean.launch_one_time();
kmean.launch_n_times();
// Not safe because we don't test kmean.is_valid()
// Pb à la création des images de debug.
t_kmean::t_color_dbg color_img = kmean.get_color_dbg();
t_kmean::t_mean_dbg mean_img = kmean.get_mean_dbg();
t_kmean::t_label_dbg label_img = kmean.get_label_dbg();
t_kmean::t_variance_cnv variance_cnv = kmean.get_variance_cnv();
t_kmean::t_mean_cnv mean_cnv = kmean.get_mean_cnv();
mln::io::ppm::save(mean_img, "mean.ppm");
mln::io::ppm::save(color_img, "color.ppm");
mln::io::pgm::save(label_img, "label.pgm");
mln::io::plot::save_image_sh(mean_cnv, "mean_cnv.sh");
mln::io::plot::save_image_sh(variance_cnv, "variance_cnv.sh");
}
void demo(const std::string& image = OLENA_IMG_PATH"/house.ppm",
const unsigned k_center = 3,
const unsigned n_times = 10,
const unsigned watch_dog = 10)
{
std::cout << "----------------------------------------" << std::endl;
std::cout << "Launching the demo with these parameters" << std::endl;
std::cout << "image : " << image << std::endl;
std::cout << "k_center : " << k_center << std::endl;
std::cout << "n_times : " << n_times << std::endl;
std::cout << "watch_dog : " << watch_dog << std::endl;
std::cout << "----------------------------------------" << std::endl;
do_demo(image, k_center, n_times, watch_dog);
}
void usage(const int argc, const char *args[])
{
std::cout << "----------------------------------------" << std::endl;
std::cout << "argc : " << argc << std::endl;
for (int i = 0; i < argc; ++i)
std::cout << "args[" << i << "] : " << args[i] << std::endl;
std::cout << "----------------------------------------" << std::endl;
std::cout << "usage: kmean1d [image [k_center [n_times [watch_dog]]]]"
<< std::endl;
std::cout << "pbm image (points to work with)" << std::endl;
std::cout << "unsigned k_center (number of centers)" << std::endl;
std::cout << "unsigned n_times (number of launching)" << std::endl;
std::cout << "unsigned watch_dog (convergence loop)" << std::endl;
std::cout << "----------------------------------------" << std::endl;
}
bool char_to_unsigned(const bool status, const char *arg, unsigned& val)
{
bool result = false;
if (status)
{
std::istringstream arg_stream(arg);
arg_stream >> val;
result = !arg_stream.fail();
}
return result;
}
bool char_to_string(const bool status, const char *arg, std::string& val)
{
bool result = false;
if (status)
{
std::istringstream arg_stream(arg);
arg_stream >> val;
return !arg_stream.fail();
}
return result;
}
int main(const int argc, const char *args[])
{
std::string image("top");
unsigned k_center;
unsigned watch_dog;
unsigned n_times;
bool status = true;
switch (argc)
{
case 5: status = char_to_unsigned(status, args[4], watch_dog);
case 4: status = char_to_unsigned(status, args[3], n_times);
case 3: status = char_to_unsigned(status, args[2], k_center);
case 2: status = char_to_string(status, args[1], image); break;
case 1: status = true; break;
default: status = false;
}
if (status)
{
switch (argc)
{
case 1: demo(); break;
case 2: demo(image); break;
case 3: demo(image, k_center); break;
case 4: demo(image, k_center, n_times); break;
case 5: demo(image, k_center, n_times, watch_dog); break;
}
}
else
usage(argc, args);
return 0;
}
This diff is collapsed.
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