# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%       TEXTON NOISE       %%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%         READ ME          %%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# This file explains how to visualize the texton noise associated to an exemplar texture.

# Please set the directories accordingly to your system:
mdir=~/research/texton_noise_sup_mat/codes/compute_texton
odir=~/research/texton_noise_sup_mat/codes/display_texton_noise

# New exemplar textures can be added in the folder $mdir/input_textures that already contains all the input textures of the paper.

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%      COMPILATION      %%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# The code is for Linux only and requires standard libraries for the links libglut, libglew, libX11, libpng.
cd $odir/
make

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%  TEST USER INTERFACE  %%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

cd $odir/bin
./texton_noise_2d

# You can try with any of the .texton files included in $odir/input with the -t option, e.g.
cd $odir/bin
./texton_noise_2d -t ../input/PaperDecorative0048_2_thumbhuge_128_s64.texton 

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%      ANALYSIS      %%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%

# One can compute all the textons associated to the exemplar textures of the directory $mdir/input_textures by running the Matlab script
# $mdir/scr_compute_textons.m

# You can do it directly in a Unix terminal with
matlab -nojvm < $mdir/scr_compute_all_textons.m > $mdir/log_scr_compute_all_textons.txt 2>&1

# If you want to compute the texton associated to one specific exemplar texture, run the following command in a Unix terminal
name=paint_2005
cd $mdir
outputtxt="output_textons/${name}_output.txt"
matlabcmd="tn_compute_texton('input_textures/"$name".png','output_textons');"
matlab -nojvm -r  $matlabcmd 1>$outputtxt

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%      SYNTHESIS      %%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# Run the openGL program to visualize the corresponding texton noise
	
# Copy all the textons in the OpenGL directory
cp $mdir/output_textons/*.texton $odir/input/

# Choose a texton (in the directory $odir/input/ ) e.g.
texton=IMG_7406_s128.texton

# Visualize the corresponding texton noise in 3D
cd $odir/bin
./texton_noise_2d -t ../input/$texton

# Visualize the corresponding texton noise in 2D
cd $odir/bin
./texton_noise_flat -t ../input/$texton


