Просмотр исходного кода

* Put the initial (Feb 08) version of the ED displacement paper into SVN, as

well as the associated C source code. Both will require huge cleanup for a
    final release.


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/research@2273 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 16 лет назад
Родитель
Сommit
d51b4a6225
21 измененных файлов: 100940 добавлений и 0 удалений
  1. +6
    -0
      2008-displacement/.gitignore
  2. +17
    -0
      2008-displacement/Makefile
  3. +191
    -0
      2008-displacement/README
  4. +1842
    -0
      2008-displacement/direction.tex
  5. +15203
    -0
      2008-displacement/fs-histo.eps
  6. +431
    -0
      2008-displacement/fs-histo.tex
  7. +16820
    -0
      2008-displacement/jajuni-histo.eps
  8. +388
    -0
      2008-displacement/jajuni-histo.tex
  9. +12535
    -0
      2008-displacement/lena-min.eps
  10. +139
    -0
      2008-displacement/lena-min.tex
  11. +1191
    -0
      2008-displacement/lena.eps
  12. +1190
    -0
      2008-displacement/llncs.cls
  13. +792
    -0
      2008-displacement/main.c
  14. +14509
    -0
      2008-displacement/optimum-histo.eps
  15. +388
    -0
      2008-displacement/optimum-histo.tex
  16. +16956
    -0
      2008-displacement/ostro-histo.eps
  17. +488
    -0
      2008-displacement/ostro-histo.tex
  18. +486
    -0
      2008-displacement/paper.tex
  19. +16904
    -0
      2008-displacement/serpopt-histo.eps
  20. +423
    -0
      2008-displacement/serpopt-histo.tex
  21. +41
    -0
      2008-displacement/xy2d.c

+ 6
- 0
2008-displacement/.gitignore Просмотреть файл

@@ -0,0 +1,6 @@
main
*.aux
*.dvi
*.log
*.pdf
xy2d

+ 17
- 0
2008-displacement/Makefile Просмотреть файл

@@ -0,0 +1,17 @@
all: main xy2d paper.pdf

xy2d: xy2d.c
$(CC) -W -Wall $^ -o $@

main: main.c
$(CC) -Wall -O3 -funroll-loops -W -Wall $^ -o $@ $$(pkg-config --cflags --libs sdl) -lSDL_image -lm

paper.pdf: paper.tex fs-histo.tex
latex paper.tex
latex paper.tex
dvipdf paper.dvi

clean:
rm -f paper.log paper.dvi paper.aux paper.pdf
rm -f xy2d main


+ 191
- 0
2008-displacement/README Просмотреть файл

@@ -0,0 +1,191 @@
# Trouver des images au pif
% find ~/4chan/unsorted-4chan/http* -name '1[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].??g' | rev | sort -k2 -t. | rev | xargs -n 1 ./main | tee fs-4chan.txt
% find ~/4chan/unsorted-4chan/http* -name '1[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].??g' | rev | sort -k2 -t. | rev | xargs -n 1 ./main-jajuni | tee jajuni-4chan.txt
% cat /tmp/4chanlist.txt | xargs -n 1 ./main | tee -a fs-4chan.txt

# Lena
set hidden3d
set grid
unset colorbox
splot "lena-min.txt" with lines lc 7 notitle
set terminal epslatex color size 2.5,2 blacktext
set tmargin screen 0.75
set bmargin screen 0.25
set lmargin screen 0.05
set rmargin screen 0.95
set output "lena-min.tex"
splot "lena-min.txt" with lines lc 7 notitle
unset output
set term pop

# Dans gnuplot
set xrange [-.1:.4]
set yrange [.45:-.05]
set grid
plot "fs-4chan.txt" using 6:7 lc 1 pt 7 ps .08 title "4chan", \
"fs-tobefred.txt" using 6:7 lc 3 pt 7 ps .08 title "tobefred", \
"fs-uscsipi.txt" using 6:7 lc 2 pt 7 ps .08 title "USC-SIPI", \
"fs-jylam.txt" using 6:7 lc 4 pt 7 ps .08 title "Jylam", \
"merge.txt" using 5:6 lc 7 ps .2 with lines
#plot "fs-textures.txt" using 6:7 lc 3 pt 7 ps .2, "fs-aerials.txt" using 6:7 lc 3 pt 7 ps .2, "fs-misc.txt" using 6:7 lc 7 pt 7 ps .2, "fs-4chan.txt" using 6:7 lc 1 pt 7 ps .2

# Histogramme de la tache Floyd-Steinberg
sed -ne 's/.* for //p' fs-*txt | ./xy2d >| histo-fs.txt
# Et ensuite dans gnuplot:
set xrange [-.1:.4]
set yrange [.4:-.1]
set grid
set lmargin screen 0.05
set bmargin screen 0.15
set tmargin screen 0.95
set rmargin screen 0.95
unset colorbox
set pm3d explicit map interpolate 1.8,1.8
set palette model RGB defined(0 "white", 1 "blue", 2 "red", 3 "yellow")
unset key
#splot "histo-fs.txt" notitle
set terminal epslatex color size 1.8,1.8 blacktext
set output "fs-histo.tex"
splot "histo-fs.txt" notitle
unset output
set term pop

set xrange [-.1:.9]
set yrange [.95:-.05]
set grid
plot "jajuni-4chan.txt" using 6:7 lc 1 pt 7 ps .08 title "4chan", \
"jajuni-tobefred.txt" using 6:7 lc 3 pt 7 ps .08 title "tobefred", \
"jajuni-uscsipi.txt" using 6:7 lc 2 pt 7 ps .08 title "USC-SIPI"

# Histogramme de la tache JaJuNi
sed -ne 's/.* for //p' jajuni*txt | ./xy2d-jajuni >| histo-jajuni.txt
# Et ensuite dans gnuplot:
set xrange [-.1:.9]
set yrange [.9:-.1]
set grid
set lmargin screen 0.05
set bmargin screen 0.15
set tmargin screen 0.95
set rmargin screen 0.95
unset colorbox
set pm3d explicit map interpolate 1.8,1.8
set palette model RGB defined(0 "white", 1 "blue", 2 "red", 3 "yellow")
unset key
#splot "histo-jajuni.txt" notitle
set terminal epslatex color size 1.8,1.8 blacktext
set output "jajuni-histo.tex"
splot "histo-jajuni.txt" notitle
unset output
set term pop

# Test de merde
set xrange [0:5]
set yrange [0:5]
set grid
plot "fs-uscsipi.txt" using 2:4 lc 1 pt 7 ps .5, "fs-4chan.txt" using 2:4 lc 7 pt 7 ps .5, "fs-tobefred.txt" using 2:4 lc 3 pt 7 ps .5

# Ostromoukhov
set xrange [-.2:.2]
set yrange [.3:-.1]
set grid
plot "ostro-4chan.txt" using 6:7 lc 1 pt 7 ps .08 title "4chan", \
"ostro-tobefred.txt" using 6:7 lc 3 pt 7 ps .08 title "tobefred", \
"ostro-uscsipi.txt" using 6:7 lc 2 pt 7 ps .08 title "USC-SIPI"

# Histogramme de la tache Ostro
sed -ne 's/.* for //p' ostro*txt | ./xy2d-ostro >| histo-ostro.txt
# Et ensuite dans gnuplot:
set xrange [-.2:.2]
set yrange [.3:-.1]
set grid
set lmargin screen 0.05
set bmargin screen 0.15
set tmargin screen 0.95
set rmargin screen 0.95
unset colorbox
set pm3d explicit map interpolate 1.8,1.8
set palette model RGB defined(0 "white", 1 "blue", 2 "red", 3 "yellow")
unset key
splot "histo-ostro.txt" notitle
set terminal epslatex color size 1.8,1.8 blacktext
set output "ostro-histo.tex"
splot "histo-ostro.txt" notitle
unset output
set term pop

# Optimum
set xrange [-.5:.2]
set yrange [.6:-.1]
set grid
plot "optimum-4chan.txt" using 6:7 lc 1 pt 7 ps .08 title "4chan", \
"optimum-tobefred.txt" using 6:7 lc 3 pt 7 ps .08 title "tobefred", \
"optimum-uscsipi.txt" using 6:7 lc 2 pt 7 ps .08 title "USC-SIPI"

# Histogramme de la tache Optimum
sed -ne 's/.* for //p' optimum*txt | ./xy2d-optimum >| histo-optimum.txt
# Et ensuite dans gnuplot:
set xrange [-.5:.2]
set yrange [.6:-.1]
set grid
set lmargin screen 0.05
set bmargin screen 0.15
set tmargin screen 0.95
set rmargin screen 0.95
unset colorbox
set pm3d explicit map interpolate 1.8,1.8
set palette model RGB defined(0 "white", 1 "blue", 2 "red", 3 "yellow")
unset key
splot "histo-optimum.txt" notitle
set terminal epslatex color size 1.8,1.8 blacktext
set output "optimum-histo.tex"
splot "histo-optimum.txt" notitle
unset output
set term pop

# Serpentine Optimum
set xrange [-.3:.3]
set yrange [.5:-.1]
set grid
plot "serpopt-4chan.txt" using 6:7 lc 1 pt 7 ps .08 title "4chan", \
"serpopt-tobefred.txt" using 6:7 lc 3 pt 7 ps .08 title "tobefred", \
"serpopt-uscsipi.txt" using 6:7 lc 2 pt 7 ps .08 title "USC-SIPI"

# Histogramme de la tache Serpentine Optimum
sed -ne 's/.* for //p' serpopt*txt | ./xy2d-serpopt >| histo-serpopt.txt
# Et ensuite dans gnuplot:
set xrange [-.3:.3]
set yrange [.6:-.1]
set grid
set lmargin screen 0.05
set bmargin screen 0.15
set tmargin screen 0.95
set rmargin screen 0.95
unset colorbox
set pm3d explicit map interpolate 1.8,1.8
set palette model RGB defined(0 "white", 1 "blue", 2 "red", 3 "yellow")
unset key
splot "histo-serpopt.txt" notitle
set terminal epslatex color size 1.8,1.8 blacktext
set output "serpopt-histo.tex"
splot "histo-serpopt.txt" notitle
unset output
set term pop

# Combinaison jajuni / floyd-steinberg
set xrange [-.1:.4]
set yrange [.9:-.1]
set grid
plot "fs-4chan.txt" using 6:7 lc 2 pt 7 ps .1 title "Floyd-Steinberg", "jajuni-tobefred.txt" using 6:7 lc 1 pt 7 ps .1 title "Jarvis-Judice-Ninke"

######################## Trucs en cours ########################

# Lancés sur canard:
boat.png elaine.png texture[2345].png

# Lancés sur poulet :
./main /var/www/net/tobefred/www/htdocs/media/romane_bohringer.jpg | tee out-bohringer.txt ; ./main /var/www/net/tobefred/www/htdocs/media/juliette_binoche_05.jpg | tee out-binoche.txt ; ./main /var/www/net/tobefred/www/htdocs/media/kate_beckinsale02.jpg | tee out-beckinsale.txt

#### Pour les out-*
scp canard.zoy.org:out-'*'.txt .
for x in out-*.txt; do sort -k7 $x | head -20 ; done | cut -f1 -d: | sort | uniq -c | sort -n


+ 1842
- 0
2008-displacement/direction.tex
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 15203
- 0
2008-displacement/fs-histo.eps
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 431
- 0
2008-displacement/fs-histo.tex Просмотреть файл

@@ -0,0 +1,431 @@
% GNUPLOT: LaTeX picture with Postscript
\begingroup
\makeatletter
\providecommand\color[2][]{%
\GenericError{(gnuplot) \space\space\space\@spaces}{%
Package color not loaded in conjunction with
terminal option `colourtext'%
}{See the gnuplot documentation for explanation.%
}{Either use 'blacktext' in gnuplot or load the package
color.sty in LaTeX.}%
\renewcommand\color[2][]{}%
}%
\providecommand\includegraphics[2][]{%
\GenericError{(gnuplot) \space\space\space\@spaces}{%
Package graphicx or graphics not loaded%
}{See the gnuplot documentation for explanation.%
}{The gnuplot epslatex terminal needs graphicx.sty or graphics.sty.}%
\renewcommand\includegraphics[2][]{}%
}%
\providecommand\rotatebox[2]{#2}%
\@ifundefined{ifGPcolor}{%
\newif\ifGPcolor
\GPcolortrue
}{}%
\@ifundefined{ifGPblacktext}{%
\newif\ifGPblacktext
\GPblacktexttrue
}{}%
% define a \g@addto@macro without @ in the name:
\let\gplgaddtomacro\g@addto@macro
% define empty templates for all commands taking text:
\gdef\gplbacktext{}%
\gdef\gplfronttext{}%
\makeatother
\ifGPblacktext
% no textcolor at all
\def\colorrgb#1{}%
\def\colorgray#1{}%
\else
% gray or color?
\ifGPcolor
\def\colorrgb#1{\color[rgb]{#1}}%
\def\colorgray#1{\color[gray]{#1}}%
\expandafter\def\csname LTw\endcsname{\color{white}}%
\expandafter\def\csname LTb\endcsname{\color{black}}%
\expandafter\def\csname LTa\endcsname{\color{black}}%
\expandafter\def\csname LT0\endcsname{\color[rgb]{1,0,0}}%
\expandafter\def\csname LT1\endcsname{\color[rgb]{0,1,0}}%
\expandafter\def\csname LT2\endcsname{\color[rgb]{0,0,1}}%
\expandafter\def\csname LT3\endcsname{\color[rgb]{1,0,1}}%
\expandafter\def\csname LT4\endcsname{\color[rgb]{0,1,1}}%
\expandafter\def\csname LT5\endcsname{\color[rgb]{1,1,0}}%
\expandafter\def\csname LT6\endcsname{\color[rgb]{0,0,0}}%
\expandafter\def\csname LT7\endcsname{\color[rgb]{1,0.3,0}}%
\expandafter\def\csname LT8\endcsname{\color[rgb]{0.5,0.5,0.5}}%
\else
% gray
\def\colorrgb#1{\color{black}}%
\def\colorgray#1{\color[gray]{#1}}%
\expandafter\def\csname LTw\endcsname{\color{white}}%
\expandafter\def\csname LTb\endcsname{\color{black}}%
\expandafter\def\csname LTa\endcsname{\color{black}}%
\expandafter\def\csname LT0\endcsname{\color{black}}%
\expandafter\def\csname LT1\endcsname{\color{black}}%
\expandafter\def\csname LT2\endcsname{\color{black}}%
\expandafter\def\csname LT3\endcsname{\color{black}}%
\expandafter\def\csname LT4\endcsname{\color{black}}%
\expandafter\def\csname LT5\endcsname{\color{black}}%
\expandafter\def\csname LT6\endcsname{\color{black}}%
\expandafter\def\csname LT7\endcsname{\color{black}}%
\expandafter\def\csname LT8\endcsname{\color{black}}%
\fi
\fi
\setlength{\unitlength}{0.0500bp}%
\begin{picture}(2590.00,2590.00)%
\gplgaddtomacro\gplbacktext{%
}%
\gplgaddtomacro\gplfronttext{%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\csname LTb\endcsname%
\put(130,104){\makebox(0,0){\strut{}-0.1}}%
\csname LTb\endcsname%
\put(596,104){\makebox(0,0){\strut{} 0}}%
\csname LTb\endcsname%
\put(1062,104){\makebox(0,0){\strut{} 0.1}}%
\csname LTb\endcsname%
\put(1528,104){\makebox(0,0){\strut{} 0.2}}%
\csname LTb\endcsname%
\put(1994,104){\makebox(0,0){\strut{} 0.3}}%
\csname LTb\endcsname%
\put(2460,104){\makebox(0,0){\strut{} 0.4}}%
\csname LTb\endcsname%
\put(-42,2460){\makebox(0,0)[r]{\strut{}-0.1}}%
\csname LTb\endcsname%
\put(-42,2046){\makebox(0,0)[r]{\strut{} 0}}%
\csname LTb\endcsname%
\put(-42,1632){\makebox(0,0)[r]{\strut{} 0.1}}%
\csname LTb\endcsname%
\put(-42,1218){\makebox(0,0)[r]{\strut{} 0.2}}%
\csname LTb\endcsname%
\put(-42,804){\makebox(0,0)[r]{\strut{} 0.3}}%
\csname LTb\endcsname%
\put(-42,390){\makebox(0,0)[r]{\strut{} 0.4}}%
}%
\gplbacktext
\put(0,0){\includegraphics{fs-histo}}%
\gplfronttext
\end{picture}%
\endgroup

+ 16820
- 0
2008-displacement/jajuni-histo.eps
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 388
- 0
2008-displacement/jajuni-histo.tex Просмотреть файл

@@ -0,0 +1,388 @@
% GNUPLOT: LaTeX picture with Postscript
\begingroup
\makeatletter
\providecommand\color[2][]{%
\GenericError{(gnuplot) \space\space\space\@spaces}{%
Package color not loaded in conjunction with
terminal option `colourtext'%
}{See the gnuplot documentation for explanation.%
}{Either use 'blacktext' in gnuplot or load the package
color.sty in LaTeX.}%
\renewcommand\color[2][]{}%
}%
\providecommand\includegraphics[2][]{%
\GenericError{(gnuplot) \space\space\space\@spaces}{%
Package graphicx or graphics not loaded%
}{See the gnuplot documentation for explanation.%
}{The gnuplot epslatex terminal needs graphicx.sty or graphics.sty.}%
\renewcommand\includegraphics[2][]{}%
}%
\providecommand\rotatebox[2]{#2}%
\@ifundefined{ifGPcolor}{%
\newif\ifGPcolor
\GPcolortrue
}{}%
\@ifundefined{ifGPblacktext}{%
\newif\ifGPblacktext
\GPblacktexttrue
}{}%
% define a \g@addto@macro without @ in the name:
\let\gplgaddtomacro\g@addto@macro
% define empty templates for all commands taking text:
\gdef\gplbacktext{}%
\gdef\gplfronttext{}%
\makeatother
\ifGPblacktext
% no textcolor at all
\def\colorrgb#1{}%
\def\colorgray#1{}%
\else
% gray or color?
\ifGPcolor
\def\colorrgb#1{\color[rgb]{#1}}%
\def\colorgray#1{\color[gray]{#1}}%
\expandafter\def\csname LTw\endcsname{\color{white}}%
\expandafter\def\csname LTb\endcsname{\color{black}}%
\expandafter\def\csname LTa\endcsname{\color{black}}%
\expandafter\def\csname LT0\endcsname{\color[rgb]{1,0,0}}%
\expandafter\def\csname LT1\endcsname{\color[rgb]{0,1,0}}%
\expandafter\def\csname LT2\endcsname{\color[rgb]{0,0,1}}%
\expandafter\def\csname LT3\endcsname{\color[rgb]{1,0,1}}%
\expandafter\def\csname LT4\endcsname{\color[rgb]{0,1,1}}%
\expandafter\def\csname LT5\endcsname{\color[rgb]{1,1,0}}%
\expandafter\def\csname LT6\endcsname{\color[rgb]{0,0,0}}%
\expandafter\def\csname LT7\endcsname{\color[rgb]{1,0.3,0}}%
\expandafter\def\csname LT8\endcsname{\color[rgb]{0.5,0.5,0.5}}%
\else
% gray
\def\colorrgb#1{\color{black}}%
\def\colorgray#1{\color[gray]{#1}}%
\expandafter\def\csname LTw\endcsname{\color{white}}%
\expandafter\def\csname LTb\endcsname{\color{black}}%
\expandafter\def\csname LTa\endcsname{\color{black}}%
\expandafter\def\csname LT0\endcsname{\color{black}}%
\expandafter\def\csname LT1\endcsname{\color{black}}%
\expandafter\def\csname LT2\endcsname{\color{black}}%
\expandafter\def\csname LT3\endcsname{\color{black}}%
\expandafter\def\csname LT4\endcsname{\color{black}}%
\expandafter\def\csname LT5\endcsname{\color{black}}%
\expandafter\def\csname LT6\endcsname{\color{black}}%
\expandafter\def\csname LT7\endcsname{\color{black}}%
\expandafter\def\csname LT8\endcsname{\color{black}}%
\fi
\fi
\setlength{\unitlength}{0.0500bp}%
\begin{picture}(2590.00,2590.00)%
\gplgaddtomacro\gplbacktext{%
}%
\gplgaddtomacro\gplfronttext{%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\csname LTb\endcsname%
\put(363,104){\makebox(0,0){\strut{} 0}}%
\csname LTb\endcsname%
\put(829,104){\makebox(0,0){\strut{} 0.2}}%
\csname LTb\endcsname%
\put(1295,104){\makebox(0,0){\strut{} 0.4}}%
\csname LTb\endcsname%
\put(1761,104){\makebox(0,0){\strut{} 0.6}}%
\csname LTb\endcsname%
\put(2227,104){\makebox(0,0){\strut{} 0.8}}%
\csname LTb\endcsname%
\put(-42,2253){\makebox(0,0)[r]{\strut{} 0}}%
\csname LTb\endcsname%
\put(-42,1839){\makebox(0,0)[r]{\strut{} 0.2}}%
\csname LTb\endcsname%
\put(-42,1425){\makebox(0,0)[r]{\strut{} 0.4}}%
\csname LTb\endcsname%
\put(-42,1011){\makebox(0,0)[r]{\strut{} 0.6}}%
\csname LTb\endcsname%
\put(-42,597){\makebox(0,0)[r]{\strut{} 0.8}}%
}%
\gplbacktext
\put(0,0){\includegraphics{jajuni-histo}}%
\gplfronttext
\end{picture}%
\endgroup

+ 12535
- 0
2008-displacement/lena-min.eps
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 139
- 0
2008-displacement/lena-min.tex Просмотреть файл

@@ -0,0 +1,139 @@
% GNUPLOT: LaTeX picture with Postscript
\begingroup
\makeatletter
\providecommand\color[2][]{%
\GenericError{(gnuplot) \space\space\space\@spaces}{%
Package color not loaded in conjunction with
terminal option `colourtext'%
}{See the gnuplot documentation for explanation.%
}{Either use 'blacktext' in gnuplot or load the package
color.sty in LaTeX.}%
\renewcommand\color[2][]{}%
}%
\providecommand\includegraphics[2][]{%
\GenericError{(gnuplot) \space\space\space\@spaces}{%
Package graphicx or graphics not loaded%
}{See the gnuplot documentation for explanation.%
}{The gnuplot epslatex terminal needs graphicx.sty or graphics.sty.}%
\renewcommand\includegraphics[2][]{}%
}%
\providecommand\rotatebox[2]{#2}%
\@ifundefined{ifGPcolor}{%
\newif\ifGPcolor
\GPcolortrue
}{}%
\@ifundefined{ifGPblacktext}{%
\newif\ifGPblacktext
\GPblacktexttrue
}{}%
% define a \g@addto@macro without @ in the name:
\let\gplgaddtomacro\g@addto@macro
% define empty templates for all commands taking text:
\gdef\gplbacktext{}%
\gdef\gplfronttext{}%
\makeatother
\ifGPblacktext
% no textcolor at all
\def\colorrgb#1{}%
\def\colorgray#1{}%
\else
% gray or color?
\ifGPcolor
\def\colorrgb#1{\color[rgb]{#1}}%
\def\colorgray#1{\color[gray]{#1}}%
\expandafter\def\csname LTw\endcsname{\color{white}}%
\expandafter\def\csname LTb\endcsname{\color{black}}%
\expandafter\def\csname LTa\endcsname{\color{black}}%
\expandafter\def\csname LT0\endcsname{\color[rgb]{1,0,0}}%
\expandafter\def\csname LT1\endcsname{\color[rgb]{0,1,0}}%
\expandafter\def\csname LT2\endcsname{\color[rgb]{0,0,1}}%
\expandafter\def\csname LT3\endcsname{\color[rgb]{1,0,1}}%
\expandafter\def\csname LT4\endcsname{\color[rgb]{0,1,1}}%
\expandafter\def\csname LT5\endcsname{\color[rgb]{1,1,0}}%
\expandafter\def\csname LT6\endcsname{\color[rgb]{0,0,0}}%
\expandafter\def\csname LT7\endcsname{\color[rgb]{1,0.3,0}}%
\expandafter\def\csname LT8\endcsname{\color[rgb]{0.5,0.5,0.5}}%
\else
% gray
\def\colorrgb#1{\color{black}}%
\def\colorgray#1{\color[gray]{#1}}%
\expandafter\def\csname LTw\endcsname{\color{white}}%
\expandafter\def\csname LTb\endcsname{\color{black}}%
\expandafter\def\csname LTa\endcsname{\color{black}}%
\expandafter\def\csname LT0\endcsname{\color{black}}%
\expandafter\def\csname LT1\endcsname{\color{black}}%
\expandafter\def\csname LT2\endcsname{\color{black}}%
\expandafter\def\csname LT3\endcsname{\color{black}}%
\expandafter\def\csname LT4\endcsname{\color{black}}%
\expandafter\def\csname LT5\endcsname{\color{black}}%
\expandafter\def\csname LT6\endcsname{\color{black}}%
\expandafter\def\csname LT7\endcsname{\color{black}}%
\expandafter\def\csname LT8\endcsname{\color{black}}%
\fi
\fi
\setlength{\unitlength}{0.0500bp}%
\begin{picture}(3600.00,2880.00)%
\gplgaddtomacro\gplbacktext{%
}%
\gplgaddtomacro\gplfronttext{%
\csname LTb\endcsname%
\put(-695,944){\makebox(0,0)[r]{\strut{}-1}}%
\csname LTb\endcsname%
\put(-513,866){\makebox(0,0)[r]{\strut{}-0.8}}%
\csname LTb\endcsname%
\put(-332,787){\makebox(0,0)[r]{\strut{}-0.6}}%
\csname LTb\endcsname%
\put(-151,709){\makebox(0,0)[r]{\strut{}-0.4}}%
\csname LTb\endcsname%
\put(30,631){\makebox(0,0)[r]{\strut{}-0.2}}%
\csname LTb\endcsname%
\put(211,552){\makebox(0,0)[r]{\strut{} 0}}%
\csname LTb\endcsname%
\put(392,474){\makebox(0,0)[r]{\strut{} 0.2}}%
\csname LTb\endcsname%
\put(574,396){\makebox(0,0)[r]{\strut{} 0.4}}%
\csname LTb\endcsname%
\put(755,317){\makebox(0,0)[r]{\strut{} 0.6}}%
\csname LTb\endcsname%
\put(936,239){\makebox(0,0)[r]{\strut{} 0.8}}%
\csname LTb\endcsname%
\put(1117,161){\makebox(0,0)[r]{\strut{} 1}}%
\csname LTb\endcsname%
\put(1437,188){\makebox(0,0){\strut{}-1}}%
\csname LTb\endcsname%
\put(1706,241){\makebox(0,0){\strut{}-0.8}}%
\csname LTb\endcsname%
\put(1973,294){\makebox(0,0){\strut{}-0.6}}%
\csname LTb\endcsname%
\put(2242,347){\makebox(0,0){\strut{}-0.4}}%
\csname LTb\endcsname%
\put(2511,399){\makebox(0,0){\strut{}-0.2}}%
\csname LTb\endcsname%
\put(2779,452){\makebox(0,0){\strut{} 0}}%
\csname LTb\endcsname%
\put(3048,505){\makebox(0,0){\strut{} 0.2}}%
\csname LTb\endcsname%
\put(3316,558){\makebox(0,0){\strut{} 0.4}}%
\csname LTb\endcsname%
\put(3585,611){\makebox(0,0){\strut{} 0.6}}%
\csname LTb\endcsname%
\put(3854,664){\makebox(0,0){\strut{} 0.8}}%
\csname LTb\endcsname%
\put(4122,716){\makebox(0,0){\strut{} 1}}%
\put(-574,1554){\makebox(0,0)[r]{\strut{} 0.2}}%
\put(-574,1660){\makebox(0,0)[r]{\strut{} 0.4}}%
\put(-574,1766){\makebox(0,0)[r]{\strut{} 0.6}}%
\put(-574,1872){\makebox(0,0)[r]{\strut{} 0.8}}%
\put(-574,1978){\makebox(0,0)[r]{\strut{} 1}}%
\put(-574,2084){\makebox(0,0)[r]{\strut{} 1.2}}%
\put(-574,2190){\makebox(0,0)[r]{\strut{} 1.4}}%
\put(-574,2296){\makebox(0,0)[r]{\strut{} 1.6}}%
\put(-574,2402){\makebox(0,0)[r]{\strut{} 1.8}}%
\put(-574,2508){\makebox(0,0)[r]{\strut{} 2}}%
\put(-574,2614){\makebox(0,0)[r]{\strut{} 2.2}}%
}%
\gplbacktext
\put(0,0){\includegraphics{lena-min}}%
\gplfronttext
\end{picture}%
\endgroup

+ 1191
- 0
2008-displacement/lena.eps
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 1190
- 0
2008-displacement/llncs.cls
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 792
- 0
2008-displacement/main.c Просмотреть файл

@@ -0,0 +1,792 @@
/* test shit */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>

#include <math.h>

#include <SDL_image.h>

#define MAXWIDTH 512
#define MAXHEIGHT 512

#define true 1
#define false 0

int WIDTH, HEIGHT;

static inline float get(float *src, int x, int y)
{
return src[y * WIDTH + x];
}

static inline void put(float *src, int x, int y, float p)
{
src[y * WIDTH + x] = p;
}

static float *new(void)
{
return malloc(WIDTH * HEIGHT * sizeof(float));
}

static float *copy(float *src)
{
float *dest = malloc(WIDTH * HEIGHT * sizeof(float));
memcpy(dest, src, WIDTH * HEIGHT * sizeof(float));
return dest;
}

#define N 5
#define NN ((N * 2 + 1))

static void makegauss(float mat[NN][NN], float sigma, float dx, float dy)
{
float t = 0;
int i, j;

sigma = 2. * sigma * sigma;

for(j = 0; j < NN; j++)
for(i = 0; i < NN; i++)
{
float a = (float)(i - N) + dx;
float b = (float)(j - N) + dy;
mat[i][j] = pow(M_E, - (a * a + b * b) / sigma);
t += mat[i][j];
}

for(j = 0; j < NN; j++)
for(i = 0; i < NN; i++)
mat[i][j] /= t;
}

static float *gauss(float *src, float mat[NN][NN])
{
float *dest = new();
int x, y, i, j;

for(y = N; y < HEIGHT - N; y++)
for(x = N; x < WIDTH - N; x++)
{
float p = 0;

for(j = 0; j < NN; j++)
for(i = 0; i < NN; i++)
p += get(src, x + i - N, y + j - N) * mat[i][j];

put(dest, x, y, p);
}

return dest;
}

static float *fullgauss(float *src, float mat[NN][NN])
{
float *dest = new();
int x, y, i, j;

for(y = 0; y < HEIGHT; y++)
for(x = 0; x < WIDTH; x++)
{
float p = 0;

for(j = 0; j < NN; j++)
for(i = 0; i < NN; i++)
if(x + i >= N && x + i < WIDTH + N
&& y + j >= N && y + j < HEIGHT + N)
p += get(src, x + i - N, y + j - N) * mat[i][j];

put(dest, x, y, p);
}

return dest;
}

static float fulldist(float *p1, float *p2)
{
float error = 0.;
int x, y;

for(y = 0; y < HEIGHT; y++)
for(x = 0; x < WIDTH; x++)
{
float t = get(p1, x, y) - get(p2, x, y);
error += t * t;
}

return error / (WIDTH * HEIGHT);
}

static float dist(float *p1, float *p2)
{
float error = 0.;
int x, y;

for(y = N; y < HEIGHT - N; y++)
for(x = N; x < WIDTH - N; x++)
{
float t = get(p1, x, y) - get(p2, x, y);
error += t * t;
}

return error / ((WIDTH - N) * (HEIGHT - N));
}

static float *load(char *name)
{
SDL_Surface *tmp, *surface;
uint32_t *pixels;
float *floats;
int x, y;

tmp = IMG_Load(name);
if(!tmp)
return NULL;

WIDTH = tmp->w > MAXWIDTH ? MAXWIDTH : tmp->w;
HEIGHT = tmp->h > MAXHEIGHT ? MAXHEIGHT : tmp->h;
floats = malloc(WIDTH * HEIGHT * sizeof(float));
if(!floats)
return NULL;

surface = SDL_CreateRGBSurface(SDL_SWSURFACE, WIDTH, HEIGHT, 32,
0xff0000, 0xff00, 0xff, 0x0);
pixels = (uint32_t *)surface->pixels;
SDL_BlitSurface(tmp, NULL, surface, NULL);
SDL_FreeSurface(tmp);

for(y = 0; y < HEIGHT; y++)
for(x = 0; x < WIDTH; x++)
{
int green = (pixels[y * surface->pitch / 4 + x] >> 8) & 0xff;
put(floats, x, y, (float)green / 0xff);
}

return floats;
}

static void save(float *src, char *name)
{
SDL_Surface *surface;
uint32_t *pixels;
int x, y;

surface = SDL_CreateRGBSurface(SDL_SWSURFACE, WIDTH, HEIGHT, 32,
0xff0000, 0xff00, 0xff, 0x0);
pixels = (uint32_t *)surface->pixels;

for(y = 0; y < HEIGHT; y++)
for(x = 0; x < WIDTH; x++)
{
float p = 255 * get(src, x, y);
uint32_t i = p < 0 ? 0 : p > 255 ? 255 : p;
pixels[surface->pitch / 4 * y + x] = (i << 16) | (i << 8) | i;
}

SDL_SaveBMP(surface, name);
}

static float *ostromoukhov(float *src)
{
static int const table[][3] =
{
{13, 0, 5}, {13, 0, 5}, {21, 0, 10}, {7, 0, 4},
{8, 0, 5}, {47, 3, 28}, {23, 3, 13}, {15, 3, 8},
{22, 6, 11}, {43, 15, 20}, {7, 3, 3}, {501, 224, 211},
{249, 116, 103}, {165, 80, 67}, {123, 62, 49}, {489, 256, 191},
{81, 44, 31}, {483, 272, 181}, {60, 35, 22}, {53, 32, 19},
{237, 148, 83}, {471, 304, 161}, {3, 2, 1}, {481, 314, 185},
{354, 226, 155}, {1389, 866, 685}, {227, 138, 125}, {267, 158, 163},
{327, 188, 220}, {61, 34, 45}, {627, 338, 505}, {1227, 638, 1075},
{20, 10, 19}, {1937, 1000, 1767}, {977, 520, 855}, {657, 360, 551},
{71, 40, 57}, {2005, 1160, 1539}, {337, 200, 247}, {2039, 1240, 1425},
{257, 160, 171}, {691, 440, 437}, {1045, 680, 627}, {301, 200, 171},
{177, 120, 95}, {2141, 1480, 1083}, {1079, 760, 513}, {725, 520, 323},
{137, 100, 57}, {2209, 1640, 855}, {53, 40, 19}, {2243, 1720, 741},
{565, 440, 171}, {759, 600, 209}, {1147, 920, 285}, {2311, 1880, 513},
{97, 80, 19}, {335, 280, 57}, {1181, 1000, 171}, {793, 680, 95},
{599, 520, 57}, {2413, 2120, 171}, {405, 360, 19}, {2447, 2200, 57},
{11, 10, 0}, {158, 151, 3}, {178, 179, 7}, {1030, 1091, 63},
{248, 277, 21}, {318, 375, 35}, {458, 571, 63}, {878, 1159, 147},
{5, 7, 1}, {172, 181, 37}, {97, 76, 22}, {72, 41, 17},
{119, 47, 29}, {4, 1, 1}, {4, 1, 1}, {4, 1, 1},
{4, 1, 1}, {4, 1, 1}, {4, 1, 1}, {4, 1, 1},
{4, 1, 1}, {4, 1, 1}, {65, 18, 17}, {95, 29, 26},
{185, 62, 53}, {30, 11, 9}, {35, 14, 11}, {85, 37, 28},
{55, 26, 19}, {80, 41, 29}, {155, 86, 59}, {5, 3, 2},
{5, 3, 2}, {5, 3, 2}, {5, 3, 2}, {5, 3, 2},
{5, 3, 2}, {5, 3, 2}, {5, 3, 2}, {5, 3, 2},
{5, 3, 2}, {5, 3, 2}, {5, 3, 2}, {5, 3, 2},
{305, 176, 119}, {155, 86, 59}, {105, 56, 39}, {80, 41, 29},
{65, 32, 23}, {55, 26, 19}, {335, 152, 113}, {85, 37, 28},
{115, 48, 37}, {35, 14, 11}, {355, 136, 109}, {30, 11, 9},
{365, 128, 107}, {185, 62, 53}, {25, 8, 7}, {95, 29, 26},
{385, 112, 103}, {65, 18, 17}, {395, 104, 101}, {4, 1, 1}
};

float *dest = new();
float *tmp = copy(src);
int x, y;

for(y = 0; y < HEIGHT; y++)
{
for(x = 0; x < WIDTH; x++)
{
int x1 = (y & 1) ? WIDTH - 1 - x + 1 : x - 1;
int x2 = (y & 1) ? WIDTH - 1 - x : x;
int x3 = (y & 1) ? WIDTH - 1 - x - 1 : x + 1;

float p = get(tmp, x2, y);
float q = p > 0.5 ? 1. : 0.;
float error = (p - q);
int i = p * 255.9999;

put(dest, x2, y, q);

if(i > 127)
i = 255 - i;
if(i < 0)
i = 0;

error /= table[i][0] + table[i][1] + table[i][2];

if(x < WIDTH - 1)
put(tmp, x3, y, get(tmp, x3, y) + error * table[i][0]);
if(y < HEIGHT - 1)
{
if(x > 0)
put(tmp, x1, y + 1,
get(tmp, x1, y + 1) + error * table[i][1]);
put(tmp, x2, y + 1, get(tmp, x2, y + 1) + error * table[i][2]);
}
}
}

free(tmp);

return dest;
}

/* Dither using error diffusion and Floyd-Steinberg-like coefficients:
X a b
c d e f g
h i j k l
*/
static float *ed(float *src, int serpentine,
int a, int b, int c, int d, int e, int f,
int g, int h, int i, int j, int k, int l)
{
float *dest = new();
float *tmp = copy(src);
int x, y, n;

n = a + b + c + d + e + f + g + h + i + j + k + l;

for(y = 0; y < HEIGHT; y++)
{
int swap = serpentine && (y & 1);

for(x = 0; x < WIDTH; x++)
{
int x0 = swap ? WIDTH - 1 - x + 2 : x - 2;
int x1 = swap ? WIDTH - 1 - x + 1 : x - 1;
int x2 = swap ? WIDTH - 1 - x : x;
int x3 = swap ? WIDTH - 1 - x - 1 : x + 1;
int x4 = swap ? WIDTH - 1 - x - 2 : x + 2;

float p = get(tmp, x2, y);
float q = p > 0.5 ? 1. : 0.;
float error = (p - q) / n;

put(dest, x2, y, q);

if(x < WIDTH - 1)
put(tmp, x3, y, get(tmp, x3, y) + error * a);
if(x < WIDTH - 2)
put(tmp, x4, y, get(tmp, x4, y) + error * b);
if(y < HEIGHT - 1)
{
if(x > 0)
{
put(tmp, x1, y + 1,
get(tmp, x1, y + 1) + error * d);
if(x > 1)
put(tmp, x0, y + 1,
get(tmp, x0, y + 1) + error * c);
}
put(tmp, x2, y + 1, get(tmp, x2, y + 1) + error * e);
if(x < WIDTH - 1)
{
put(tmp, x3, y + 1,
get(tmp, x3, y + 1) + error * f);
if(x < WIDTH - 2)
put(tmp, x4, y + 1,
get(tmp, x4, y + 1) + error * g);
}
}
if(y < HEIGHT - 2)
{
if(x > 0)
{
put(tmp, x1, y + 2,
get(tmp, x1, y + 2) + error * h);
if(x > 1)
put(tmp, x0, y + 2,
get(tmp, x0, y + 2) + error * i);
}
put(tmp, x2, y + 2, get(tmp, x2, y + 2) + error * j);
if(x < WIDTH - 1)
{
put(tmp, x3, y + 2,
get(tmp, x3, y + 2) + error * k);
if(x < WIDTH - 2)
put(tmp, x4, y + 2,
get(tmp, x4, y + 2) + error * l);
}
}
}
}

free(tmp);

return dest;
}

/* XXX */
static float *dbs(float *src, float *orig, float sigma, float dx, float dy)
{
float mat[NN][NN];
float *dest, *tmp, *tmp2;
float error;

makegauss(mat, sigma, 0., 0.);
tmp = fullgauss(src, mat);

makegauss(mat, sigma, dx, dy);
dest = copy(orig);
tmp2 = fullgauss(dest, mat);

error = dist(tmp, tmp2);

for(;;)
{
int changes = 0;
int x, y, i, j, n;

for(y = 0; y < HEIGHT; y++)
for(x = 0; x < WIDTH; x++)
{
float d, d2, e, best = 0.;
int opx = -1, opy = -1;

d = get(dest, x, y);

/* Compute the effect of a toggle */
e = 0.;
for(j = -N; j < N + 1; j++)
{
if(y + j < 0 || y + j >= HEIGHT)
continue;

for(i = -N; i < N + 1; i++)
{
float m, p, q1, q2;

if(x + i < 0 || x + i >= WIDTH)
continue;
m = mat[i + N][j + N];
p = get(tmp, x + i, y + j);
q1 = get(tmp2, x + i, y + j);
q2 = q1 - m * d + m * (1. - d);
e += (q1 - p) * (q1 - p) - (q2 - p) * (q2 - p);
}
}
if(e > best)
{
best = e;
opx = opy = 0;
}

/* Compute the effect of swaps */
for(n = 0; n < 8; n++)
{
static int const step[] =
{ 0, 1, 0, -1, -1, 0, 1, 0, -1, -1, -1, 1, 1, -1, 1, 1 };
int idx = step[n * 2], idy = step[n * 2 + 1];
if(y + idy < 0 || y + idy >= HEIGHT
|| x + idx < 0 || x + idx >= WIDTH)
continue;
d2 = get(dest, x + idx, y + idy);
if(d2 == d)
continue;
e = 0.;
for(j = -N; j < N + 1; j++)
{
if(y + j < 0 || y + j >= HEIGHT)
continue;
if(j - idy + N < 0 || j - idy + N >= NN)
continue;
for(i = -N; i < N + 1; i++)
{
float ma, mb, p, q1, q2;
if(x + i < 0 || x + i >= WIDTH)
continue;
if(i - idx + N < 0 || i - idx + N >= NN)
continue;
ma = mat[i + N][j + N];
mb = mat[i - idx + N][j - idy + N];
p = get(tmp, x + i, y + j);
q1 = get(tmp2, x + i, y + j);
q2 = q1 - ma * d + ma * d2 - mb * d2 + mb * d;
e += (q1 - p) * (q1 - p) - (q2 - p) * (q2 - p);
}
}
if(e > best)
{
best = e;
opx = idx;
opy = idy;
}
}

/* Apply the change if interesting */
if(best <= 0.)
continue;
if(opx || opy)
{
d2 = get(dest, x + opx, y + opy);
put(dest, x + opx, y + opy, d);
}
else
d2 = 1. - d;
put(dest, x, y, d2);
for(j = -N; j < N + 1; j++)
for(i = -N; i < N + 1; i++)
{
float m = mat[i + N][j + N];
if(y + j >= 0 && y + j < HEIGHT
&& x + i >= 0 && x + i < WIDTH)
{
float t = get(tmp2, x + i, y + j);
put(tmp2, x + i, y + j, t + m * (d2 - d));
}
if((opx || opy) && y + opy + j >= 0 && y + opy + j < HEIGHT
&& x + opx + i >= 0 && x + opx + i < WIDTH)
{
float t = get(tmp2, x + opx + i, y + opy + j);
put(tmp2, x + opx + i, y + opy + j, t + m * (d - d2));
}
}

changes++;
}

fprintf(stderr, "did %i changes\n", changes);

if(changes == 0)
break;
}

free(tmp);
free(tmp2);

return dest;
}

static void study(float *src, float *dest, float sigma, float precision)
{
# define Z 3
float mat[NN][NN];
float *tmp, *tmp2;
float e0, best, fx = -1., fy = -1., step = 2.;
int dx, dy;

makegauss(mat, sigma, 0., 0.);
tmp = gauss(src, mat);
tmp2 = gauss(dest, mat);

e0 = dist(tmp, tmp2);
free(tmp2);

while(step > precision)
{
float bfx = 0., bfy = 0., e;

best = 9999.;

for(dy = 0; dy <= Z; dy++)
for(dx = 0; dx <= Z; dx++)
{
makegauss(mat, sigma, fx + step * dx / Z, fy + step * dy / Z);
tmp2 = gauss(dest, mat);
e = dist(tmp, tmp2);
free(tmp2);
if(e < best)
{
best = e;
bfx = fx + step * dx / Z;
bfy = fy + step * dy / Z;
}
}

fx = bfx - step / Z;
fy = bfy - step / Z;
step = step * 2 / Z;
}

free(tmp);

printf("%g -> %g for %g %g\n", 1000 * e0, 1000 * best, fx, fy);
fflush(stdout);
}

static float *merge(float *im1, float *im2, float t)
{
float *dest = new();
int x, y;

for(y = 0; y < HEIGHT; y++)
for(x = 0; x < WIDTH; x++)
put(dest, x, y, t * get(im1, x, y) + (1. - t) * get(im2, x, y));

return dest;
}

int main(int argc, char *argv[])
{
float mat0[NN][NN];
float mat[NN][NN];
float *src, *src2, *dest, *tmp, *tmp2;
float sigma;
int dx, dy, a, b, c, d, i;

if(argc < 2)
return 1;

src = load(argv[1]);
if(!src)
return 2;

#if 0
if(argc < 3)
return 3;
src2 = load(argv[2]);
if(!src2)
return 4;

for(i = 0; i <= 100; i++)
{
tmp = merge(src, src2, (float)i / 100.);
dest = ed(tmp, 7, 0, 1, 3, 5, 0, 0, 0, 0, 0, 0, 0);
study(tmp, dest, 1.2, 0.001);
free(dest);
free(tmp);
}
free(src2);
free(src);
#endif

#if 0
tmp = ed(src, 7, 0, 0, 3, 5, 1, 0, 0, 0, 0, 0, 0);
//dest = dbs(src, tmp, 0., 0.);
dest = dbs(src, tmp, 0.20, 0.30);
//dest = dbs(src, tmp, 0.158718, 0.283089);
//dest = copy(tmp);
free(tmp);
study(src, dest, 1.2, 0.00001);
save(dest, "output.bmp");
free(dest);
#endif

#if 0
//dest = ed(src, 5, 0, 0, 3, 5, 3, 0, 0, 0, 0, 0, 0);
//dest = ed(src, false, 7, 0, 0, 3, 5, 1, 0, 0, 0, 0, 0, 0);
//dest = ed(src, true, 7, 0, 0, 3, 5, 1, 0, 0, 0, 0, 0, 0);
//dest = ed(src, true, 7, 0, 0, 4, 5, 0, 0, 0, 0, 0, 0, 0);
//dest = ed(src, 7, 5, 3, 5, 7, 5, 3, 1, 3, 5, 3, 1);
//dest = ed(src, 7, 0, 1, 3, 5, 0, 0, 0, 0, 0, 0, 0);
//dest = ed(src, 7, 0, 1, 4, 4, 0, 0, 0, 0, 0, 0, 0);
//dest = ed(src, 2, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0);
//dest = ed(src, 2911, 0, 1373, 3457, 2258, 0, 0, 0, 0, 0, 0, 0);
dest = ostromoukhov(src);
//dest = ed(src, 7, 0, 0, 4, 5, 0, 0, 0, 0, 0, 0, 0);
//printf("%s: ", argv[1]);
//study(src, dest, 1.2, 0.001);
save(dest, "output.bmp");
free(dest);
#endif

#if 0
# define STEP 32
dest = ed(src, 7, 0, 0, 3, 5, 1, 0, 0, 0, 0, 0, 0);
makegauss(mat, 1.2, 0., 0.);
tmp = gauss(src, mat);
for(dy = 0; dy < STEP; dy++)
{
for(dx = 0; dx < STEP; dx++)
{
float fy = 2. / STEP * (dy - STEP / 2.);
float fx = 2. / STEP * (dx - STEP / 2.);

makegauss(mat, 1.2, fx, fy);
tmp2 = gauss(dest, mat);
printf("%g %g %g\n", fy, fx, 1000. * dist(tmp, tmp2));
fflush(stdout);
free(tmp2);
}
printf("\n");
}

save(dest, "output.bmp");
#endif

#if 0
makegauss(mat0, 1.2, 0, 0);
for(a = 0; a <= 16; a++)
for(b = 0; b <= 16; b++)
for(c = 0; c <= 16; c++)
for(d = 0; d <= 16; d++)
{
float *tmp;
if(a + b + c + d != 16)
continue;
#if 0
if(b > c) continue;
if(d > c) continue;
if(d > a) continue;
#endif
printf("%02d %02d %02d %02d: ", a, b, c, d);
dest = ed(src, true, a, 0, 0, b, c, d, 0, 0, 0, 0, 0, 0);
//dest = ed(src, false, a, 0, 0, b, c, d, 0, 0, 0, 0, 0, 0);
//study(src, dest, 1.2, 0.01);
tmp = gauss(src, mat0);
tmp2 = gauss(dest, mat0);
printf("%.5g\n", 1000. * dist(tmp, tmp2));
fflush(stdout);
free(tmp);
free(tmp2);
free(dest);
}
#endif

#if 0
tmp = gauss(src, 0., 0.);
for(a = 0; a < 16; a++)
for(b = 0; b < 16; b++)
for(c = 0; c < 16; c++)
for(d = 0; d < 16; d++)
{
if(a + b + c + d != 16)
continue;
dest = ed(src, a, 0, 0, b, c, d, 0, 0, 0, 0, 0, 0);
tmp2 = gauss(dest, 0., 0.);
printf("%.5g: (%02d %02d %02d %02d)\n",
1000. * dist(tmp, tmp2), a, b, c, d);
free(dest);
free(tmp2);
}

save(dest, "output.bmp");
#endif

#if 0
printf("%s: ", argv[1]);
makegauss(mat0, 1.2, 0, 0);
tmp = gauss(src, mat0);

dest = ed(src, false, 7, 0, 0, 3, 5, 1, 0, 0, 0, 0, 0, 0);
tmp2 = gauss(dest, mat0);
printf("%.5g ", 1000. * dist(tmp, tmp2));
free(tmp2);
makegauss(mat, 1.2, 0.16, 0.28);
tmp2 = gauss(dest, mat);
printf("%.5g ", 1000. * dist(tmp, tmp2));
free(tmp2);
free(dest);

dest = ed(src, false, 7, 5, 3, 5, 7, 5, 3, 1, 3, 5, 3, 1);
tmp2 = gauss(dest, mat0);
printf("%.5g ", 1000. * dist(tmp, tmp2));
free(tmp2);
makegauss(mat, 1.2, 0.26, 0.76);
tmp2 = gauss(dest, mat);
printf("%.5g ", 1000. * dist(tmp, tmp2));
free(tmp2);
free(dest);

dest = ostromoukhov(src);
tmp2 = gauss(dest, mat0);
printf("%.5g ", 1000. * dist(tmp, tmp2));
free(tmp2);
makegauss(mat, 1.2, 0.0, 0.19);
tmp2 = gauss(dest, mat);
printf("%.5g ", 1000. * dist(tmp, tmp2));
free(tmp2);
free(dest);

dest = ed(src, true, 2911, 0, 0, 1373, 3457, 2258, 0, 0, 0, 0, 0, 0);
tmp2 = gauss(dest, mat0);
printf("%.5g ", 1000. * dist(tmp, tmp2));
free(tmp2);
makegauss(mat, 1.2, 0.0, 0.34);
tmp2 = gauss(dest, mat);
printf("%.5g ", 1000. * dist(tmp, tmp2));
free(tmp2);
free(dest);

printf("\n");
#endif

#if 0
printf("%s\n", argv[1]);

dest = ed(src, false, 7, 0, 0, 3, 5, 1, 0, 0, 0, 0, 0, 0);
study(src, dest, 1.2, 0.01);
free(dest);

dest = ed(src, false, 7, 5, 3, 5, 7, 5, 3, 1, 3, 5, 3, 1);
study(src, dest, 1.2, 0.01);
free(dest);

dest = ostromoukhov(src);
study(src, dest, 1.2, 0.01);
free(dest);

dest = ed(src, true, 2911, 0, 0, 1373, 3457, 2258, 0, 0, 0, 0, 0, 0);
study(src, dest, 1.2, 0.01);
free(dest);

printf("\n");
#endif

#if 0
//dest = ostromoukhov(src);
//dest = ed(src, true, 7, 0, 0, 3, 5, 1, 0, 0, 0, 0, 0, 0);
tmp = new();//ed(src, 7, 0, 0, 3, 5, 1, 0, 0, 0, 0, 0, 0);
dest = dbs(src, tmp, 0., 0.);
for(sigma = 0.8; sigma < 2; sigma *= 1.03)
//for(sigma = 0.8; sigma < 2.; sigma *= 1.01)
{
printf("%g ", sigma);
study(src, dest, sigma, 0.01);
}
#endif

tmp = new();
a = 0;
for(sigma = 0.8; sigma < 2; sigma *= 1.03)
{
char buf[1024];
printf("%i: %g\n", a, sigma);
dest = dbs(src, tmp, sigma, 0., 0.);
sprintf(buf, "output-dbs-%i.bmp", a++);
save(dest, buf);
}

return 0;
}


+ 14509
- 0
2008-displacement/optimum-histo.eps
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 388
- 0
2008-displacement/optimum-histo.tex Просмотреть файл

@@ -0,0 +1,388 @@
% GNUPLOT: LaTeX picture with Postscript
\begingroup
\makeatletter
\providecommand\color[2][]{%
\GenericError{(gnuplot) \space\space\space\@spaces}{%
Package color not loaded in conjunction with
terminal option `colourtext'%
}{See the gnuplot documentation for explanation.%
}{Either use 'blacktext' in gnuplot or load the package
color.sty in LaTeX.}%
\renewcommand\color[2][]{}%
}%
\providecommand\includegraphics[2][]{%
\GenericError{(gnuplot) \space\space\space\@spaces}{%
Package graphicx or graphics not loaded%
}{See the gnuplot documentation for explanation.%
}{The gnuplot epslatex terminal needs graphicx.sty or graphics.sty.}%
\renewcommand\includegraphics[2][]{}%
}%
\providecommand\rotatebox[2]{#2}%
\@ifundefined{ifGPcolor}{%
\newif\ifGPcolor
\GPcolortrue
}{}%
\@ifundefined{ifGPblacktext}{%
\newif\ifGPblacktext
\GPblacktexttrue
}{}%
% define a \g@addto@macro without @ in the name:
\let\gplgaddtomacro\g@addto@macro
% define empty templates for all commands taking text:
\gdef\gplbacktext{}%
\gdef\gplfronttext{}%
\makeatother
\ifGPblacktext
% no textcolor at all
\def\colorrgb#1{}%
\def\colorgray#1{}%
\else
% gray or color?
\ifGPcolor
\def\colorrgb#1{\color[rgb]{#1}}%
\def\colorgray#1{\color[gray]{#1}}%
\expandafter\def\csname LTw\endcsname{\color{white}}%
\expandafter\def\csname LTb\endcsname{\color{black}}%
\expandafter\def\csname LTa\endcsname{\color{black}}%
\expandafter\def\csname LT0\endcsname{\color[rgb]{1,0,0}}%
\expandafter\def\csname LT1\endcsname{\color[rgb]{0,1,0}}%
\expandafter\def\csname LT2\endcsname{\color[rgb]{0,0,1}}%
\expandafter\def\csname LT3\endcsname{\color[rgb]{1,0,1}}%
\expandafter\def\csname LT4\endcsname{\color[rgb]{0,1,1}}%
\expandafter\def\csname LT5\endcsname{\color[rgb]{1,1,0}}%
\expandafter\def\csname LT6\endcsname{\color[rgb]{0,0,0}}%
\expandafter\def\csname LT7\endcsname{\color[rgb]{1,0.3,0}}%
\expandafter\def\csname LT8\endcsname{\color[rgb]{0.5,0.5,0.5}}%
\else
% gray
\def\colorrgb#1{\color{black}}%
\def\colorgray#1{\color[gray]{#1}}%
\expandafter\def\csname LTw\endcsname{\color{white}}%
\expandafter\def\csname LTb\endcsname{\color{black}}%
\expandafter\def\csname LTa\endcsname{\color{black}}%
\expandafter\def\csname LT0\endcsname{\color{black}}%
\expandafter\def\csname LT1\endcsname{\color{black}}%
\expandafter\def\csname LT2\endcsname{\color{black}}%
\expandafter\def\csname LT3\endcsname{\color{black}}%
\expandafter\def\csname LT4\endcsname{\color{black}}%
\expandafter\def\csname LT5\endcsname{\color{black}}%
\expandafter\def\csname LT6\endcsname{\color{black}}%
\expandafter\def\csname LT7\endcsname{\color{black}}%
\expandafter\def\csname LT8\endcsname{\color{black}}%
\fi
\fi
\setlength{\unitlength}{0.0500bp}%
\begin{picture}(2590.00,2590.00)%
\gplgaddtomacro\gplbacktext{%
}%
\gplgaddtomacro\gplfronttext{%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\csname LTb\endcsname%
\put(130,104){\makebox(0,0){\strut{}-0.5}}%
\csname LTb\endcsname%
\put(463,104){\makebox(0,0){\strut{}-0.4}}%
\csname LTb\endcsname%
\put(796,104){\makebox(0,0){\strut{}-0.3}}%
\csname LTb\endcsname%
\put(1129,104){\makebox(0,0){\strut{}-0.2}}%
\csname LTb\endcsname%
\put(1461,104){\makebox(0,0){\strut{}-0.1}}%
\csname LTb\endcsname%
\put(1794,104){\makebox(0,0){\strut{} 0}}%
\csname LTb\endcsname%
\put(2127,104){\makebox(0,0){\strut{} 0.1}}%
\csname LTb\endcsname%
\put(2460,104){\makebox(0,0){\strut{} 0.2}}%
\csname LTb\endcsname%
\put(-42,2460){\makebox(0,0)[r]{\strut{}-0.1}}%
\csname LTb\endcsname%
\put(-42,2164){\makebox(0,0)[r]{\strut{} 0}}%
\csname LTb\endcsname%
\put(-42,1868){\makebox(0,0)[r]{\strut{} 0.1}}%
\csname LTb\endcsname%
\put(-42,1572){\makebox(0,0)[r]{\strut{} 0.2}}%
\csname LTb\endcsname%
\put(-42,1278){\makebox(0,0)[r]{\strut{} 0.3}}%
\csname LTb\endcsname%
\put(-42,982){\makebox(0,0)[r]{\strut{} 0.4}}%
\csname LTb\endcsname%
\put(-42,686){\makebox(0,0)[r]{\strut{} 0.5}}%
\csname LTb\endcsname%
\put(-42,390){\makebox(0,0)[r]{\strut{} 0.6}}%
}%
\gplbacktext
\put(0,0){\includegraphics{optimum-histo}}%
\gplfronttext
\end{picture}%
\endgroup

+ 16956
- 0
2008-displacement/ostro-histo.eps
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 488
- 0
2008-displacement/ostro-histo.tex Просмотреть файл

@@ -0,0 +1,488 @@
% GNUPLOT: LaTeX picture with Postscript
\begingroup
\makeatletter
\providecommand\color[2][]{%
\GenericError{(gnuplot) \space\space\space\@spaces}{%
Package color not loaded in conjunction with
terminal option `colourtext'%
}{See the gnuplot documentation for explanation.%
}{Either use 'blacktext' in gnuplot or load the package
color.sty in LaTeX.}%
\renewcommand\color[2][]{}%
}%
\providecommand\includegraphics[2][]{%
\GenericError{(gnuplot) \space\space\space\@spaces}{%
Package graphicx or graphics not loaded%
}{See the gnuplot documentation for explanation.%
}{The gnuplot epslatex terminal needs graphicx.sty or graphics.sty.}%
\renewcommand\includegraphics[2][]{}%
}%
\providecommand\rotatebox[2]{#2}%
\@ifundefined{ifGPcolor}{%
\newif\ifGPcolor
\GPcolortrue
}{}%
\@ifundefined{ifGPblacktext}{%
\newif\ifGPblacktext
\GPblacktexttrue
}{}%
% define a \g@addto@macro without @ in the name:
\let\gplgaddtomacro\g@addto@macro
% define empty templates for all commands taking text:
\gdef\gplbacktext{}%
\gdef\gplfronttext{}%
\makeatother
\ifGPblacktext
% no textcolor at all
\def\colorrgb#1{}%
\def\colorgray#1{}%
\else
% gray or color?
\ifGPcolor
\def\colorrgb#1{\color[rgb]{#1}}%
\def\colorgray#1{\color[gray]{#1}}%
\expandafter\def\csname LTw\endcsname{\color{white}}%
\expandafter\def\csname LTb\endcsname{\color{black}}%
\expandafter\def\csname LTa\endcsname{\color{black}}%
\expandafter\def\csname LT0\endcsname{\color[rgb]{1,0,0}}%
\expandafter\def\csname LT1\endcsname{\color[rgb]{0,1,0}}%
\expandafter\def\csname LT2\endcsname{\color[rgb]{0,0,1}}%
\expandafter\def\csname LT3\endcsname{\color[rgb]{1,0,1}}%
\expandafter\def\csname LT4\endcsname{\color[rgb]{0,1,1}}%
\expandafter\def\csname LT5\endcsname{\color[rgb]{1,1,0}}%
\expandafter\def\csname LT6\endcsname{\color[rgb]{0,0,0}}%
\expandafter\def\csname LT7\endcsname{\color[rgb]{1,0.3,0}}%
\expandafter\def\csname LT8\endcsname{\color[rgb]{0.5,0.5,0.5}}%
\else
% gray
\def\colorrgb#1{\color{black}}%
\def\colorgray#1{\color[gray]{#1}}%
\expandafter\def\csname LTw\endcsname{\color{white}}%
\expandafter\def\csname LTb\endcsname{\color{black}}%
\expandafter\def\csname LTa\endcsname{\color{black}}%
\expandafter\def\csname LT0\endcsname{\color{black}}%
\expandafter\def\csname LT1\endcsname{\color{black}}%
\expandafter\def\csname LT2\endcsname{\color{black}}%
\expandafter\def\csname LT3\endcsname{\color{black}}%
\expandafter\def\csname LT4\endcsname{\color{black}}%
\expandafter\def\csname LT5\endcsname{\color{black}}%
\expandafter\def\csname LT6\endcsname{\color{black}}%
\expandafter\def\csname LT7\endcsname{\color{black}}%
\expandafter\def\csname LT8\endcsname{\color{black}}%
\fi
\fi
\setlength{\unitlength}{0.0500bp}%
\begin{picture}(2590.00,2590.00)%
\gplgaddtomacro\gplbacktext{%
}%
\gplgaddtomacro\gplfronttext{%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\csname LTb\endcsname%
\put(130,104){\makebox(0,0){\strut{}-0.2}}%
\csname LTb\endcsname%
\put(421,104){\makebox(0,0){\strut{}-0.15}}%
\csname LTb\endcsname%
\put(713,104){\makebox(0,0){\strut{}-0.1}}%
\csname LTb\endcsname%
\put(1004,104){\makebox(0,0){\strut{}-0.05}}%
\csname LTb\endcsname%
\put(1295,104){\makebox(0,0){\strut{} 0}}%
\csname LTb\endcsname%
\put(1586,104){\makebox(0,0){\strut{} 0.05}}%
\csname LTb\endcsname%
\put(1877,104){\makebox(0,0){\strut{} 0.1}}%
\csname LTb\endcsname%
\put(2169,104){\makebox(0,0){\strut{} 0.15}}%
\csname LTb\endcsname%
\put(2460,104){\makebox(0,0){\strut{} 0.2}}%
\csname LTb\endcsname%
\put(-42,2460){\makebox(0,0)[r]{\strut{}-0.1}}%
\csname LTb\endcsname%
\put(-42,2201){\makebox(0,0)[r]{\strut{}-0.05}}%
\csname LTb\endcsname%
\put(-42,1942){\makebox(0,0)[r]{\strut{} 0}}%
\csname LTb\endcsname%
\put(-42,1683){\makebox(0,0)[r]{\strut{} 0.05}}%
\csname LTb\endcsname%
\put(-42,1425){\makebox(0,0)[r]{\strut{} 0.1}}%
\csname LTb\endcsname%
\put(-42,1167){\makebox(0,0)[r]{\strut{} 0.15}}%
\csname LTb\endcsname%
\put(-42,908){\makebox(0,0)[r]{\strut{} 0.2}}%
\csname LTb\endcsname%
\put(-42,649){\makebox(0,0)[r]{\strut{} 0.25}}%
\csname LTb\endcsname%
\put(-42,390){\makebox(0,0)[r]{\strut{} 0.3}}%
}%
\gplbacktext
\put(0,0){\includegraphics{ostro-histo}}%
\gplfronttext
\end{picture}%
\endgroup

+ 486
- 0
2008-displacement/paper.tex Просмотреть файл

@@ -0,0 +1,486 @@
% This is LLNCS.DEM the demonstration file of
% the LaTeX macro package from Springer-Verlag
% for Lecture Notes in Computer Science,
% version 2.2 for LaTeX2e
%
\documentclass{llncs}
%
\usepackage{makeidx} % allows for indexgeneration
\usepackage{graphicx} % for gnuplot epslatex stuff
\usepackage{color} % ditto
\usepackage{pstricks} % for inkscape TeX output
%
\begin{document}
%
\mainmatter % start of the contributions
%
\title{Reinstating Floyd-Steinberg: Improved Metrics for Quality Assessment
of Error Diffusion Algorithms}
%
\titlerunning{Adapting Qualitative Metrics to Common Error Diffusion Algorithms} % abbreviated title (for running head)
% also used for the TOC unless
% \toctitle is used
%
\author{Sam Hocevar\inst{1} \and Gary Niger\inst{2}}
%
\authorrunning{Sam Hocevar et al.} % abbreviated author list (for running head)
%
%%%% modified list of authors for the TOC (add the affiliations)
\tocauthor{Sam Hocevar, Gary Niger (Laboratoire d'Imagerie Bureautique et de
Conception Artistique)}
%
\institute{Laboratoire d'Imagerie Bureautique et de Conception Artistique\\
14 rue de Plaisance, Paris, France
\and
143 Rolloffle Avenue, Tarzana, California 91356\\
\email{sam@hocevar.net}, \email{gary\_niger@gnaa.us}}

\maketitle % typeset the title of the contribution

\begin{abstract}
In this contribution we introduce a little-known property of error diffusion
halftoning algorithms which we call error diffusion displacement.
By accounting for the inherent sub-pixel displacement caused by the error
propagation, we correct an important flaw in most metrics used to assess the
quality of resulting halftones. We find these metrics to usually highly
underestimate the quality of error diffusion in comparison to more modern
algorithms such as direct binary search.
Using empirical observation, we give a method for creating computationally
efficient, image-independent, model-based metrics for this quality assessment.
Finally, we use the properties of error diffusion displacement to justify
Floyd and Steinberg's well-known choice of algorithm coefficients.

{\bf Keywords}: halftoning, error diffusion, image quality, human visual
system, color quantization
\end{abstract}
%
\section{Introduction}

Image dithering is the process of reducing continuous-tone images to images
with a limited number of available colours. Applications vary tremendously,
from laser and ink-jet printing to display on small devices such as cellphones,
or even the design of banknotes.

Countless methods have been published for the last 40 years that try to best
address the problem of colour reduction. Comparing two algorithms in terms of
speed or memory usage is often straightforward, but how exactly a halftoning
algorithm performs in terms of quality is a far more complex issue, as it
highly depends on the display device and the inner workings of the human eye.

Though this document focuses on the particular case of bilevel halftoning,
most of our results can be directly adapted to the more generic problem of
colour reduction.

\section{Halftoning algorithms}

The most ancient halftoning method is probably classical screening. This highly
parallelisible algorithm consists in tiling a dither matrix over the image
and using its elements as threshold values. Classical screening is known for
its structural artifacts such as the cross-hatch patterns caused by Bayer
ordered dither matrices \cite{bayer}. However, modern techniques such as the
void-and-cluster method \cite{void1}, \cite{void2} allow to generate screens
yielding visually pleasing results.

Error diffusion dithering, introduced in 1976 by Floyd and Steinberg
\cite{fstein}, tries to compensate for the thresholding error through the use
of feedback. Typically applied in raster scan order, it uses an error diffusion
matrix such as the following one:

\[ \frac{1}{16} \left| \begin{array}{ccc}
- & x & 7 \\
3 & 5 & 1 \end{array} \right| \]

Though efforts have been made to make error diffusion parallelisable
\cite{parfstein}, it is generally considered more computationally expensive
than screening.

Model-based halftoning is the third important algorithm category. It relies
on a model of the human visual system (HVS) and attempts to minimise an error
value based on that model. One such algorithm is direct binary seach (DBS)
\cite{allebach}, also referred to as least-squares model-based halftoning
(LSMB) \cite{lsmb}.

HVS models are usually low-pass filters. Nasanen \cite{nasanen}, Analoui
and Allebach \cite{allebach} found that using gaussian models gave visually
pleasing results, an observation confirmed by independent visual perception
studies \cite{mcnamara}.

DBS yields halftones of impressive quality. However, despite efforts to make
it more efficient \cite{bhatt}, it suffers from its large computational
requirements and error diffusion remains a widely used technique.

\section{Error diffusion displacement}

Most error diffusion implementations parse the image in raster scan order.
Boustrophedonic (serpentine) scan has been shown to cause fewer visual
artifacts \cite{halftoning}, but other, more complex processing paths such as
Hilbert curves \cite{spacefilling}, \cite{peano} are seldom used as they do not
improve the image quality significantly.

Intuitively, as the error is always propagated to the bottom-left or
bottom-right of each pixel (Fig. \ref{fig:direction}), one may expect the
resulting image to be slightly translated. This expectation is confirmed
when alternatively viewing an error diffused image and the corresponding DBS
halftone.

\begin{figure}
\begin{center}
\input{direction}
\caption{Floyd-Steinberg error diffusion direction in raster scan (left)
and serpentine scan (right).}\label{fig:direction}
\end{center}
\end{figure}

This small translation is visually innocuous but we found that it means a lot
in terms of error computation. A common way to compute the error between an
image $h_{i,j}$ and the corresponding halftone $b_{i,j}$ is to compute the
mean square error between modified versions of the images, in the form:

\begin{equation}
E(h,b) = \frac{(||v * h_{i,j} - v * b_{i,j}||_2)^2}{wh}
\end{equation}

where $w$ and $h$ are the image dimensions, $*$ denotes the convolution and $v$
is a model for the human visual system.

To compensate for the slight translation experienced in the halftone, we
use the following error metric instead:

\begin{equation}
E_{dx,dy}(h,b) = \frac{(||v * h_{i,j} - v * t_{dx,dy} * b_{i,j}||_2)^2}{wh}
\end{equation}

where $t_{dx,dy}$ is an operator which translates the image along the $(dx,dy)$
vector.

A simple example can be given using a gaussian HVS model:

\begin{equation}
v(x,y) = e^{\frac{x^2+y^2}{2\sigma^2}}
\end{equation}

Finding the second filter is then straightforward:

\begin{equation}
(v * t_{dx,dy})(x,y) = e^{\frac{(x-dx)^2+(y-dy)^2}{2\sigma^2}}
\end{equation}

Experiment shows that for a given image and a given corresponding halftone,
$E_{dx,dy}$ has a local minimum almost always away from $(dx,dy) = (0,0)$ (Fig.
\ref{fig:lena-min}). Let $E$ be an error metric where this remains true. We
call the local minimum $E_{min}$:

\begin{equation}
E_{min}(h,b) = \min_{dx,dy}E_{dx,dy}(h,b)
\end{equation}

\begin{figure}
\begin{center}
\input{lena-min}
\caption{Mean square error for the \textit{Lena} image. $v$ is a simple
$11\times11$ gaussian convolution kernel with $\sigma = 1.2$ and
$(dx,dy)$ vary in $[-1,1]\times[-1,1]$.}
\label{fig:lena-min}
\end{center}
\end{figure}

For instance, a Floyd-Steinberg dither of \textit{Lena}, with $\sigma = 1.2$
yields a per-pixel mean square error of $8.51\times10^{-4}$. However, when
taking the displacement into account, the error becomes $7.77\times10^{-4}$
for $(dx,dy) = (0.167709,0.299347)$. The new, corrected error is significantly
smaller, with the exact same input and output images.

Experiment shows that the corrected error is always noticeably smaller except
in the case of images that are already mostly pure black and white. The
experiment was performed on a database of 10,000 images from common computer
vision sets and from the image board \textit{4chan}, providing a representative
sampling of the photographs, digital art and business graphics widely exchanged
on the Internet.

In addition to the classical Floyd-Steinberg and Jarvis, Judice and Ninke
kernels, we tested two serpentine error diffusion algorithms: Ostromoukhov's
simple error diffusion \cite{ostromoukhov}, which uses a variable coefficient
kernel, and Wong and Allebach's optimum error diffusion kernel \cite{wong}.

\begin{center}
\begin{tabular}{|l|l|l|}
\hline
& $E$ & $E_{min}$ \\ \hline
raster Floyd-Steinberg & 0.00089705 & 0.000346514 \\ \hline
raster Ja-Ju-Ni & 0.0020309 & 0.000692003 \\ \hline
Ostromoukhov & 0.00189721 & 0.00186343 \\ \hline
% raster optimum kernel & 0.00442951 & 0.00135092 \\ \hline
optimum kernel & 0.00146338 & 0.00136522 \\
\hline
\end{tabular}
\end{center}

We clearly see that usual metrics underestimate the quality of error-diffused
halftones, especially in raster scan. Algorithms such as direct binary search,
on the other hand, do not suffer from this bias since they are designed to
minimise the very error induced by the HVS model.

\section{An image-independent corrected quality metric for error-diffused
halftones}

We have seen that for a given image, $E_{min}(h,b)$ is a better and fairer
visual error measurement than $E(h,b)$. However, its major drawback is that it
is highly computationally expensive: for each image, the new $(dx,dy)$ values
need to be calculated to minimise the energy value.

Fortunately, we found that for a given raster or serpentine scan
error diffusion algorithm, there was often very little variation in
the optimal $(dx,dy)$ values (Fig. \ref{fig:table-historaster} and
\ref{fig:table-histoserp}).

\begin{figure}
\begin{center}
\begin{minipage}[c]{0.50\textwidth}
\input{fs-histo}
\end{minipage}
\begin{minipage}[c]{0.40\textwidth}
\input{jajuni-histo}
\end{minipage}
\caption{error diffusion displacement histograms for the raster
Floyd-Steinberg (left) and raster Jarvis, Judis and Ninke (right)
algorithms applied to a corpus of 10,000 images}
\label{fig:table-historaster}
\end{center}
\end{figure}

\begin{figure}
\begin{center}
\begin{minipage}[c]{0.50\textwidth}
\input{ostro-histo}
\end{minipage}
\begin{minipage}[c]{0.40\textwidth}
\input{serpopt-histo}
\end{minipage}
\caption{error diffusion displacement histograms for the Ostromoukhov (left) and optimum kernel (right) algorithms applied to a corpus
of 10,000 images}
\label{fig:table-histoserp}
\end{center}
\end{figure}

For each algorithm, we choose the $(dx,dy)$ values at the histogram peak and
we refer to them as the \textit{algorithm's displacement}, as opposed to the
\textit{image's displacement} for a given algorithm. We call $E_{fast}(h,b)$
the error computed at $(dx,dy)$. As $E_{fast}$ does not depend on the image, it
is a lot faster to compute than $E_{min}$, and as it is statistically closer to
$E_{min}$, we can expect it to be a better error estimation than $E$.

\begin{center}
\begin{tabular}{|l|l|l|l|l|}
\hline
& $E$ & $dx$ & $dy$ & $E_{fast}$ \\ \hline
raster Floyd-Steinberg & 0.00089705 & 0.16 & 0.28 & 0.00083502 \\ \hline
raster Ja-Ju-Ni & 0.0020309 & 0.26 & 0.76 & 0.00192991 \\ \hline
Ostromoukhov & 0.00189721 & 0.00 & 0.19 & 0.00186839 \\ \hline
optimum kernel & 0.00146338 & 0.00 & 0.34 & 0.00138165 \\
\hline
\end{tabular}
\end{center}

\section{Using error diffusion displacement for optimum kernel design}

We believe that our higher quality $E_{min}$ error metric may be useful in
kernel design, because it is the very same error that admittedly superior yet
computationally expensive algorithms such as DBS try to minimise.

Our first experiment was a study of the Floyd-Steinberg-like 4-block error
diffusion kernels. According to the original authors, the coefficients were
found "mostly by trial and error" \cite{fstein}. With our improved metric, we
now have the tools to confirm or infirm Floyd and Steinberg's initial proposal.

We chose to do an exhaustive study of every $\frac{1}{16}\{a,b,c,d\}$ integer
combination. We deliberately chose positive integers whose sum is 16. Error
diffusion coefficients smaller than zero or adding up to more than 1 are known
to be unstable \cite{stability}, and diffusing less than 100\% of the error is
known to cause important error in shadow and highlight areas of the image.

First we studied all possible coefficients on a pool of 250 images with an
error metric $E$ based on a standard gaussian HVS model. Since we are studying
algorithms on different images but error values are only meaningful for a given
image, we chose a Condorcet voting scheme to determine winners. $E_{min}$ is
only given here as an indication and had no role in the computation:

\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
rank & coefficients & $E$ & $E_{min}$ \\ \hline
1 & 8 3 5 0 & 0.00129563 & 0.000309993 \\ \hline
2 & 7 3 6 0 & 0.00131781 & 0.000313941 \\ \hline
3 & 9 3 4 0 & 0.00131115 & 0.000310815 \\ \hline
4 & 9 2 5 0 & 0.00132785 & 0.000322754 \\ \hline
5 & 8 4 4 0 & 0.0013117 & 0.00031749 \\ \hline
\dots & \dots & \dots & \dots \\
\hline
\end{tabular}
\end{center}

The exact same operation using $E_{min}$ as the decision variable yields very
different results. Again, $E$ is only given here as an indication:

\begin{center}
\begin{tabular}{|c|c|c|c|}
\hline
rank & coefficients & $E_{min}$ & $E$ \\ \hline
1 & 7 3 5 1 & 0.000306251 & 0.00141414 \\ \hline
2 & 6 3 6 1 & 0.000325488 & 0.00145197 \\ \hline
3 & 8 3 4 1 & 0.000313537 & 0.00141632 \\ \hline
4 & 7 3 4 2 & 0.000336239 & 0.00156376 \\ \hline
5 & 6 4 5 1 & 0.000333702 & 0.00147671 \\ \hline
\dots & \dots & \dots & \dots \\
\hline
\end{tabular}
\end{center}

Our improved metric was able to confirm that the original Floyd-Steinberg
coefficients were indeed the best possible for raster scan.

For serpentine scan, however, our experiment suggests that
$\frac{1}{16}\{7,4,5,0\}$ is a better choice than the Floyd-Steinberg
coefficients that have nonetheless been widely in use so far (Fig.
\ref{fig:lena7450}).

\begin{figure}
\begin{center}
\includegraphics[width=0.8\textwidth]{lena.eps}
\caption{halftone of \textit{Lena} using serpentine error diffusion and
the optimum coefficients $\frac{1}{16}\{7,4,5,0\}$ that improve
on the standard Floyd-Steinberg coefficients in terms of visual
quality for a given HVS model}
\label{fig:lena7450}
\end{center}
\end{figure}

\section{Conclusion}

We have disclosed an interesting property of error diffusion algorithms
allowing to more precisely measure the quality of such halftoning methods.
Having showed that such quality is often underestimated by usual metrics,
we hope to see even more development in simple error diffusion methods.

Confirming Floyd and Steinberg's 30-year old "trial-and-error" result with our
work is only the beginning: future work may cover more complex HVS models,
for instance by taking into account the angular dependance of the human eye
\cite{sullivan}. And now that we have a proper metric, we plan to improve all
error diffusion methods that may require fine-tuning of their propagation
coefficients.

%
% ---- Bibliography ----
%
\begin{thebibliography}{}
%
\bibitem[1]{bayer}
B. Bayer,
\textit{Color imaging array}.
U.S. patent 3,971,065 (1976)

\bibitem[2]{void1}
R.A. Ulichney (Digital Equipment Corporation),
\textit{Void and cluster apparatus and method for generating dither templates}.
U.S. patent 5,535,020 (1992)

\bibitem[3]{void2}
H. Ancin, A. Bhattacharjya and J. Shu (Seiko Epson Corporation),
\textit{Void-and-cluster dither-matrix generation for better half-tone
uniformity}.
U.S. patent 6,088,512 (1997)

\bibitem[4]{fstein}
R.W. Floyd, L. Steinberg,
\textit{An adaptive algorithm for spatial grey scale}.
Proceedings of the Society of Information Display 17, (1976) 75--77

\bibitem[5]{parfstein}
P. Metaxas,
\textit{Optimal Parallel Error-Diffusion Dithering}.
Color Imaging: Device-Indep. Color, Color Hardcopy, and Graphic Arts IV, Proc.
SPIE 3648, 485--494 (1999)

\bibitem[6]{quality}
T. D. Kite,
\textit{Design and Quality Assessment of Forward and Inverse Error-Diffusion
Halftoning Algorithms}.
PhD thesis, Dept. of ECE, The University of Texas at Austin, Austin, TX, Aug.
1998

\bibitem[7]{halftoning}
R. Ulichney,
\textit{Digital Halftoning}
MIT Press, 1987

\bibitem[8]{spacefilling}
L. Velho and J. Gomes,
\textit{Digital halftoning with space-filling curves}
Computer Graphics (Proceedings of SIGGRAPH 91), 25(4):81--90, 1991

\bibitem[9]{peano}
I.~H. Witten and R.~M. Neal,
\textit{Using peano curves for bilevel display of continuous-tone images}
IEEE Computer Graphics \& Appl., 2:47--52, 1982

\bibitem[10]{nasanen}
R. Nasanen,
\textit{Visibility of halftone dot textures}
IEEE Trans. Syst. Man. Cyb., vol. 14, no. 6, pp. 920--924, 1984

\bibitem[11]{allebach}
M. Analoui and J.~P. Allebach,
\textit{Model-based halftoning using direct binary search}
Proc. of SPIE/IS\&T Symp. on Electronic Imaging Science and Tech.,
February 1992, San Jose, CA, pp. 96--108

\bibitem[12]{mcnamara}
Ann McNamara,
\textit{Visual Perception in Realistic Image Synthesis}
Computer Graphics Forum, vol. 20, no. 4, pp. 211--224, 2001

\bibitem[13]{bhatt}
Bhatt \textit{et al.},
\textit{Direct Binary Search with Adaptive Search and Swap}
\url{http://www.ima.umn.edu/2004-2005/MM8.1-10.05/activities/Wu-Chai/halftone.pdf}

\bibitem[14]{4chan}
moot,
\url{http://www.4chan.org/}

\bibitem[15]{wong}
P.~W. Wong and J.~P. Allebach,
\textit{Optimum error-diffusion kernel design}
Proc. SPIE Vol. 3018, p. 236--242, 1997

\bibitem[16]{ostromoukhov}
Victor Ostromoukhov,
\textit{A Simple and Efficient Error-Diffusion Algorithm}
in Proceedings of SIGGRAPH 2001, in ACM Computer Graphics, Annual Conference
Series, pp. 567--572, 2001

\bibitem[17]{lsmb}
T.~N. Pappas and D.~L. Neuhoff,
\textit{Least-squares model-baed halftoning}
in Proc. SPIE, Human Vision, Visual Proc., and Digital Display III, San Jose,
CA, Feb. 1992, vol. 1666, pp. 165--176

\bibitem[18]{stability}
R. Eschbach, Z. Fan, K.~T. Knox and G. Marcu,
\textit{Threshold Modulation and Stability in Error Diffusion}
in Signal Processing Magazine, IEEE, July 2003, vol. 20, issue 4, pp. 39--50

\bibitem[19]{kite}
T.~D. Kite,
\textit{Design and quality assessment of forward and inverse error diffusion
halftoning algorithms}
Ph.~D. in Electrical Engineering (Image Processing), August 1998

\bibitem[20]{sullivan}
J. Sullivan, R. Miller and G. Pios,
\textit{Image halftoning using a visual model in error diffusion}
J. Opt. Soc. Am. A, vol. 10, pp. 1714--1724, Aug. 1993

\end{thebibliography}

\end{document}


+ 16904
- 0
2008-displacement/serpopt-histo.eps
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 423
- 0
2008-displacement/serpopt-histo.tex Просмотреть файл

@@ -0,0 +1,423 @@
% GNUPLOT: LaTeX picture with Postscript
\begingroup
\makeatletter
\providecommand\color[2][]{%
\GenericError{(gnuplot) \space\space\space\@spaces}{%
Package color not loaded in conjunction with
terminal option `colourtext'%
}{See the gnuplot documentation for explanation.%
}{Either use 'blacktext' in gnuplot or load the package
color.sty in LaTeX.}%
\renewcommand\color[2][]{}%
}%
\providecommand\includegraphics[2][]{%
\GenericError{(gnuplot) \space\space\space\@spaces}{%
Package graphicx or graphics not loaded%
}{See the gnuplot documentation for explanation.%
}{The gnuplot epslatex terminal needs graphicx.sty or graphics.sty.}%
\renewcommand\includegraphics[2][]{}%
}%
\providecommand\rotatebox[2]{#2}%
\@ifundefined{ifGPcolor}{%
\newif\ifGPcolor
\GPcolortrue
}{}%
\@ifundefined{ifGPblacktext}{%
\newif\ifGPblacktext
\GPblacktexttrue
}{}%
% define a \g@addto@macro without @ in the name:
\let\gplgaddtomacro\g@addto@macro
% define empty templates for all commands taking text:
\gdef\gplbacktext{}%
\gdef\gplfronttext{}%
\makeatother
\ifGPblacktext
% no textcolor at all
\def\colorrgb#1{}%
\def\colorgray#1{}%
\else
% gray or color?
\ifGPcolor
\def\colorrgb#1{\color[rgb]{#1}}%
\def\colorgray#1{\color[gray]{#1}}%
\expandafter\def\csname LTw\endcsname{\color{white}}%
\expandafter\def\csname LTb\endcsname{\color{black}}%
\expandafter\def\csname LTa\endcsname{\color{black}}%
\expandafter\def\csname LT0\endcsname{\color[rgb]{1,0,0}}%
\expandafter\def\csname LT1\endcsname{\color[rgb]{0,1,0}}%
\expandafter\def\csname LT2\endcsname{\color[rgb]{0,0,1}}%
\expandafter\def\csname LT3\endcsname{\color[rgb]{1,0,1}}%
\expandafter\def\csname LT4\endcsname{\color[rgb]{0,1,1}}%
\expandafter\def\csname LT5\endcsname{\color[rgb]{1,1,0}}%
\expandafter\def\csname LT6\endcsname{\color[rgb]{0,0,0}}%
\expandafter\def\csname LT7\endcsname{\color[rgb]{1,0.3,0}}%
\expandafter\def\csname LT8\endcsname{\color[rgb]{0.5,0.5,0.5}}%
\else
% gray
\def\colorrgb#1{\color{black}}%
\def\colorgray#1{\color[gray]{#1}}%
\expandafter\def\csname LTw\endcsname{\color{white}}%
\expandafter\def\csname LTb\endcsname{\color{black}}%
\expandafter\def\csname LTa\endcsname{\color{black}}%
\expandafter\def\csname LT0\endcsname{\color{black}}%
\expandafter\def\csname LT1\endcsname{\color{black}}%
\expandafter\def\csname LT2\endcsname{\color{black}}%
\expandafter\def\csname LT3\endcsname{\color{black}}%
\expandafter\def\csname LT4\endcsname{\color{black}}%
\expandafter\def\csname LT5\endcsname{\color{black}}%
\expandafter\def\csname LT6\endcsname{\color{black}}%
\expandafter\def\csname LT7\endcsname{\color{black}}%
\expandafter\def\csname LT8\endcsname{\color{black}}%
\fi
\fi
\setlength{\unitlength}{0.0500bp}%
\begin{picture}(2590.00,2590.00)%
\gplgaddtomacro\gplbacktext{%
}%
\gplgaddtomacro\gplfronttext{%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\color{black}%
\csname LTb\endcsname%
\put(130,104){\makebox(0,0){\strut{}-0.3}}%
\csname LTb\endcsname%
\put(519,104){\makebox(0,0){\strut{}-0.2}}%
\csname LTb\endcsname%
\put(907,104){\makebox(0,0){\strut{}-0.1}}%
\csname LTb\endcsname%
\put(1295,104){\makebox(0,0){\strut{} 0}}%
\csname LTb\endcsname%
\put(1683,104){\makebox(0,0){\strut{} 0.1}}%
\csname LTb\endcsname%
\put(2071,104){\makebox(0,0){\strut{} 0.2}}%
\csname LTb\endcsname%
\put(2460,104){\makebox(0,0){\strut{} 0.3}}%
\csname LTb\endcsname%
\put(-42,2460){\makebox(0,0)[r]{\strut{}-0.1}}%
\csname LTb\endcsname%
\put(-42,2164){\makebox(0,0)[r]{\strut{} 0}}%
\csname LTb\endcsname%
\put(-42,1868){\makebox(0,0)[r]{\strut{} 0.1}}%
\csname LTb\endcsname%
\put(-42,1572){\makebox(0,0)[r]{\strut{} 0.2}}%
\csname LTb\endcsname%
\put(-42,1278){\makebox(0,0)[r]{\strut{} 0.3}}%
\csname LTb\endcsname%
\put(-42,982){\makebox(0,0)[r]{\strut{} 0.4}}%
\csname LTb\endcsname%
\put(-42,686){\makebox(0,0)[r]{\strut{} 0.5}}%
\csname LTb\endcsname%
\put(-42,390){\makebox(0,0)[r]{\strut{} 0.6}}%
}%
\gplbacktext
\put(0,0){\includegraphics{serpopt-histo}}%
\gplfronttext
\end{picture}%
\endgroup

+ 41
- 0
2008-displacement/xy2d.c Просмотреть файл

@@ -0,0 +1,41 @@
#include <stdio.h>

#define N 128

#if 1
#define X1 -.1
#define X2 .4
#define Y1 -.05
#define Y2 .45
#endif

int tab[N][N];

int main(void)
{
float fx, fy;
int x, y;

for(;;)
{
if(fscanf(stdin, "%g %g\n", &fx, &fy) != 2)
break;

x = (N - 0.000001) * (fx - X1) / (X2 - X1);
y = (N - 0.000001) * (fy - Y1) / (Y2 - Y1);
if(x < 0 || y < 0 || x >= N || y >= N)
continue;

tab[x][y]++;
}

for(y = 0; y < N; y++)
{
for(x = 0; x < N; x++)
printf("%g %g %i\n", (float)x * (X2 - X1) / (N - 1) + X1,
(float)y * (Y2 - Y1) / (N - 1) + Y1, tab[x][y]);
printf("\n");
}

return 0;
}

Загрузка…
Отмена
Сохранить