This commit is contained in:
Nguyễn Anh Khoa 2019-05-14 22:37:19 +07:00
commit a43837539e
250 changed files with 26352 additions and 0 deletions

576
.gitignore vendored Normal file
View File

@ -0,0 +1,576 @@
# Created by https://www.gitignore.io/api/julia,jupyternotebook,jupyternotebooks,latex,python,tex,vim
# Edit at https://www.gitignore.io/?templates=julia,jupyternotebook,jupyternotebooks,latex,python,tex,vim
### Julia ###
# Files generated by invoking Julia with --code-coverage
*.jl.cov
*.jl.*.cov
# Files generated by invoking Julia with --track-allocation
*.jl.mem
# System-specific files and directories generated by the BinaryProvider and BinDeps packages
# They contain absolute paths specific to the host computer, and so should not be committed
deps/deps.jl
deps/build.log
deps/downloads/
deps/usr/
deps/src/
# Build artifacts for creating documentation generated by the Documenter package
docs/build/
docs/site/
# File generated by Pkg, the package manager, based on a corresponding Project.toml
# It records a fixed state of all packages used by the project. As such, it should not be
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.toml
### JupyterNotebook ###
.ipynb_checkpoints
*/.ipynb_checkpoints/*
# Remove previous ipynb_checkpoints
# git rm -r .ipynb_checkpoints/
#
### JupyterNotebooks ###
# gitignore template for Jupyter Notebooks
# website: http://jupyter.org/
# Remove previous ipynb_checkpoints
# git rm -r .ipynb_checkpoints/
### LaTeX ###
## Core latex/pdflatex auxiliary files:
*.aux
*.lof
*.log
*.lot
*.fls
*.out
*.toc
*.fmt
*.fot
*.cb
*.cb2
.*.lb
## Intermediate documents:
*.dvi
*.xdv
*-converted-to.*
# these rules might exclude image files for figures etc.
# *.ps
# *.eps
# *.pdf
## Generated if empty string is given at "Please type another file name for output:"
.pdf
## Bibliography auxiliary files (bibtex/biblatex/biber):
*.bbl
*.bcf
*.blg
*-blx.aux
*-blx.bib
*.run.xml
## Build tool auxiliary files:
*.fdb_latexmk
*.synctex
*.synctex(busy)
*.synctex.gz
*.synctex.gz(busy)
*.pdfsync
## Build tool directories for auxiliary files
# latexrun
latex.out/
## Auxiliary and intermediate files from other packages:
# algorithms
*.alg
*.loa
# achemso
acs-*.bib
# amsthm
*.thm
# beamer
*.nav
*.pre
*.snm
*.vrb
# changes
*.soc
# comment
*.cut
# cprotect
*.cpt
# elsarticle (documentclass of Elsevier journals)
*.spl
# endnotes
*.ent
# fixme
*.lox
# feynmf/feynmp
*.mf
*.mp
*.t[1-9]
*.t[1-9][0-9]
*.tfm
#(r)(e)ledmac/(r)(e)ledpar
*.end
*.?end
*.[1-9]
*.[1-9][0-9]
*.[1-9][0-9][0-9]
*.[1-9]R
*.[1-9][0-9]R
*.[1-9][0-9][0-9]R
*.eledsec[1-9]
*.eledsec[1-9]R
*.eledsec[1-9][0-9]
*.eledsec[1-9][0-9]R
*.eledsec[1-9][0-9][0-9]
*.eledsec[1-9][0-9][0-9]R
# glossaries
*.acn
*.acr
*.glg
*.glo
*.gls
*.glsdefs
# gnuplottex
*-gnuplottex-*
# gregoriotex
*.gaux
*.gtex
# htlatex
*.4ct
*.4tc
*.idv
*.lg
*.trc
*.xref
# hyperref
*.brf
# knitr
*-concordance.tex
# TODO Comment the next line if you want to keep your tikz graphics files
*.tikz
*-tikzDictionary
# listings
*.lol
# luatexja-ruby
*.ltjruby
# makeidx
*.idx
*.ilg
*.ind
*.ist
# minitoc
*.maf
*.mlf
*.mlt
*.mtc[0-9]*
*.slf[0-9]*
*.slt[0-9]*
*.stc[0-9]*
# minted
_minted*
*.pyg
# morewrites
*.mw
# nomencl
*.nlg
*.nlo
*.nls
# pax
*.pax
# pdfpcnotes
*.pdfpc
# sagetex
*.sagetex.sage
*.sagetex.py
*.sagetex.scmd
# scrwfile
*.wrt
# sympy
*.sout
*.sympy
sympy-plots-for-*.tex/
# pdfcomment
*.upa
*.upb
# pythontex
*.pytxcode
pythontex-files-*/
# tcolorbox
*.listing
# thmtools
*.loe
# TikZ & PGF
*.dpth
*.md5
*.auxlock
# todonotes
*.tdo
# vhistory
*.hst
*.ver
# easy-todo
*.lod
# xcolor
*.xcp
# xmpincl
*.xmpi
# xindy
*.xdy
# xypic precompiled matrices
*.xyc
# endfloat
*.ttt
*.fff
# Latexian
TSWLatexianTemp*
## Editors:
# WinEdt
*.bak
*.sav
# Texpad
.texpadtmp
# LyX
*.lyx~
# Kile
*.backup
# KBibTeX
*~[0-9]*
# auto folder when using emacs and auctex
./auto/*
*.el
# expex forward references with \gathertags
*-tags.tex
# standalone packages
*.sta
### LaTeX Patch ###
# glossaries
*.glstex
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that dont work, or not
# install all needed dependencies.
#Pipfile.lock
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
### TeX ###
# these rules might exclude image files for figures etc.
# *.ps
# *.eps
# *.pdf
# latexrun
# algorithms
# achemso
# amsthm
# beamer
# changes
# comment
# cprotect
# elsarticle (documentclass of Elsevier journals)
# endnotes
# fixme
# feynmf/feynmp
# glossaries
# gnuplottex
# gregoriotex
# htlatex
# hyperref
# knitr
# TODO Comment the next line if you want to keep your tikz graphics files
# listings
# luatexja-ruby
# makeidx
# minitoc
# minted
# morewrites
# nomencl
# pax
# pdfpcnotes
# sagetex
# scrwfile
# sympy
# pdfcomment
# pythontex
# tcolorbox
# thmtools
# TikZ & PGF
# todonotes
# vhistory
# easy-todo
# xcolor
# xmpincl
# xindy
# xypic precompiled matrices
# endfloat
# Latexian
# WinEdt
# Texpad
# LyX
# Kile
# KBibTeX
# auto folder when using emacs and auctex
# expex forward references with \gathertags
# standalone packages
### TeX Patch ###
# glossaries
### Vim ###
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]
# Session
Session.vim
# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
# End of https://www.gitignore.io/api/julia,jupyternotebook,jupyternotebooks,latex,python,tex,vim

BIN
images/aaa.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

BIN
images/bangdiem.jpeg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

BIN
images/bangdiem.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 590 KiB

BIN
images/dark.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 KiB

BIN
images/f124074.jpg Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 KiB

BIN
images/histogram.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

BIN
images/hough1.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
images/hough_edge.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 299 KiB

BIN
images/projective.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

@ -0,0 +1,528 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"using Formatting\n",
"using StatsBase\n",
"using FFTW\n",
"using Plots"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Histogram normalized\n"
]
},
{
"data": {
"text/plain": [
"5×5 Array{Int64,2}:\n",
" 7 1 1 3 5\n",
" 5 3 7 3 5\n",
" 8 3 7 3 5\n",
" 8 6 7 6 5\n",
" 8 3 8 3 5"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0.08, 0.28, 0.16, 0.08, 0.08, 0.16, 0.04, 0.12]\n",
"Cumsum Histogram normalized\n",
"[0.08, 0.36, 0.52, 0.6, 0.68, 0.84, 0.88, 1.0]\n",
"Prefered Histogram\n",
"[0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125, 0.125]\n",
"Cumsum Prefered Histogram\n",
"[0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0]\n",
"out hist\n",
"[0.125, 0.375, 0.625, 0.625, 0.75, 0.875, 1.0, 1.0]\n",
"out color\n",
"[0, 1, 2, 3, 4, 5, 6, 7]\n",
"[1.0, 3.0, 5.0, 5.0, 6.0, 7.0, 8.0, 8.0]\n",
"\n",
"New Histogram\n",
"[2, 0, 7, 0, 6, 2, 4, 4]\n",
"New Histogram normalized\n",
"[0.08, 0.0, 0.28, 0.0, 0.24, 0.08, 0.16, 0.16]\n",
"New Cumsum Histogram normalized\n",
"[0.08, 0.08, 0.36, 0.36, 0.6, 0.68, 0.84, 1.0]\n"
]
}
],
"source": [
" I_cau1 = [\n",
" 5 0 0 1 2\n",
" 2 1 5 1 2\n",
" 7 1 5 1 2\n",
" 7 4 5 4 3\n",
" 7 1 6 1 3\n",
" ]\n",
"\n",
" hist = fit(Histogram, reshape(I_cau1, (length(I_cau1))), nbins=8).weights\n",
" normalized_hist = hist ./ sum(hist)\n",
" cumsum_normalized_hist = cumsum(normalized_hist)\n",
"\n",
" println(\"Histogram normalized\")\n",
" println(normalized_hist)\n",
" println(\"Cumsum Histogram normalized\")\n",
" println(cumsum_normalized_hist)\n",
"\n",
" prefered_hist = fit(Histogram, 0:7, nbins=8).weights\n",
" normalized_prefered_hist = prefered_hist ./ sum(prefered_hist)\n",
" cumsum_normalized_prefered_hist = cumsum(normalized_prefered_hist)\n",
"\n",
" println(\"Prefered Histogram\")\n",
" println(normalized_prefered_hist)\n",
" println(\"Cumsum Prefered Histogram\")\n",
" println(cumsum_normalized_prefered_hist)\n",
"\n",
" # https://dsp.stackexchange.com/questions/16166/histogram-matching-of-two-images-using-cdf\n",
" out_hist = zeros(8)\n",
" out_color = zeros(8)\n",
"\n",
" for i in 1:length(out_color)\n",
" for k in 1:length(cumsum_normalized_prefered_hist)\n",
" if cumsum_normalized_prefered_hist[k] - cumsum_normalized_hist[i] < 0\n",
" continue\n",
" end\n",
" out_hist[i] = cumsum_normalized_prefered_hist[k]\n",
" out_color[i] = k\n",
" break\n",
" end\n",
" end\n",
"\n",
" println(\"out hist\")\n",
" println(out_hist)\n",
" println(\"out color\")\n",
" println([i for i=0:7])\n",
" println(out_color)\n",
"\n",
" for idx in CartesianIndices(I_cau1)\n",
" newcolor = out_color[I_cau1[idx] + 1]\n",
" I_cau1[idx] = newcolor\n",
" end\n",
"\n",
" display(I_cau1)\n",
" println()\n",
" hist = fit(Histogram, reshape(I_cau1, (length(I_cau1))), nbins=8).weights\n",
" normalized_hist = hist ./ sum(hist)\n",
" cumsum_normalized_hist = cumsum(normalized_hist)\n",
"\n",
" println(\"New Histogram\")\n",
" println(hist)\n",
" println(\"New Histogram normalized\")\n",
" println(normalized_hist)\n",
" println(\"New Cumsum Histogram normalized\")\n",
" println(cumsum_normalized_hist)\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 2400 1600\">\n",
"<defs>\n",
" <clipPath id=\"clip8700\">\n",
" <rect x=\"0\" y=\"0\" width=\"2400\" height=\"1600\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polygon clip-path=\"url(#clip8700)\" points=\"\n",
"0,1600 2400,1600 2400,0 0,0 \n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip8701\">\n",
" <rect x=\"480\" y=\"0\" width=\"1681\" height=\"1600\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polygon clip-path=\"url(#clip8700)\" points=\"\n",
"121.251,1503.47 2321.26,1503.47 2321.26,47.2441 121.251,47.2441 \n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip8702\">\n",
" <rect x=\"121\" y=\"47\" width=\"2201\" height=\"1457\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 342.665,1503.47 342.665,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 844.717,1503.47 844.717,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1346.77,1503.47 1346.77,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1848.82,1503.47 1848.82,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 121.251,1462.26 2321.26,1462.26 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 121.251,1069.75 2321.26,1069.75 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 121.251,677.231 2321.26,677.231 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 121.251,284.716 2321.26,284.716 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 121.251,1503.47 2321.26,1503.47 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 121.251,1503.47 121.251,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 342.665,1503.47 342.665,1481.63 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 844.717,1503.47 844.717,1481.63 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1346.77,1503.47 1346.77,1481.63 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1848.82,1503.47 1848.82,1481.63 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 121.251,1462.26 154.251,1462.26 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 121.251,1069.75 154.251,1069.75 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 121.251,677.231 154.251,677.231 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip8700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 121.251,284.716 154.251,284.716 \n",
" \"/>\n",
"<g clip-path=\"url(#clip8700)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 342.665, 1557.47)\" x=\"342.665\" y=\"1557.47\">0</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip8700)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 844.717, 1557.47)\" x=\"844.717\" y=\"1557.47\">2</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip8700)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1346.77, 1557.47)\" x=\"1346.77\" y=\"1557.47\">4</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip8700)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1848.82, 1557.47)\" x=\"1848.82\" y=\"1557.47\">6</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip8700)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 97.2505, 1479.76)\" x=\"97.2505\" y=\"1479.76\">0</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip8700)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 97.2505, 1087.25)\" x=\"97.2505\" y=\"1087.25\">2</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip8700)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 97.2505, 694.731)\" x=\"97.2505\" y=\"694.731\">4</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip8700)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 97.2505, 302.216)\" x=\"97.2505\" y=\"302.216\">6</text>\n",
"</g>\n",
"<polygon clip-path=\"url(#clip8702)\" points=\"\n",
"242.255,1069.75 242.255,1462.26 443.076,1462.26 443.076,1069.75 242.255,1069.75 242.255,1069.75 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 242.255,1069.75 242.255,1462.26 443.076,1462.26 443.076,1069.75 242.255,1069.75 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip8702)\" points=\"\n",
"493.281,1462.26 493.281,1462.26 694.101,1462.26 694.101,1462.26 493.281,1462.26 493.281,1462.26 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 493.281,1462.26 493.281,1462.26 694.101,1462.26 493.281,1462.26 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip8702)\" points=\"\n",
"744.306,88.4582 744.306,1462.26 945.127,1462.26 945.127,88.4582 744.306,88.4582 744.306,88.4582 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 744.306,88.4582 744.306,1462.26 945.127,1462.26 945.127,88.4582 744.306,88.4582 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip8702)\" points=\"\n",
"995.332,1462.26 995.332,1462.26 1196.15,1462.26 1196.15,1462.26 995.332,1462.26 995.332,1462.26 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 995.332,1462.26 995.332,1462.26 1196.15,1462.26 995.332,1462.26 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip8702)\" points=\"\n",
"1246.36,284.716 1246.36,1462.26 1447.18,1462.26 1447.18,284.716 1246.36,284.716 1246.36,284.716 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1246.36,284.716 1246.36,1462.26 1447.18,1462.26 1447.18,284.716 1246.36,284.716 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip8702)\" points=\"\n",
"1497.38,1069.75 1497.38,1462.26 1698.2,1462.26 1698.2,1069.75 1497.38,1069.75 1497.38,1069.75 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1497.38,1069.75 1497.38,1462.26 1698.2,1462.26 1698.2,1069.75 1497.38,1069.75 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip8702)\" points=\"\n",
"1748.41,677.231 1748.41,1462.26 1949.23,1462.26 1949.23,677.231 1748.41,677.231 1748.41,677.231 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1748.41,677.231 1748.41,1462.26 1949.23,1462.26 1949.23,677.231 1748.41,677.231 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip8702)\" points=\"\n",
"1999.43,677.231 1999.43,1462.26 2200.26,1462.26 2200.26,677.231 1999.43,677.231 1999.43,677.231 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip8702)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1999.43,677.231 1999.43,1462.26 2200.26,1462.26 2200.26,677.231 1999.43,677.231 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip8700)\" points=\"\n",
"1958.43,251.724 2249.26,251.724 2249.26,130.764 1958.43,130.764 \n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip8700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1958.43,251.724 2249.26,251.724 2249.26,130.764 1958.43,130.764 1958.43,251.724 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip8700)\" points=\"\n",
"1982.43,215.436 2126.43,215.436 2126.43,167.052 1982.43,167.052 1982.43,215.436 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip8700)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1982.43,215.436 2126.43,215.436 2126.43,167.052 1982.43,167.052 1982.43,215.436 \n",
" \"/>\n",
"<g clip-path=\"url(#clip8700)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:start;\" transform=\"rotate(0, 2150.43, 208.744)\" x=\"2150.43\" y=\"208.744\">y1</text>\n",
"</g>\n",
"</svg>\n"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# h = fit(Histogram, reshape(I_cau1, (length(I_cau1))), nbins=8)\n",
"bar(0:length(hist)-1, hist)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 2400 1600\">\n",
"<defs>\n",
" <clipPath id=\"clip9100\">\n",
" <rect x=\"0\" y=\"0\" width=\"2400\" height=\"1600\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polygon clip-path=\"url(#clip9100)\" points=\"\n",
"0,1600 2400,1600 2400,0 0,0 \n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip9101\">\n",
" <rect x=\"480\" y=\"0\" width=\"1681\" height=\"1600\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polygon clip-path=\"url(#clip9100)\" points=\"\n",
"188.156,1503.47 2321.26,1503.47 2321.26,47.2441 188.156,47.2441 \n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip9102\">\n",
" <rect x=\"188\" y=\"47\" width=\"2134\" height=\"1457\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 402.838,1503.47 402.838,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 889.621,1503.47 889.621,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1376.4,1503.47 1376.4,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1863.19,1503.47 1863.19,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 188.156,1462.26 2321.26,1462.26 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 188.156,1118.81 2321.26,1118.81 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 188.156,775.359 2321.26,775.359 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 188.156,431.909 2321.26,431.909 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 188.156,88.4582 2321.26,88.4582 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 188.156,1503.47 2321.26,1503.47 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 188.156,1503.47 188.156,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 402.838,1503.47 402.838,1481.63 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 889.621,1503.47 889.621,1481.63 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1376.4,1503.47 1376.4,1481.63 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1863.19,1503.47 1863.19,1481.63 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 188.156,1462.26 220.153,1462.26 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 188.156,1118.81 220.153,1118.81 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 188.156,775.359 220.153,775.359 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 188.156,431.909 220.153,431.909 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 188.156,88.4582 220.153,88.4582 \n",
" \"/>\n",
"<g clip-path=\"url(#clip9100)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 402.838, 1557.47)\" x=\"402.838\" y=\"1557.47\">0</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip9100)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 889.621, 1557.47)\" x=\"889.621\" y=\"1557.47\">2</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip9100)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1376.4, 1557.47)\" x=\"1376.4\" y=\"1557.47\">4</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip9100)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:middle;\" transform=\"rotate(0, 1863.19, 1557.47)\" x=\"1863.19\" y=\"1557.47\">6</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip9100)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 164.156, 1479.76)\" x=\"164.156\" y=\"1479.76\">0.00</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip9100)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 164.156, 1136.31)\" x=\"164.156\" y=\"1136.31\">0.25</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip9100)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 164.156, 792.859)\" x=\"164.156\" y=\"792.859\">0.50</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip9100)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 164.156, 449.409)\" x=\"164.156\" y=\"449.409\">0.75</text>\n",
"</g>\n",
"<g clip-path=\"url(#clip9100)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:end;\" transform=\"rotate(0, 164.156, 105.958)\" x=\"164.156\" y=\"105.958\">1.00</text>\n",
"</g>\n",
"<polygon clip-path=\"url(#clip9102)\" points=\"\n",
"305.481,88.4582 305.481,1462.26 500.194,1462.26 500.194,88.4582 305.481,88.4582 305.481,88.4582 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 305.481,88.4582 305.481,1462.26 500.194,1462.26 500.194,88.4582 305.481,88.4582 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip9102)\" points=\"\n",
"548.872,88.4582 548.872,1462.26 743.586,1462.26 743.586,88.4582 548.872,88.4582 548.872,88.4582 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 548.872,88.4582 548.872,1462.26 743.586,1462.26 743.586,88.4582 548.872,88.4582 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip9102)\" points=\"\n",
"792.264,88.4582 792.264,1462.26 986.977,1462.26 986.977,88.4582 792.264,88.4582 792.264,88.4582 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 792.264,88.4582 792.264,1462.26 986.977,1462.26 986.977,88.4582 792.264,88.4582 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip9102)\" points=\"\n",
"1035.66,88.4582 1035.66,1462.26 1230.37,1462.26 1230.37,88.4582 1035.66,88.4582 1035.66,88.4582 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1035.66,88.4582 1035.66,1462.26 1230.37,1462.26 1230.37,88.4582 1035.66,88.4582 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip9102)\" points=\"\n",
"1279.05,88.4582 1279.05,1462.26 1473.76,1462.26 1473.76,88.4582 1279.05,88.4582 1279.05,88.4582 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1279.05,88.4582 1279.05,1462.26 1473.76,1462.26 1473.76,88.4582 1279.05,88.4582 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip9102)\" points=\"\n",
"1522.44,88.4582 1522.44,1462.26 1717.15,1462.26 1717.15,88.4582 1522.44,88.4582 1522.44,88.4582 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1522.44,88.4582 1522.44,1462.26 1717.15,1462.26 1717.15,88.4582 1522.44,88.4582 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip9102)\" points=\"\n",
"1765.83,88.4582 1765.83,1462.26 1960.54,1462.26 1960.54,88.4582 1765.83,88.4582 1765.83,88.4582 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1765.83,88.4582 1765.83,1462.26 1960.54,1462.26 1960.54,88.4582 1765.83,88.4582 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip9102)\" points=\"\n",
"2009.22,88.4582 2009.22,1462.26 2203.94,1462.26 2203.94,88.4582 2009.22,88.4582 2009.22,88.4582 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip9102)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 2009.22,88.4582 2009.22,1462.26 2203.94,1462.26 2203.94,88.4582 2009.22,88.4582 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip9100)\" points=\"\n",
"1958.43,251.724 2249.26,251.724 2249.26,130.764 1958.43,130.764 \n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1958.43,251.724 2249.26,251.724 2249.26,130.764 1958.43,130.764 1958.43,251.724 \n",
" \"/>\n",
"<polygon clip-path=\"url(#clip9100)\" points=\"\n",
"1982.43,215.436 2126.43,215.436 2126.43,167.052 1982.43,167.052 1982.43,215.436 \n",
" \" fill=\"#009af9\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip9100)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1982.43,215.436 2126.43,215.436 2126.43,167.052 1982.43,167.052 1982.43,215.436 \n",
" \"/>\n",
"<g clip-path=\"url(#clip9100)\">\n",
"<text style=\"fill:#000000; fill-opacity:1; font-family:Arial,Helvetica Neue,Helvetica,sans-serif; font-size:48px; text-anchor:start;\" transform=\"rotate(0, 2150.43, 208.744)\" x=\"2150.43\" y=\"208.744\">y1</text>\n",
"</g>\n",
"</svg>\n"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bar(0:length(prefered_hist)-1, prefered_hist)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.2.0-DEV",
"language": "julia",
"name": "julia-1.2"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

150
julia_notebook/dct.ipynb Normal file
View File

@ -0,0 +1,150 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"using FFTW"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dct (generic function with 1 method)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function dct(f)\n",
" function a(u, N)\n",
" if u == 0\n",
" sqrt(1/N)\n",
" else\n",
" sqrt(2/N)\n",
" end\n",
" end\n",
"\n",
" if ndims(f) == 1\n",
" N = length(f)\n",
" [a(u, N) * sum([x * cos(pi * u * (2i - 1)/ (2N)) for (i, x) in enumerate(f)]) for u=0:N - 1]\n",
" elseif ndims(f) == 2\n",
" N, M = size(f)\n",
" [a(u, N) * a(v, M) * sum([f[x+1, y+1] * cos(pi * u * (2x + 1)/ (2N)) * cos(pi * v * (2y + 1) / (2M)) for x=0:N-1, y=0:M-1]) for u=0:N - 1, v=0:M-1]\n",
" else\n",
" error(\"What the hell man?\")\n",
" end\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8-element Array{Float64,1}:\n",
" 12.727922061357857 \n",
" -6.4423230227051365 \n",
" -1.3322676295501878e-15\n",
" -0.6734548009039396 \n",
" 0.0 \n",
" -0.20090290373599107 \n",
" -2.6645352591003757e-15\n",
" -0.05070232275964859 "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"8-element Array{Float64,1}:\n",
" 12.727922061357857 \n",
" -6.442323022705137 \n",
" 0.0 \n",
" -0.6734548009039407 \n",
" 0.0 \n",
" -0.20090290373599654 \n",
" 0.0 \n",
" -0.050702322759645924"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"8×8 Array{Float64,2}:\n",
" 260.0 -18.2216 -3.51701e-14 … -4.89869e-14 -0.143408 \n",
" -145.773 -3.55271e-15 -1.77636e-15 3.01981e-14 1.02141e-14\n",
" -4.14504e-14 5.32907e-15 0.0 0.0 1.77636e-15\n",
" -15.2385 -3.55271e-15 3.55271e-15 -7.10543e-15 0.0 \n",
" 1.6329e-14 -1.77636e-15 3.55271e-15 -8.88178e-16 9.76996e-15\n",
" -4.54591 -5.32907e-15 0.0 … 0.0 5.9952e-15 \n",
" -5.33831e-14 1.15463e-14 -6.21725e-15 -4.44089e-16 -1.33227e-15\n",
" -1.14726 -2.66454e-15 -4.44089e-15 -2.22045e-15 2.66454e-15"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"8×8 Array{Float64,2}:\n",
" 260.0 -18.2216 0.0 -1.90482 0.0 -0.568239 0.0 -0.143408\n",
" -145.773 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
" -15.2385 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
" -4.54591 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
" 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n",
" -1.14726 0.0 0.0 0.0 0.0 0.0 0.0 0.0 "
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(dct(1:8))\n",
"\n",
"display(FFTW.dct(1:8))\n",
"\n",
"display(dct([(i-1)*8 + j for i=1:8, j=1:8]))\n",
"\n",
"display(FFTW.dct([(i-1)*8 + j for i=1:8,j=1:8]))\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.2.0-DEV",
"language": "julia",
"name": "julia-1.2"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -0,0 +1,211 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"using FFTW"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dft (generic function with 1 method)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function dft(f)\n",
" if ndims(f) == 1\n",
" M = length(f)\n",
" [sum([x * exp(-2im*pi*u * (idx - 1) / M ) for (idx, x) in enumerate(f)]) for u=0:M-1]\n",
" elseif ndims(f) == 2\n",
" M, N = size(f)\n",
" [sum([f[x+1, y+1] * exp(-2im*pi*(u*x/M + v*y/M)) for x=0:M-1, y=0:N-1]) for u=0:M-1, v=0:N-1]\n",
" else\n",
" error(\"Wrong dimension\")\n",
" end\n",
"end "
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"fft2d (generic function with 1 method)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function fft1d(array)\n",
" #= https://en.wikipedia.org/wiki/Cooley%E2%80%93Tukey_FFT_algorithm\n",
" #\n",
" # Xk = Ek + e^(-2pi*i/N * k) * Ok\n",
" #\n",
" # Ek = Event DFT\n",
" # Ok = Odd DFT\n",
" #\n",
" =#\n",
" N = size(array)[1]\n",
" if N == 1\n",
" return array\n",
" elseif N % 2 != 0\n",
" error(\"Wrong dimension\")\n",
" end\n",
"\n",
" # people count from zero while julia counts from 1\n",
" # either way, it should be the same name\n",
" even = fft1d(array[1:2:end])\n",
" odd = fft1d(array[2:2:end])\n",
" w = exp.(-2im * pi / N * [i for i=0:N/2-1])\n",
" half1 = even .+ (odd .* w)\n",
" half2 = even .- (odd .* w)\n",
" vcat(half1,half2)\n",
"end\n",
"\n",
"function fft2d(matrix)\n",
" if ndims(matrix) != 2\n",
" error(\"I dont handle other than 2 dimension matrix\")\n",
" end\n",
" matrix_fft1 = hcat(fft1d.(eachrow(matrix))...)\n",
" hcat(fft1d.(eachrow(matrix_fft1))...)\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8-element Array{Complex{Float64},1}:\n",
" 36.0 + 0.0im \n",
" -4.0 + 9.65685424949238im \n",
" -4.0 + 4.0im \n",
" -4.0 + 1.6568542494923806im\n",
" -4.0 + 0.0im \n",
" -4.0 - 1.6568542494923806im\n",
" -4.0 - 4.0im \n",
" -4.0 - 9.65685424949238im "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"8-element Array{Complex{Float64},1}:\n",
" 36.0 - 0.0im \n",
" -4.0 + 9.65685424949238im \n",
" -4.0 + 4.0im \n",
" -4.0 + 1.6568542494923797im\n",
" -4.0 + 0.0im \n",
" -3.9999999999999996 - 1.6568542494923797im\n",
" -3.9999999999999996 - 4.0im \n",
" -3.9999999999999987 - 9.65685424949238im "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"8-element Array{Complex{Float64},1}:\n",
" 36.0 - 0.0im \n",
" -4.000000000000003 + 9.65685424949238im \n",
" -4.000000000000002 + 3.9999999999999982im \n",
" -4.0 + 1.656854249492386im \n",
" -4.0 - 3.91886975727153e-15im\n",
" -4.0000000000000115 - 1.6568542494923912im \n",
" -4.000000000000018 - 4.000000000000005im \n",
" -3.9999999999999725 - 9.656854249492369im "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"2×8 Array{Complex{Float64},2}:\n",
" 72.0+0.0im -8.0+19.3137im -8.0+8.0im … -8.0-8.0im -8.0-19.3137im\n",
" 0.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"2×8 Array{Complex{Float64},2}:\n",
" 72.0-0.0im -8.0+19.3137im -8.0+8.0im … -8.0-8.0im -8.0-19.3137im\n",
" 0.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im 0.0+0.0im "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"2×8 Array{Complex{Float64},2}:\n",
" 72.0-0.0im -8.0-7.83774e-15im … -8.0-3.39081e-13im\n",
" 0.0-4.40873e-15im 0.0+4.89859e-16im 0.0-1.87804e-13im"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"display(fft(1:8))\n",
"display(fft1d(1:8))\n",
"display(dft(1:8))\n",
"\n",
"\n",
"display(fft([[1:8...] [1:8...]]'))\n",
"display(fft2d([[1:8...] [1:8...]]'))\n",
"display(dft([[1:8...] [1:8...]]'))\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.2.0-DEV",
"language": "julia",
"name": "julia-1.2"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

235
julia_notebook/fiters.ipynb Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

824
julia_notebook/hough.ipynb Normal file

File diff suppressed because one or more lines are too long

409
julia_notebook/jpeg.ipynb Normal file
View File

@ -0,0 +1,409 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"using Images\n",
"using FFTW\n",
"using Formatting"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8×8 Array{Int64,2}:\n",
" 1 2 6 7 15 16 28 29\n",
" 3 5 8 14 17 27 30 43\n",
" 4 9 13 18 26 31 42 44\n",
" 10 12 19 25 32 41 45 54\n",
" 11 20 24 33 40 46 53 55\n",
" 21 23 34 39 47 52 56 61\n",
" 22 35 38 48 51 57 60 62\n",
" 36 37 49 50 58 59 63 64"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"LUMINANCE_QUANTIZATION_TABLE = [\n",
" 16 11 10 16 24 40 51 61 \n",
" 12 12 14 19 26 58 60 55 \n",
" 14 13 16 24 40 57 69 56 \n",
" 14 17 22 29 51 87 80 62 \n",
" 18 22 37 56 68 109 103 77 \n",
" 24 35 55 64 81 104 113 92 \n",
" 49 64 78 87 103 121 120 101 \n",
" 72 92 95 98 112 100 103 99 \n",
" ]\n",
"\n",
"ZIGZAG = [\n",
" 0 1 5 6 14 15 27 28\n",
" 2 4 7 13 16 26 29 42\n",
" 3 8 12 17 25 30 41 43\n",
" 9 11 18 24 31 40 44 53\n",
" 10 19 23 32 39 45 52 54\n",
" 20 22 33 38 46 51 55 60\n",
" 21 34 37 47 50 56 59 61\n",
" 35 36 48 49 57 58 62 63\n",
" ] .+ 1"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"to_zigzag (generic function with 1 method)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"function to_zigzag(block)\n",
" out_block = zeros(eltype(block), size(ZIGZAG))\n",
" for idx in CartesianIndices(ZIGZAG)\n",
" out_block[ZIGZAG[idx]] = block[idx]\n",
" # display(out_block)\n",
" end\n",
" reshape(out_block, (1,64))\n",
"end"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"720×1280 Array{Float32,2}:\n",
" 39.2166 39.4639 39.4639 39.0577 … 37.4843 37.4843 37.4843 37.4843\n",
" 39.4639 39.4639 39.0577 39.0577 37.4843 37.4843 37.4843 37.4843\n",
" 39.4639 39.0577 39.0577 39.0577 37.4843 37.4843 37.4843 37.4843\n",
" 39.0577 39.0577 39.0577 39.9165 38.0348 37.4843 37.4843 37.4843\n",
" 39.0577 39.9165 39.9165 39.9165 38.0348 37.176 37.4843 37.4843\n",
" 39.9165 39.9165 39.9165 40.1639 … 38.0348 38.0348 37.4843 37.4843\n",
" 39.9165 39.9165 39.9165 40.1639 38.0348 38.0348 37.4843 37.4843\n",
" 39.9165 39.9165 39.9165 40.1639 38.1327 38.0348 38.3432 37.4843\n",
" 39.4639 39.4639 39.9165 40.1639 39.4493 38.3432 38.0348 38.5484\n",
" 39.4639 39.4639 39.0577 40.1639 39.4493 38.3432 38.0348 38.5484\n",
" 39.4639 39.4639 39.0577 40.1639 … 39.4493 38.5905 38.0348 38.0348\n",
" 39.4639 39.0577 39.0577 40.1639 39.1925 39.4493 38.5905 38.0348\n",
" 39.0577 39.0577 39.0577 40.1639 39.1925 39.4493 38.5905 38.5905\n",
" ⋮ ⋱ \n",
" 30.5854 31.1969 31.7105 32.261 37.663 37.663 37.663 37.663 \n",
" 31.3927 31.3927 31.4021 31.3927 38.2135 38.2135 38.2135 38.4608\n",
" 31.64 31.64 31.64 30.5244 … 38.4608 38.4608 39.3196 39.3196\n",
" 31.3738 30.515 30.515 29.6562 38.4608 38.4608 39.3196 39.3196\n",
" 28.751 30.7666 30.7202 27.99 39.3196 39.3196 39.3196 39.3196\n",
" 29.049 31.4253 28.8394 30.0572 38.4608 38.4608 38.4608 38.4608\n",
" 29.6141 29.3899 26.2063 32.4233 38.2135 38.2135 38.2135 38.2135\n",
" 29.7077 29.1984 33.8936 25.0958 … 37.663 37.663 37.663 37.663 \n",
" 28.7364 32.2369 29.0447 29.6003 37.663 37.663 37.663 37.663 \n",
" 32.5504 24.4422 29.8614 31.7749 37.663 37.663 37.663 37.663 \n",
" 29.876 31.5507 29.8468 28.1386 37.3546 37.3546 37.3546 37.3546\n",
" 31.5645 30.7108 31.397 29.6708 38.2135 38.2135 38.2135 37.3546"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"8×8 Array{Float32,2}:\n",
" 55.4277 55.736 54.8772 54.8772 55.736 55.736 55.736 55.736 \n",
" 56.2866 56.2866 57.4537 57.4537 56.5949 55.736 55.736 55.736 \n",
" 57.9948 57.9948 57.1359 56.0813 55.2225 55.2225 55.736 56.5949\n",
" 58.2421 58.2421 58.2421 58.2421 58.2421 58.0463 56.9401 56.9401\n",
" 57.3833 58.4894 61.0659 62.7836 63.6424 61.6774 57.7989 55.2225\n",
" 58.4894 58.4894 58.9326 60.6502 61.5091 61.0659 58.2421 56.0813\n",
" 61.0659 59.6935 59.7914 59.1799 58.9326 58.0832 58.2421 57.7989\n",
" 61.0659 62.27 64.0855 64.0246 62.3679 59.8009 58.2421 56.9401"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"8×8 Array{Float32,2}:\n",
" -71.5723 -71.264 -72.1228 -72.1228 … -71.264 -71.264 -71.264 \n",
" -70.7134 -70.7134 -69.5463 -69.5463 -71.264 -71.264 -71.264 \n",
" -69.0052 -69.0052 -69.8641 -70.9187 -71.7775 -71.264 -70.4051\n",
" -68.7579 -68.7579 -68.7579 -68.7579 -68.9537 -70.0599 -70.0599\n",
" -69.6167 -68.5106 -65.9341 -64.2164 -65.3226 -69.2011 -71.7775\n",
" -68.5106 -68.5106 -68.0674 -66.3498 … -65.9341 -68.7579 -70.9187\n",
" -65.9341 -67.3065 -67.2086 -67.8201 -68.9168 -68.7579 -69.2011\n",
" -65.9341 -64.73 -62.9145 -62.9754 -67.1991 -68.7579 -70.0599"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"8×8 Array{Float32,2}:\n",
" -550.578 4.7784 … 0.00653681 0.205445 0.212533 \n",
" -13.5756 -2.92463 -0.472033 -0.130214 -0.218505 \n",
" -1.48771 1.21404 0.279535 -0.391432 0.330444 \n",
" -0.673342 -2.97597 -0.222817 -0.0539551 -0.0560064\n",
" 3.04324 0.102968 -0.474424 -0.0202312 0.0131407\n",
" -3.61937 -0.509858 … -0.253103 -0.123185 -0.0314786\n",
" -0.353786 0.00731296 -0.460769 -0.278703 -0.466107 \n",
" -0.00664318 0.52792 -0.0775939 -0.022749 0.307393 "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"8×8 Array{Int32,2}:\n",
" -34 0 -1 0 0 0 0 0\n",
" -1 0 0 0 0 0 0 0\n",
" 0 0 0 0 0 0 0 0\n",
" 0 0 0 0 0 0 0 0\n",
" 0 0 0 0 0 0 0 0\n",
" 0 0 0 0 0 0 0 0\n",
" 0 0 0 0 0 0 0 0\n",
" 0 0 0 0 0 0 0 0"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"1×64 Array{Int32,2}:\n",
" -34 0 -1 0 0 -1 0 0 0 0 0 … 0 0 0 0 0 0 0 0 0 0 0 0"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"14400-element Array{Any,1}:\n",
" -44\n",
" -43\n",
" -43\n",
" -42\n",
" -42\n",
" -42\n",
" -41\n",
" -41\n",
" -41\n",
" -41\n",
" -40\n",
" -40\n",
" -39\n",
" ⋮\n",
" -42\n",
" -41\n",
" -41\n",
" -41\n",
" -41\n",
" -42\n",
" -43\n",
" -43\n",
" -44\n",
" -44\n",
" -44\n",
" -45"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"14400-element Array{Any,1}:\n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" ⋮ \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[-1, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]\n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[1, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] \n",
" Int32[0, 0, 0, 0, 0, 0, 0, 0, 0, 0 … 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] "
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"720×1280 Array{Float32,2}:\n",
" 141.368 141.226 141.226 141.956 … 143.855 143.855 143.855 143.855\n",
" 141.226 141.226 141.956 141.956 143.855 143.855 143.855 143.855\n",
" 141.226 141.956 141.956 141.956 143.855 143.855 143.855 143.855\n",
" 141.956 141.956 141.956 141.956 145.025 143.855 143.855 143.855\n",
" 141.956 141.956 141.956 141.956 145.025 145.025 143.855 143.855\n",
" 141.956 141.956 141.956 141.813 … 145.025 145.025 143.855 143.855\n",
" 141.956 141.956 141.956 141.813 145.025 145.025 143.855 143.855\n",
" 141.956 141.956 141.956 141.813 145.464 145.025 143.855 143.855\n",
" 141.226 141.226 141.956 141.813 143.713 143.855 145.025 144.728\n",
" 141.226 141.226 141.956 141.813 143.713 143.855 145.025 144.728\n",
" 141.226 141.226 141.956 141.813 … 143.713 143.713 145.025 145.025\n",
" 141.226 141.956 141.956 141.813 143.861 143.713 143.713 145.025\n",
" 141.956 141.956 141.956 141.813 143.861 143.713 143.713 143.713\n",
" ⋮ ⋱ \n",
" 130.487 130.63 130.333 131.503 138.299 138.299 138.299 138.299\n",
" 131.508 131.508 131.503 131.508 139.469 139.469 139.469 139.326\n",
" 131.366 131.366 131.366 131.514 … 139.326 139.326 139.326 139.326\n",
" 131.519 131.519 131.519 131.519 139.326 139.326 139.326 139.326\n",
" 130.059 133.853 132.392 130.498 139.326 139.326 139.326 139.326\n",
" 133.853 130.498 130.503 133.271 139.326 139.326 139.326 139.326\n",
" 132.535 131.673 134.006 134.879 139.469 139.469 139.469 139.469\n",
" 130.498 133.271 135.022 131.673 … 138.299 138.299 138.299 138.299\n",
" 132.546 133.995 131.376 130.064 138.299 138.299 138.299 138.299\n",
" 130.344 132.546 132.392 133.271 138.299 138.299 138.299 138.299\n",
" 129.905 132.409 134.879 134.874 139.469 139.469 139.469 139.469\n",
" 134.879 132.398 130.514 129.032 139.469 139.469 139.469 139.469"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"720×1280 Array{Float32,2}:\n",
" 115.448 114.641 114.641 114.938 … 115.459 115.459 115.459 115.459\n",
" 114.641 114.641 114.938 114.938 115.459 115.459 115.459 115.459\n",
" 114.641 114.938 114.938 114.938 115.459 115.459 115.459 115.459\n",
" 114.938 114.938 114.938 114.938 115.684 115.459 115.459 115.459\n",
" 114.938 114.938 114.938 114.938 115.684 115.684 115.459 115.459\n",
" 114.938 114.938 114.938 114.131 … 115.684 115.684 115.459 115.459\n",
" 114.938 114.938 114.938 114.131 115.684 115.684 115.459 115.459\n",
" 114.938 114.938 114.938 114.131 115.612 115.684 115.459 115.459\n",
" 114.641 114.641 114.938 114.131 114.652 115.459 115.684 116.562\n",
" 114.641 114.641 114.938 114.131 114.652 115.459 115.684 116.562\n",
" 114.641 114.641 114.938 114.131 … 114.652 114.652 115.684 115.684\n",
" 114.641 114.938 114.938 114.131 114.213 114.652 114.652 115.684\n",
" 114.938 114.938 114.938 114.131 114.213 114.652 114.652 114.652\n",
" ⋮ ⋱ \n",
" 128.011 128.818 129.696 129.921 114.702 114.702 114.702 114.702\n",
" 128.675 128.675 129.921 128.675 114.927 114.927 114.927 114.12 \n",
" 127.868 127.868 127.868 127.429 … 114.12 114.12 114.12 114.12 \n",
" 126.182 126.182 126.182 126.182 114.12 114.12 114.12 114.12 \n",
" 125.59 127.878 127.286 125.518 114.12 114.12 114.12 114.12 \n",
" 127.878 125.518 124.272 127.143 114.12 114.12 114.12 114.12 \n",
" 128.093 124.497 126.193 127.296 114.927 114.927 114.927 114.927\n",
" 125.518 127.143 128.103 124.497 … 114.702 114.702 114.702 114.702\n",
" 125.6 128.685 125.375 124.343 114.702 114.702 114.702 114.702\n",
" 127.204 125.6 127.286 127.143 114.702 114.702 114.702 114.702\n",
" 127.275 123.547 127.296 128.543 114.927 114.927 114.927 114.927\n",
" 127.296 126.04 121.78 126.172 114.927 114.927 114.927 114.927"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"img = load(\"../images/f124074.jpg\")\n",
"img_ycbcr = channelview(YCbCr.(img))\n",
"\n",
"for c in 1:3\n",
" channel = img_ycbcr[c,:,:]\n",
" row, col = size(channel)\n",
"\n",
" display(channel)\n",
" \n",
" DC = []\n",
" AC = []\n",
"\n",
" for i in 1:8:row\n",
" for j in 1:8:col\n",
" block = channel[i:i+7, j:j+7]\n",
"\n",
" block_shifted = block .- 127\n",
" block_dct = FFTW.dct(block_shifted)\n",
"\n",
" block_quantization = round.(Int32, block_dct ./ LUMINANCE_QUANTIZATION_TABLE)\n",
" # block_quantization = block_dct ./ LUMINANCE_QUANTIZATION_TABLE\n",
" block_zigzag = to_zigzag(block_quantization)\n",
"\n",
" if c == 1 && i == 1 + 8*10 && j == 1 + 8*3\n",
" display(block)\n",
" display(block_shifted)\n",
" display(block_dct)\n",
" display(block_quantization)\n",
" display(block_zigzag)\n",
" end\n",
"\n",
" # block_zigzag = collect(block_zigzag)\n",
" push!(DC, block_zigzag[1])\n",
" push!(AC, block_zigzag[2:end])\n",
" end\n",
" end\n",
"\n",
" if c == 1\n",
" display(DC)\n",
" display(AC)\n",
" end\n",
"end\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.2.0-DEV",
"language": "julia",
"name": "julia-1.2"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -0,0 +1,285 @@
using Images
using Formatting
using StatsBase
using FFTW
function genMatrix(what, params...)
params = map(x->parse(Float32, x), params)
M = zeros(Float32, (3,3))
M[3, 3] = 1
if what == "scale"
if length(params) < 2
error("Scale requires two parameter (x, y)")
end
x, y = params
printfmt("Scale with x = {}; y = {}\n", x, y)
M[1, 1] = x
M[2, 2] = y
elseif what == "translate"
if length(params) < 2
error("Translate requires two parameter (dx, dy)")
end
dx, dy = params
M[1, 1] = 1
M[2, 2] = 1
M[1, 3] = dx
M[2, 3] = dy
elseif what == "rotate"
if length(params) < 1
error("Rotate requires one parameter (theta, isRadian: true)")
end
theta = params[1]
isRadian = 1
if length(params) >= 2
isRadian = params[2]
end
if isRadian == 1
M[1, 1] = cos(theta)
M[1, 2] = -sin(theta)
M[2, 1] = sin(theta)
M[2, 2] = cos(theta)
else
M[1, 1] = cosd(theta)
M[1, 2] = -sind(theta)
M[2, 1] = sind(theta)
M[2, 2] = cosd(theta)
end
elseif what == "shear"
if length(params) < 4
error("Rotate requires four parameter (a, b, c, d)")
end
a,b,c,d = params
M[1, 1] = a
M[1, 2] = b
M[2, 1] = c
M[2, 2] = d
else
error(printfmt("Matrix of {} is unknown\n", what))
end
M
end
function conv(in, kernel)
row, col = size(in)
krow, kcol = size(kernel)
rowPad, colPad = round(Int32, krow/2, RoundDown),round(Int32, kcol/2, RoundDown)
# feature_maps = zeros(eltype(in), (row + rowPad * 2, col + colPad * 2))
feature_maps = [
5 5 0 0 1 2 2
5 5 0 0 1 2 2
2 2 1 5 1 2 2
7 7 1 5 1 2 2
7 7 4 5 4 3 3
7 7 1 6 1 3 3
7 7 1 6 1 3 3
]
out = zeros(eltype(in), size(in))
colStartIdx = colPad + 1
colEndIdx = colPad + col
rowStartIdx = rowPad + 1
rowEndIdx = rowPad + row
# setup feature map and kernel
feature_maps[rowStartIdx:rowEndIdx, colStartIdx:colEndIdx] = in
kernel = rot180(kernel)
for i in rowStartIdx:rowEndIdx
for j in colStartIdx:colEndIdx
part = feature_maps[i-rowPad:i-rowPad+krow-1, j-colPad:j-colPad+kcol-1]
v = sum(part .* kernel)
if (v < 0)
v = 0
elseif (v > 1)
v = 1
end
out[i-rowPad,j-colPad] = v
end
end
# TODO: normalize output
out ./ maximum(out)
end
if abspath(PROGRAM_FILE) == @__FILE__
I_cau1 = [
5 0 0 1 2
2 1 5 1 2
7 1 5 1 2
7 4 5 4 3
7 1 6 1 3
]
sobel_x_kernel = [
-1 0 1
-2 0 2
-1 0 1
]
sobel_y_kernel = rotl90(sobel_x_kernel)
# I_Gx = imfilter(I_cau1, centered(reflect(sobel_x_kernel)), "reflect")
# I_Gy = imfilter(I_cau1, centered(reflect(sobel_y_kernel)), "reflect")
I_Gx = conv(I_cau1, sobel_x_kernel)
I_Gy = conv(I_cau1, sobel_y_kernel)
# I_G = round.(Int32, sqrt.((I_Gx .^ 2) .* (I_Gy .^ 2)))
printfmtln("Vector G(0,0) = ({}, {})", I_Gx[1,1], I_Gy[1,1])
printfmtln("Vector G(1,1) = ({}, {})", I_Gx[2,2], I_Gy[2,2])
printfmtln("Vector G(0,3) = ({}, {})", I_Gx[1,4], I_Gy[1,4])
hist = fit(Histogram, reshape(I_cau1, (length(I_cau1))), nbins=8).weights
normalized_hist = hist ./ sum(hist)
cumsum_normalized_hist = cumsum(normalized_hist)
println("Histogram normalized")
println(normalized_hist)
println("Cumsum Histogram normalized")
println(cumsum_normalized_hist)
prefered_hist = fit(Histogram, 0:7, nbins=8).weights
normalized_prefered_hist = prefered_hist ./ sum(prefered_hist)
cumsum_normalized_prefered_hist = cumsum(normalized_prefered_hist)
println("Prefered Histogram")
println(normalized_prefered_hist)
println("Cumsum Prefered Histogram")
println(cumsum_normalized_prefered_hist)
# https://dsp.stackexchange.com/questions/16166/histogram-matching-of-two-images-using-cdf
out_hist = zeros(8)
out_color = zeros(8)
for i in 1:length(out_color)
for k in 1:length(cumsum_normalized_prefered_hist)
if cumsum_normalized_prefered_hist[k] - cumsum_normalized_hist[i] < 0
continue
end
out_hist[i] = cumsum_normalized_prefered_hist[k]
out_color[i] = k
break
end
end
println("out hist")
println(out_hist)
println("out color")
println([i for i=0:7])
println(out_color)
for idx in CartesianIndices(I_cau1)
newcolor = out_color[I_cau1[idx] + 1]
I_cau1[idx] = newcolor
end
display(I_cau1)
println()
hist = fit(Histogram, reshape(I_cau1, (length(I_cau1))), nbins=8).weights
normalized_hist = hist ./ sum(hist)
cumsum_normalized_hist = cumsum(normalized_hist)
println("New Histogram normalized")
println(normalized_hist)
println("New Cumsum Histogram normalized")
println(cumsum_normalized_hist)
println("==============================")
fx = [1 3]
N = length(fx)
dft_fx = [exp(-2im*pi*u*x / N) for u=0:N-1, x=0:N-1]
fx_dft = dft_fx * fx'
println("Ma tran he co dft")
display(dft_fx)
println()
println("Bien doi fft cua fx = [1, 3]")
println(fx_dft)
println("==============================")
function alpha(u, N)
if u == 0
sqrt(1/N)
else
sqrt(2/N)
end
end
fx = [1 0 1 0] # pad with 0
N = 4
dct_fx = [alpha(u, N) * cos((2*x + 1) * u * pi / (2N)) for u=0:N-1, x=0:N - 1]
fx_dct = dct_fx * fx'
println("Ma tran he co dct voi N = 4 tren fx")
display(dct_fx)
println()
println("Bien doi dct 4 diem cua fx = [1, 0, 1]")
println(fx_dct)
println("==============================")
M_move_00 = genMatrix("translate", "-3", "-3")
M_rotate_25 = genMatrix("rotate", "45", "0")
M_move_33 = genMatrix("translate", "3", "3")
M = M_move_33 * M_rotate_25 * M_move_00
println("Ma tran M de xoay hinh xung quanh (3,3)")
display(M)
println()
new_idx = round.(Int32, inv(M) * [2 3 1]')
printfmtln("Toa do Io(2, 3) co gia tri bang voi I({}, {})", new_idx[1:2]...)
end
# SAMPLE OUTPUT
#=
Vector G(0,0) = (0.0, 0.0)
Vector G(1,1) = (1.0, 1.0)
Vector G(0,3) = (1.0, 0.0)
Histogram
Dict{Int64,Float64} with 8 entries:
0 => 0.08
4 => 0.08
7 => 0.12
2 => 0.16
3 => 0.08
5 => 0.16
6 => 0.04
1 => 0.28
==============================
Ma tran he co dft
2×2 Array{Complex{Float64},2}:
1.0-0.0im 1.0-0.0im
1.0-0.0im -1.0-1.22465e-16im
Bien doi fft cua fx = [1, 3]
2×1 Array{Complex{Float64},2}:
4.0 + 0.0im
-2.0 - 3.6739403974420594e-16im
==============================
Ma tran he co dct voi N = 4 tren fx
4×3 Array{Float64,2}:
0.5 0.5 0.5
0.653281 0.270598 -0.270598
0.5 -0.5 -0.5
0.270598 -0.653281 0.653281
Bien doi dct 4 diem cua fx = [1, 0, 1]
4×1 Array{Float64,2}:
1.0
0.3826834323650898
0.0
0.9238795325112867
==============================
Ma tran M de xoay hinh xung quanh (3,3)
3×3 Array{Float32,2}:
0.707107 -0.707107 3.0
0.707107 0.707107 -1.24264
0.0 0.0 1.0
Toa do Io(2, 3) co gia tri bang voi I(2, 4)
=#

View File

View File

@ -0,0 +1,77 @@
module Convole
using Formatting
export conv
function padSize(kernelSize)
row, col = kernelSize
round(Int32, row/2, RoundDown),round(Int32, col/2, RoundDown)
end
function conv(in, kernel)
row, col = size(in)
krow, kcol = size(kernel)
rowPad, colPad = padSize(size(kernel))
feature_maps = zeros(eltype(in), (row + rowPad * 2, col + colPad * 2))
out = zeros(eltype(in), size(in))
colStartIdx = colPad + 1
colEndIdx = colPad + col
rowStartIdx = rowPad + 1
rowEndIdx = rowPad + row
# setup feature map and kernel
feature_maps[rowStartIdx:rowEndIdx, colStartIdx:colEndIdx] = in
kernel = rot180(kernel)
for i in rowStartIdx:rowEndIdx
for j in colStartIdx:colEndIdx
part = feature_maps[i-rowPad:i-rowPad+krow-1, j-colPad:j-colPad+kcol-1]
v = sum(part .* kernel)
if (v < 0)
v = 0
elseif (v > 1)
v = 1
end
out[i-rowPad,j-colPad] = v
end
end
# TODO: normalize output
out ./ maximum(out)
end
end
if abspath(PROGRAM_FILE) == @__FILE__
using .Convole
in = [1 2 3; 4 5 6; 7 8 9]
kernel = [-1 -2 -1; 0 0 0; 1 2 1]
println("Input")
display(in)
println()
println("Kernel")
display(kernel)
println()
println("Output")
display(conv(in, kernel))
println()
if (length(ARGS) < 1)
return
end
println("image convolution")
gaussian_kernel = [
1 4 7 4 1
4 16 26 16 4
7 26 41 26 7
4 16 26 16 4
1 4 7 4 1
] ./ 273
img = load(ARGS[1])
img_gray = Gray.(img)
img_blur = conv(img_gray, gaussian_kernel)
save("img_blur_convole.jpg", img_blur)
end

33
julia_scripts/dct.jl Normal file
View File

@ -0,0 +1,33 @@
using FFTW
function dct(f)
function a(u, N)
if u == 0
sqrt(1/N)
else
sqrt(2/N)
end
end
if ndims(f) == 1
N = length(f)
[a(u, N) * sum([x * cos(pi * u * (2i - 1)/ (2N)) for (i, x) in enumerate(f)]) for u=0:N - 1]
elseif ndims(f) == 2
N, M = size(f)
[a(u, N) * a(v, M) * sum([f[x+1, y+1] * cos(pi * u * (2x + 1)/ (2N)) * cos(pi * v * (2y + 1) / (2M)) for x=0:N-1, y=0:M-1]) for u=0:N - 1, v=0:M-1]
else
error("What the hell man?")
end
end
if abspath(PROGRAM_FILE) == @__FILE__
display(dct(1:8))
println()
display(FFTW.dct(1:8))
println()
display(dct([(i-1)*8 + j for i=1:8, j=1:8]))
println()
display(FFTW.dct([(i-1)*8 + j for i=1:8,j=1:8]))
println()
end

93
julia_scripts/fft.jl Normal file
View File

@ -0,0 +1,93 @@
include("showpicture.jl")
using FFTW
using Images
using ImageView
using Plots
using .Showpicture
function dft(f)
if ndims(f) == 1
M = length(f)
[sum([x * exp(-2im*pi*u * (idx - 1) / M ) for (idx, x) in enumerate(f)]) for u=0:M-1]
elseif ndims(f) == 2
M, N = size(f)
[sum([f[x+1, y+1] * exp(-2im*pi*(u*x/M + v*y/M)) for x=0:M-1, y=0:N-1]) for u=0:M-1, v=0:N-1]
else
error("Wrong dimension")
end
# mesh = [i * j for i=0:N-1, j=0:N-1]
# W = exp.(-2im * pi * mesh / N)
# W * f
end
function fft1d(array)
#= https://en.wikipedia.org/wiki/Cooley%E2%80%93Tukey_FFT_algorithm
#
# Xk = Ek + e^(-2pi*i/N * k) * Ok
#
# Ek = Event DFT
# Ok = Odd DFT
#
=#
N = size(array)[1]
if N == 1
return array
elseif N % 2 != 0
error("Wrong dimension")
end
# people count from zero while julia counts from 1
# either way, it should be the same name
even = fft1d(array[1:2:end])
odd = fft1d(array[2:2:end])
w = exp.(-2im * pi / N * [i for i=0:N/2-1])
half1 = even .+ (odd .* w)
half2 = even .- (odd .* w)
vcat(half1,half2)
end
function fft2d(matrix)
if ndims(matrix) != 2
error("I dont handle other than 2 dimension matrix")
end
matrix_fft1 = hcat(fft1d.(eachrow(matrix))...)
hcat(fft1d.(eachrow(matrix_fft1))...)
end
if abspath(PROGRAM_FILE) == @__FILE__
if (length(ARGS) < 1)
println("fft library")
display(fft(1:8))
println()
println("fft own implemenation")
display(fft1d(1:8))
println()
println("DFT1D")
display(dft(1:8))
println()
println("====================")
println("fft2d library")
display(fft([[1:8...] [1:8...]]'))
println()
println("fft2d own implemenation")
display(fft2d([[1:8...] [1:8...]]'))
println()
println("DFT2D")
display(dft([[1:8...] [1:8...]]'))
println()
else
img = load(ARGS[1])
img_gray = Float32.(Gray.(img))
# img_fft = fft2d(Gray.(img))
img_fft = fftshift(fft(img_gray))
normalize = log.(abs.(img_fft)) .+ 1
showpicture(normalize)
end
end

68
julia_scripts/filter.jl Normal file
View File

@ -0,0 +1,68 @@
using FileIO
using Images, ImageView
using Colors
using Formatting
using FFTW
function idealFilter(r, isLow, threshold)
if isLow
r .<= threshold
else
r .> threshold
end
end
function gaussianFilter(r, isLow, threshold)
if isLow
exp.(-(r.^2) ./ 2*(threshold^2))
else
1 .- exp.(-(r.^2) ./ 2*(threshold^2))
end
end
function butterworthFilter(r, isLow, threshold, n)
if isLow
1 ./ (1 .+ (r ./ threshold) .^ (2 * n))
else
1 ./ (1 .+ (threshold ./ r) .^ (2 * n))
end
end
function laplacianFilter(r, isLow, threshold)
-r.^2
end
function filterFactory(name, shape, isLow, threshold, other)
n, m = shape
r = sqrt.([i^2 + j^2 for i=-n/2:n/2-1, j=-m/2:m/2-1])
if name == "Ideal"
idealFilter(r, isLow, threshold)
elseif name == "Gaussian"
gaussianFilter(r, isLow, threshold)
elseif name == "Butterworth"
butterworthFilter(r, isLow, threshold, other)
elseif name == "Laplacian"
laplacianFilter(r, isLow, threshold)
else
error("Filter not found")
end
end
if abspath(PROGRAM_FILE) == @__FILE__
imagePath = ARGS[1]
filterName = ARGS[2]
filterLow = ARGS[3] .== "true"
filterThreshold = parse(UInt32, ARGS[4])
filterOther = parse(UInt32, ARGS[5])
img = load(imagePath)
img_gray = Float32.(Gray.(img))
filter = filterFactory(filterName, size(img_gray), filterLow, filterThreshold, filterOther)
#= display(filter) =#
#= println() =#
img_fft = fftshift(fft(img_gray))
out = abs.(real.(ifft(img_fft .* filter)))
filename = format("filter_{}_{}_{}_{}.png", imagePath, filterName, filterLow, filterThreshold)
save(filename, out)
end

173
julia_scripts/geometric.jl Normal file
View File

@ -0,0 +1,173 @@
using FileIO
using Images, ImageView
using Formatting
function roundAround(x, low, high)
if x < low
low
elseif x > high
high
else
round(Int32, x)
end
end
function forwardTransform(M, P)
n, m = size(P)
out = zeros(eltype(P), n, m)
for index in CartesianIndices(P)
x, y = Tuple(index)
newindex = M * [x; y; 1]
x1 = roundAround(newindex[1], 1, n)
y1 = roundAround(newindex[2], 1, m)
out[x1, y1] = P[x, y]
end
out
end
function backwardTransform(algo, M, P)
M = inv(M)
n, m = size(P)
out = zeros(eltype(P), n, m)
for index in CartesianIndices(out)
x, y = Tuple(index)
sourceIndex = M * [x; y; 1]
sourceIndex ./= sourceIndex[3]
x1 = round(Int32, sourceIndex[1])
y1 = round(Int32, sourceIndex[2])
#= if ((x == 1 && y == 1) || =#
#= (x == 1 && y == m) || =#
#= (x == n && y == 1) || =#
#= (x == n && y == m)) =#
#= println("AAAAAAAAAAA") =#
#= display([x; y; 1]) =#
#= println() =#
#= display(sourceIndex) =#
#= println() =#
#= end =#
if (x1 < 1 || y1 < 1 || x1 > n || y1 > m)
continue
end
if (sourceIndex[1] > n || sourceIndex[2] > m)
continue
end
out[x, y] = P[x1, y1]
end
out
end
function genMatrix(what, params...)
params = map(x->parse(Float32, x), params)
M = zeros(Float32, (3,3))
M[3, 3] = 1
if what == "scale"
if length(params) < 2
error("Scale requires two parameter (x, y)")
end
x, y = params
printfmt("Scale with x = {}; y = {}\n", x, y)
M[1, 1] = x
M[2, 2] = y
elseif what == "translate"
if length(params) < 2
error("Translate requires two parameter (dx, dy)")
end
dx, dy = params
M[1, 1] = 1
M[2, 2] = 1
M[1, 3] = dx
M[2, 3] = dy
elseif what == "rotate"
if length(params) < 1
error("Rotate requires one parameter (theta, isRadian: true)")
end
theta = params[1]
isRadian = 1
if length(params) >= 2
isRadian = params[2]
end
if isRadian == 1
M[1, 1] = cos(theta)
M[1, 2] = -sin(theta)
M[2, 1] = sin(theta)
M[2, 2] = cos(theta)
else
M[1, 1] = cosd(theta)
M[1, 2] = -sind(theta)
M[2, 1] = sind(theta)
M[2, 2] = cosd(theta)
end
elseif what == "shear"
if length(params) < 4
error("Rotate requires four parameter (a, b, c, d)")
end
a,b,c,d = params
M[1, 1] = a
M[1, 2] = b
M[2, 1] = c
M[2, 2] = d
else
error(printfmt("Matrix of {} is unknown\n", what))
end
M
end
function projectiveTransform(picture, points)
if length(points) != 4
error("Not correct number of point")
end
A = zeros(Int64, 2*length(points), 8)
B = zeros(Int64, 2*length(points), 1)
for i in 1:length(points)
x, y, x1, y1 = points[i]
A[2*i - 1,:] = [x y 1 0 0 0 -x*x1 -x1*y]
A[2*i,:] = [0 0 0 x y 1 -x*y1 -y*y1]
B[2*i - 1] = x1
B[2*i] = y1
end
H = vcat(A\B, 1)
M = reshape(H, (3,3))'
println("Matrix M = reshape([A\\B, 1], (3,3))")
display(M)
println()
backwardTransform("zero", M, picture)
end
if abspath(PROGRAM_FILE) == @__FILE__
what = ARGS[1]
img = load(ARGS[2])
if what == "transform"
# M = [[cosd(25) -sind(25) 0]; [sind(25) cosd(25) 0]; [0 0 1]]
# M = genMatrix("rotate", 25, false)
M = genMatrix(ARGS[3], ARGS[4:end]...)
forward = forwardTransform(M, img)
save("forward.png", forward)
backward = backwardTransform("zero", M, img)
save("backward.png", backward)
elseif what == "multitransform"
elseif what == "projective"
row, col = size(img)
out = projectiveTransform(img,
[
# [x y x1 y1],
[55 187 1 1],
[1276 619 1295 1],
[1447 1761 1295 1635],
[166 1819 1 1635]
]
)
save("projective.png", out)
else
println("Do what? transform/projective")
end
end

View File

@ -0,0 +1,3 @@
if abspath(PROGRAM_FILE) == @__FILE__
end

99
julia_scripts/hough.jl Normal file
View File

@ -0,0 +1,99 @@
include("convolution.jl")
using Images
using TestImages
using FileIO
using Colors
using ImageFeatures
using Formatting
using .Convole
function hough(img, thetaRange=100, rhoRange=100)
r, c = size(img)
D = sqrt(r * r + c * c)
rho_min = -D
rho_max = D
L_rho = 2*D
rho_step = L_rho / rhoRange
theta_min = -pi/2
theta_max = pi/2
L_theta = pi
theta_step = L_theta / thetaRange
function dcm_rho(idx)
rho_min + ((idx) * rho_step) + (rho_step / 2)
end
function cdm_rho(rho)
round(Int32, (rho - rho_min) / rho_step)
end
function dcm_theta(idx)
theta_min + ((idx) * theta_step) + (theta_step / 2)
end
function cdm_theta(theta)
round(Int32, (theta - theta_min) / theta_step)
end
accumulator = zeros(Int32, rhoRange, thetaRange)
#= display(accumulator) =#
#= println() =#
for index in CartesianIndices(img)
x, y = Tuple(index)
for k in 1:thetaRange
theta = dcm_theta(k)
rho = x * cos(theta) + y * sin(theta)
i = cdm_rho(rho)
accumulator[i, k] += 1 # simple delta(x,y)
end
end
rho_idx, theta_idx = Tuple(argmax(accumulator))
rho, theta = dcm_rho(rho_idx), dcm_theta(theta_idx)
(rho, theta)
end
if abspath(PROGRAM_FILE) == @__FILE__
#= img = zeros(Bool,10,10) =#
#= for i in 1:10 =#
#= img[2,i] = img[i,2] = img[7,i] = img[i,9] = true =#
#= end =#
#= lines = hough_transform_standard(img) =#
#= =#
#= display(img) =#
#= println() =#
#= for line in lines =#
#= r, t = line =#
#= printfmt("x * cos({}π) + y * sin({}π) = {}\n", t/π, t/π, r) =#
#= end =#
gaussian_kernel = [
1 4 7 4 1
4 16 26 16 4
7 26 41 26 7
4 16 26 16 4
1 4 7 4 1
] ./ 273
laplacian_kernel = [
-1 -1 -1
-1 8 -1
-1 -1 -1
]
sobel_x_kernel = [
-1 0 1
-2 0 2
-1 0 1
]
sobel_y_kernel = rotl90(sobel_x_kernel)
img = load(ARGS[1])
img_gray = Gray.(img)
img_blur = conv(img_gray, gaussian_kernel)
img_edge_x = conv(img_blur, sobel_x_kernel)
img_edge_y = conv(img_blur, sobel_y_kernel)
img_edge = Gray.(round.(Int32, sqrt.((img_edge_x .^ 2) .* (img_edge_y .^ 2))))
save("hough_edge.jpg", img_edge)
r, t = hough(img_gray)
printfmt("x * cos({}π) + y * sin({}π) = {}\n", t/π, t/π, r)
end

98
julia_scripts/jpeg.jl Normal file
View File

@ -0,0 +1,98 @@
using Images
using FFTW
using Formatting
LUMINANCE_QUANTIZATION_TABLE = [
16 11 10 16 24 40 51 61
12 12 14 19 26 58 60 55
14 13 16 24 40 57 69 56
14 17 22 29 51 87 80 62
18 22 37 56 68 109 103 77
24 35 55 64 81 104 113 92
49 64 78 87 103 121 120 101
72 92 95 98 112 100 103 99
]
ZIGZAG = [
0 1 5 6 14 15 27 28
2 4 7 13 16 26 29 42
3 8 12 17 25 30 41 43
9 11 18 24 31 40 44 53
10 19 23 32 39 45 52 54
20 22 33 38 46 51 55 60
21 34 37 47 50 56 59 61
35 36 48 49 57 58 62 63
] .+ 1
function to_zigzag(block)
out_block = zeros(eltype(block), size(ZIGZAG))
for idx in CartesianIndices(ZIGZAG)
out_block[ZIGZAG[idx]] = block[idx]
# display(out_block)
end
reshape(out_block, (1,64))
end
function RLC(block)
codes = Tuple{Int32, Int32, Int32}[]
leadingZeros = 0
for idx in CartesianIndices(ZIGZAG)
if (idx == CartesianIndex(1, 1))
DC = 0
push!(codes, (0, DC, block[idx]))
elseif (block[idx] == 0)
leadingZeros += 1
else
push!(codes, (leadingZeros, log(2, block[idx]), block[idx]))
leadingZeros = 0
end
end
push!(codes, (0, 0, 0))
codes
end
if abspath(PROGRAM_FILE) == @__FILE__
img = load(ARGS[1])
img_ycbcr = channelview(YCbCr.(img))
for c in 1:3
channel = img_ycbcr[c,:,:]
row, col = size(channel)
printfmt("{} {}\n", row, col)
printfmt("{} {}\n", row % 8, col % 8)
for i in 1:8:row
for j in 1:8:col
# printfmt("{} {}\n", i, j)
block = channel[i:i+7, j:j+7]
block_shifted = block .- 127
block_dct = FFTW.dct(block_shifted)
block_quantization = round.(Int32, block_dct ./ LUMINANCE_QUANTIZATION_TABLE)
block_zigzag = to_zigzag(block_quantization)
if i == 1 && j == 9
display(block)
println()
display(block_shifted)
println()
display(block_dct)
println()
display(block_quantization)
println()
display(block_zigzag)
println()
end
# block_zigzag = collect(block_zigzag)
DC = block_zigzag[1]
AC = block_zigzag[2:end]
end
end
end
end

35
julia_scripts/point.jl Normal file
View File

@ -0,0 +1,35 @@
using Images
using FileIO
using Colors
function transform(img, what, params...)
if length(params) < 2
error("Transform requires two parameter (a, b)")
end
a, b = params
out = zeros(eltype(img), size(img))
if what == "linear"
out = a .* img .+ b
elseif what == "log"
out = a .* log.(1 .+ img) .+ b
elseif what == "exp"
out = a .* exp.(img) .+ b
elseif what == "pow"
if length(params) < 3
error("Power transform requires three parameter (a, b, gamma)")
end
gamma = params[3]
out = a .* (img .^ gamma) .+ b
else
error("What the hell man?")
end
# TODO: Scale to 255
out
end
if abspath(PROGRAM_FILE) == @__FILE__
what = ARGS[1]
img = Gray.(load(ARGS[2]))
out = transform(img, what, ARGS[3:end]...)
save("point.png", out)
end

View File

@ -0,0 +1,24 @@
module Showpicture
using Images, ImageView, Gtk.ShortNames
export showpicture
function showpicture(img)
guidict = imshow(img);
#If we are not in a REPL
if (!isinteractive())
c = Condition()
# Get the window
win = guidict["gui"]["window"]
# Notify the condition object when the window closes
signal_connect(win, :destroy) do widget
notify(c)
end
# Wait for the notification before proceeding ...
wait(c)
end
end
end

View File

@ -0,0 +1,165 @@
```{.python .input n=84}
import numpy as np
from scipy import signal
from scipy import fftpack
import matplotlib.pyplot as plt
print("Question 1: ")
### Question 1
print("a/")
##a
I1 = np.array([
[5,0,0,1,2],
[2,1,5,1,2],
[7,1,5,1,2],
[7,4,5,4,3],
[7,1,6,1,3]
])
H_sobel_x = np.array([[-1,0,1],[-2,0,2],[-1,0,1]])
H_sobel_y = np.array([[-1,-2,-1],[0,0,0],[1,2,1]])
grad_x = signal.convolve2d(I1,H_sobel_x,boundary='symm',mode ='same')
grad_y = signal.convolve2d(I1,H_sobel_y,boundary='symm',mode = 'same')
print(f"Gradient of (0,0) according to x and y: {grad_x[0,0]} {grad_y[0,0]}")
print(f"Gradient of (1,1) according to x and y: {grad_x[1,1]} {grad_y[1,1]}")
print(f"Gradient of (0,3) according to x and y: {grad_x[0,3]} {grad_y[0,3]}")
##b
print("b/")
n = I1.size
hist1 = np.bincount(I1.flatten())/n
print("Normalized Histogram of I1: ")
print(hist1)
##c
print("c/")
hist2 = np.array([1/8 for i in range(8)])
cdf1 = np.cumsum(hist1)
cdf2 = np.cumsum(hist2)
## equalize
print("I2: ")
I2 = np.zeros((N,N))
N = I1.shape[0]
for i in range(N):
for j in range(N):
x = I1[i,j]
c_x = cdf1[x]
for k in range(len(cdf2)):
if cdf2[k] == c_x:
I2[i,j] = k
print(I2.astype(np.int))
print("Histogram of I2: ")
plt.hist(I2.flatten(),8,[0,8])
plt.show()
### Question 2
print("Question 2: ")
#a
print("a/")
f = np.array([1,2])
A = np.arange(2).reshape((1,2))
M = A.reshape((2,1)).dot(A)
M_dft = np.round(np.exp(1)**(-2j*(np.pi/2)*M))
print("Based vectors after DFT: ")
i=0
for e in M_dft:
print(f"e{i}: {e}")
i+=1
#b
print("b/")
M = 4
u = np.arange(M).reshape((M,1))
x = 2*u+1
W_dct = np.dot(u,x.T)
W_dct = np.cos(np.pi*W_dct/(2*M))
for _ in range(M):
if _ == 0:
W_dct[_,:]*= np.sqrt(1/M)
else:
W_dct[_,:]*= np.sqrt(2/M)
print("Based vectors after DCT for 4 dims: ")
i=0
for e in W_dct:
print(f"e{i}: {e}")
i+=1
IW = np.round(W_dct.dot(W_dct.T)).astype(np.int32)
print(f"W_dct.dot(W_dct.T): \n {IW}")
if(np.array_equal(IW,np.eye(4))):
print("W is orthor")
fx = np.array([1,0,1])
fx_dct = fftpack.dct(fx)
print(f"dct of fx: {fx_dct}")
### Question 3:
print("Question 3: ")
print("a/")
phi = np.pi/4
H2 = np.array([[np.cos(phi),-np.sin(phi),0],[np.sin(phi),np.cos(phi),0],[0,0,1]])
H1 = np.array([[1,0,-3],[0,1,-3],[0,0,1]])
H3 = np.array([[1,0,3],[0,1,3],[0,0,1]])
print(f"Translate -3: \n{H1}")
print(f"Rotate : \n {H2}")
print(f"Translate 3: \n{H3}")
H = H3.dot(H2).dot(H1)
print(f"Matrix to rotate the image around (3,3): \n {H}")
print("b/")
Io = np.array((2,3,1)).reshape((3,1))
I = np.linalg.pinv(H).dot(Io)
x,y=I[0:2,:].flatten()
print(f"x, y after zero order: {np.round(x).astype(np.int32)},{np.round(y).astype(np.int32)}")
```
```{.json .output n=84}
[
{
"name": "stdout",
"output_type": "stream",
"text": "Question 1: \na/\nGradient of (0,0) according to x and y: 16 8\nGradient of (1,1) according to x and y: 1 -9\nGradient of (0,3) according to x and y: -3 -5\nb/\nNormalized Histogram of I1: \n[0.08 0.28 0.16 0.08 0.08 0.16 0.04 0.12]\nc/\nI2: \n[[0 0 0 0 0]\n [0 0 0 0 0]\n [7 0 0 0 0]\n [7 0 0 0 0]\n [7 0 0 0 0]]\nHistogram of I2: \n"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4zLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvnQurowAAC99JREFUeJzt3W+MZfVdx/H3pyymhVZLs+Nm5Y/T\nGEJCTIRmgtU2DUppqDQFn5iS2BDTZPugNaAmBvuk+gwTrT4xTVZA1khpkD8psaRCKAk2UewsRVn+\nVCpCu+vCDiEKGJMK/fpgztZxs9OZ+2f23P3m/Uomc++5Z+Z8M5l979nfveduqgpJ0unvbWMPIEma\nD4MuSU0YdElqwqBLUhMGXZKaMOiS1IRBl6QmDLokNWHQJamJXafyYLt3767l5eVTeUhJOu0dPHjw\nlapa2mq/Uxr05eVlVldXT+UhJem0l+TF7eznkoskNWHQJakJgy5JTRh0SWrCoEtSEwZdkpow6JLU\nhEGXpCYMuiQ1cUqvFJ3F8k1fHXuEk3rh5qvHHkGSAM/QJakNgy5JTRh0SWrCoEtSEwZdkpow6JLU\nhEGXpCYMuiQ1YdAlqQmDLklNGHRJasKgS1ITBl2SmjDoktTElkFPcn6SR5I8neSpJDcM29+T5KEk\nzw2fz9n5cSVJm9nOGfqbwO9U1cXA+4HPJLkYuAl4uKouBB4e7kuSRrJl0KvqaFU9Ptx+HXgGOBe4\nBjgw7HYAuHanhpQkbW2iNfQky8ClwGPAnqo6Ojz0ErBnrpNJkiay7aAneSdwD3BjVb228bGqKqA2\n+bp9SVaTrK6trc00rCRpc9sKepIzWY/5HVV177D55SR7h8f3AsdO9rVVtb+qVqpqZWlpaR4zS5JO\nYjuvcglwK/BMVX1hw0P3A9cPt68HvjL/8SRJ27VrG/t8APgk8GSSJ4ZtnwNuBu5K8ingReDXdmZE\nSdJ2bBn0qvoGkE0evmK+40iSpuWVopLUhEGXpCYMuiQ1YdAlqQmDLklNGHRJasKgS1ITBl2SmjDo\nktSEQZekJgy6JDVh0CWpCYMuSU0YdElqwqBLUhMGXZKaMOiS1IRBl6QmDLokNWHQJakJgy5JTRh0\nSWrCoEtSEwZdkpow6JLUhEGXpCYMuiQ1YdAlqQmDLklNGHRJasKgS1ITBl2SmjDoktSEQZekJgy6\nJDVh0CWpCYMuSU0YdElqYsugJ7ktybEkhzZs+/0kR5I8MXz8ys6OKUnaynbO0G8HrjrJ9j+pqkuG\njwfmO5YkaVJbBr2qHgVePQWzSJJmMMsa+meT/POwJHPO3CaSJE1l2qB/EfgZ4BLgKPDHm+2YZF+S\n1SSra2trUx5OkrSVqYJeVS9X1VtV9QPgz4HLfsS++6tqpapWlpaWpp1TkrSFqYKeZO+Gu78KHNps\nX0nSqbFrqx2S3AlcDuxOchj4PHB5kkuAAl4APr2DM0qStmHLoFfVdSfZfOsOzCJJmoFXikpSEwZd\nkpow6JLUhEGXpCYMuiQ1YdAlqQmDLklNGHRJasKgS1ITBl2SmjDoktSEQZekJgy6JDVh0CWpCYMu\nSU0YdElqwqBLUhMGXZKaMOiS1IRBl6QmDLokNWHQJakJgy5JTRh0SWrCoEtSEwZdkpow6JLUhEGX\npCYMuiQ1YdAlqQmDLklNGHRJasKgS1ITBl2SmjDoktSEQZekJgy6JDVh0CWpiS2DnuS2JMeSHNqw\n7T1JHkry3PD5nJ0dU5K0le2cod8OXHXCtpuAh6vqQuDh4b4kaURbBr2qHgVePWHzNcCB4fYB4No5\nzyVJmtC0a+h7qurocPslYM+c5pEkTWnmJ0WrqoDa7PEk+5KsJlldW1ub9XCSpE1MG/SXk+wFGD4f\n22zHqtpfVStVtbK0tDTl4SRJW5k26PcD1w+3rwe+Mp9xJEnT2s7LFu8E/h64KMnhJJ8CbgauTPIc\n8OHhviRpRLu22qGqrtvkoSvmPIskaQZeKSpJTRh0SWrCoEtSEwZdkpow6JLUhEGXpCYMuiQ1YdAl\nqQmDLklNGHRJasKgS1ITBl2SmjDoktSEQZekJgy6JDVh0CWpCYMuSU0YdElqwqBLUhMGXZKaMOiS\n1IRBl6QmDLokNWHQJakJgy5JTRh0SWrCoEtSEwZdkpow6JLUhEGXpCYMuiQ1YdAlqQmDLklNGHRJ\nasKgS1ITBl2SmjDoktSEQZekJnbN8sVJXgBeB94C3qyqlXkMJUma3ExBH/xSVb0yh+8jSZqBSy6S\n1MSsQS/gwSQHk+ybx0CSpOnMuuTywao6kuQngYeSPFtVj27cYQj9PoALLrhgxsNJkjYz0xl6VR0Z\nPh8D7gMuO8k++6tqpapWlpaWZjmcJOlHmDroSc5O8q7jt4GPAIfmNZgkaTKzLLnsAe5Lcvz7fKmq\nvjaXqSRJE5s66FX1PPBzc5xFkjQDX7YoSU0YdElqwqBLUhMGXZKaMOiS1IRBl6QmDLokNWHQJakJ\ngy5JTRh0SWrCoEtSEwZdkpow6JLUhEGXpCZm/S/oJGlhLN/01bFH2NQLN1+948fwDF2SmjDoktSE\nQZekJgy6JDVh0CWpCYMuSU0YdElqwqBLUhMGXZKaMOiS1IRBl6QmDLokNWHQJakJgy5JTRh0SWrC\noEtSEwZdkpow6JLUhEGXpCYMuiQ1YdAlqQmDLklNGHRJamKmoCe5Ksm3k3wnyU3zGkqSNLmpg57k\nDODPgI8CFwPXJbl4XoNJkiYzyxn6ZcB3qur5qvo+8GXgmvmMJUma1CxBPxf43ob7h4dtkqQR7Nrp\nAyTZB+wb7r6R5NtTfqvdwCvzmWp+8oeLORcL+vPCuSblXJNZ1LlmbcVPb2enWYJ+BDh/w/3zhm3/\nT1XtB/bPcBwAkqxW1cqs32fenGsyzjUZ55rMos4Fp2a2WZZcvglcmOS9SX4M+ARw/3zGkiRNauoz\n9Kp6M8lngb8FzgBuq6qn5jaZJGkiM62hV9UDwANzmmUrMy/b7BDnmoxzTca5JrOoc8EpmC1VtdPH\nkCSdAl76L0lNnBZBX8S3GEhyW5JjSQ6NPctGSc5P8kiSp5M8leSGsWcCSPL2JP+Y5J+Guf5g7Jk2\nSnJGkm8l+ZuxZzkuyQtJnkzyRJLVsec5Lsm7k9yd5NkkzyT5hQWY6aLh53T847UkN449F0CS3xp+\n5w8luTPJ23fsWIu+5DK8xcC/AFeyfvHSN4Hrqurpkef6EPAG8JdV9bNjzrJRkr3A3qp6PMm7gIPA\ntQvw8wpwdlW9keRM4BvADVX1D2POdVyS3wZWgB+vqo+NPQ+sBx1YqaqFel11kgPA31XVLcMr3M6q\nqv8Ye67jhmYcAX6+ql4ceZZzWf9dv7iq/jvJXcADVXX7ThzvdDhDX8i3GKiqR4FXx57jRFV1tKoe\nH26/DjzDAlzBW+veGO6eOXwsxNlEkvOAq4Fbxp5l0SX5CeBDwK0AVfX9RYr54ArgX8eO+Qa7gHck\n2QWcBfz7Th3odAi6bzEwpSTLwKXAY+NOsm5Y1ngCOAY8VFULMRfwp8DvAj8Ye5ATFPBgkoPDFdeL\n4L3AGvAXwxLVLUnOHnuoE3wCuHPsIQCq6gjwR8B3gaPAf1bVgzt1vNMh6JpCkncC9wA3VtVrY88D\nUFVvVdUlrF9VfFmS0ZeqknwMOFZVB8ee5SQ+WFXvY/0dTT8zLPONbRfwPuCLVXUp8F/AQjyvBTAs\nAX0c+OuxZwFIcg7rKwrvBX4KODvJr+/U8U6HoG/rLQb0f4Y16nuAO6rq3rHnOdHwT/RHgKvGngX4\nAPDxYb36y8AvJ/mrcUdaN5zdUVXHgPtYX34c22Hg8IZ/Xd3NeuAXxUeBx6vq5bEHGXwY+LeqWquq\n/wHuBX5xpw52OgTdtxiYwPDk463AM1X1hbHnOS7JUpJ3D7ffwfqT3M+OOxVU1e9V1XlVtcz679bX\nq2rHzqC2K8nZw5PaDEsaHwFGf0VVVb0EfC/JRcOmK4BRn3A/wXUsyHLL4LvA+5OcNfzZvIL157V2\nxI6/2+KsFvUtBpLcCVwO7E5yGPh8Vd067lTA+hnnJ4Enh/VqgM8NV/WOaS9wYHgFwtuAu6pqYV4i\nuID2APetN4BdwJeq6mvjjvRDvwncMZxgPQ/8xsjzAD/8i+9K4NNjz3JcVT2W5G7gceBN4Fvs4BWj\nC/+yRUnS9pwOSy6SpG0w6JLUhEGXpCYMuiQ1YdAlqQmDLklNGHRJasKgS1IT/wuDycEaNT65agAA\nAABJRU5ErkJggg==\n",
"text/plain": "<Figure size 432x288 with 1 Axes>"
},
"metadata": {
"tags": []
},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": "Question 2: \na/\nBased vectors after DFT: \ne0: [1.+0.j 1.+0.j]\ne1: [ 1.+0.j -1.-0.j]\nb/\nBased vectors after DCT for 4 dims: \ne0: [0.5 0.5 0.5 0.5]\ne1: [ 0.65328148 0.27059805 -0.27059805 -0.65328148]\ne2: [ 0.5 -0.5 -0.5 0.5]\ne3: [ 0.27059805 -0.65328148 0.65328148 -0.27059805]\nW_dct.dot(W_dct.T): \n [[1 0 0 0]\n [0 1 0 0]\n [0 0 1 0]\n [0 0 0 1]]\nW is orthor\ndct of fx: [4. 0. 2.]\nQuestion 3: \na/\nTranslate -3: \n[[ 1 0 -3]\n [ 0 1 -3]\n [ 0 0 1]]\nRotate : \n [[ 0.70710678 -0.70710678 0. ]\n [ 0.70710678 0.70710678 0. ]\n [ 0. 0. 1. ]]\nTranslate 3: \n[[1 0 3]\n [0 1 3]\n [0 0 1]]\nMatrix to rotate the image around (3,3): \n [[ 0.70710678 -0.70710678 3. ]\n [ 0.70710678 0.70710678 -1.24264069]\n [ 0. 0. 1. ]]\nb/\nx, y after zero order: 2,4\n"
}
]
```

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

136
python_notebook/hough.ipynb Normal file
View File

@ -0,0 +1,136 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import imageio\n",
"import math"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def rgb2gray(rgb):\n",
" return np.dot(rgb[..., :3], [0.299, 0.587, 0.114]).astype(np.uint8)\n",
"\n",
"\n",
"def hough_line(img, angle_step=1, lines_are_white=True, value_threshold=5):\n",
" \"\"\"\n",
" Hough transform for lines\n",
"\n",
" Input:\n",
" img - 2D binary image with nonzeros representing edges\n",
" angle_step - Spacing between angles to use every n-th angle\n",
" between -90 and 90 degrees. Default step is 1.\n",
" lines_are_white - boolean indicating whether lines to be detected are white\n",
" value_threshold - Pixel values above or below the value_threshold are edges\n",
"\n",
" Returns:\n",
" accumulator - 2D array of the hough transform accumulator\n",
" theta - array of angles used in computation, in radians.\n",
" rhos - array of rho values. Max size is 2 times the diagonal\n",
" distance of the input image.\n",
" \"\"\"\n",
" # Rho and Theta ranges\n",
" thetas = np.deg2rad(np.arange(-90.0, 90.0, angle_step))\n",
" width, height = img.shape\n",
" diag_len = int(round(math.sqrt(width * width + height * height)))\n",
" rhos = np.linspace(-diag_len, diag_len, diag_len * 2)\n",
"\n",
" # Cache some resuable values\n",
" cos_t = np.cos(thetas)\n",
" sin_t = np.sin(thetas)\n",
" num_thetas = len(thetas)\n",
"\n",
" # Hough accumulator array of theta vs rho\n",
" accumulator = np.zeros((2 * diag_len, num_thetas), dtype=np.uint8)\n",
" # (row, col) indexes to edges\n",
" are_edges = img > value_threshold if lines_are_white else img < value_threshold\n",
" y_idxs, x_idxs = np.nonzero(are_edges)\n",
"\n",
" # Vote in the hough accumulator\n",
" for i in range(len(x_idxs)):\n",
" x = x_idxs[i]\n",
" y = y_idxs[i]\n",
"\n",
" for t_idx in range(num_thetas):\n",
" # Calculate rho. diag_len is added for a positive index\n",
" rho = diag_len + int(round(x * cos_t[t_idx] + y * sin_t[t_idx]))\n",
" accumulator[rho, t_idx] += 1\n",
"\n",
" return accumulator, thetas, rhos"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"def show_hough_line(img, accumulator, thetas, rhos, save_path=None):\n",
" import matplotlib.pyplot as plt\n",
"\n",
" fig, ax = plt.subplots(1, 2, figsize=(10, 10))\n",
"\n",
" ax[0].imshow(img, cmap=plt.cm.gray)\n",
" ax[0].set_title('Input image')\n",
" ax[0].axis('image')\n",
"\n",
" ax[1].imshow(\n",
" accumulator, cmap='jet',\n",
" extent=[np.rad2deg(thetas[-1]), np.rad2deg(thetas[0]), rhos[-1], rhos[0]])\n",
" ax[1].set_aspect('equal', adjustable='box')\n",
" ax[1].set_title('Hough transform')\n",
" ax[1].set_xlabel('Angles (degrees)')\n",
" ax[1].set_ylabel('Distance (pixels)')\n",
" ax[1].axis('image')\n",
"\n",
" # plt.axis('off')\n",
" if save_path is not None:\n",
" plt.savefig(save_path, bbox_inches='tight')\n",
" plt.show()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"imgpath = '../images/bangdiem.png'\n",
"img = imageio.imread(imgpath)\n",
"if img.ndim == 3:\n",
" img = rgb2gray(img)\n",
"accumulator, thetas, rhos = hough_line(img)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -0,0 +1,134 @@
import cv2 as cv
import numpy as np
from numpy import fft
import matplotlib.pyplot as plt
from scipy import ndimage
from scipy import signal
from scipy import fftpack
def create_histogram(img):
size = img.shape[0]*img.shape[1]
hist = np.zeros(8, dtype=np.float)
for row in range(img.shape[0]):
for col in range(img.shape[1]):
hist[img[row][col]] += 1
return hist/size
def create_sum_histogram(hist):
sum_hist = np.zeros(8,dtype=np.float)
sum_hist[0] = hist[0]
for x in range(1,8):
sum_hist[x] = sum_hist[x-1] + hist[x]
return sum_hist
def dft(signal):
N = len(signal)
x = np.array(range(N))
x = np.tile(x,(N,1))
u = x.copy().T
M = np.exp((-1j*2*np.pi*x*u)/N)
return np.matmul(M,signal)
def show_dft_vector(N):
x = np.array(range(N))
x = np.tile(x,(N,1))
u = x.copy().T
M = np.exp((-1j*2*np.pi*x*u)/N)
print(M)
def dct(signal):
N = len(signal)
x = np.array(range(N))
x = np.tile(x,(N,1))
u = x.copy().T
M = np.cos((2*x+1)*u*np.pi/(2*N))
a1 = [np.sqrt(1/N)]
a2 = np.repeat(np.array([np.sqrt(2/N)]),N-1)
a = np.concatenate((a1,a2),axis = 0)
return np.matmul(M,signal)*a
def show_dct(N):
x = np.array(range(N))
x = np.tile(x,(N,1))
u = x.copy().T
M = np.cos((2*x+1)*u*np.pi/(2*N))
a1 = [np.sqrt(1/N)]
a2 = np.repeat(np.array([np.sqrt(2/N)]),N-1)
a = np.concatenate((a1,a2),axis = 0)
a = np.repeat(a,4)
a = np.reshape(a,(4,4))
return M*a
def bai1():
I = np.array([[5,0,0,1,2],
[2,1,5,1,2],
[7,1,5,1,2],
[7,4,5,4,3],
[7,1,6,1,3]])
Kx = np.array([[-1,0,1],
[-2,0,2],
[-1,0,1]])
Ky = Kx.T
Gx = ndimage.convolve(I,Kx,mode='reflect')
Gy = ndimage.convolve(I,Ky,mode='reflect')
print('Gradient vector at (0,0): (' + str(Gx[0,0]) + ',' + str(Gy[0,0]) +')')
print('Gradient vector at (1,1): (' + str(Gx[1,1]) + ',' + str(Gy[1,1]) +')')
print('Gradient vector at (0,3): (' + str(Gx[0,3]) + ',' + str(Gy[0,3]) +')')
h = create_histogram(I)
plt.plot(h,color = 'b')
plt.xlim([0,7])
plt.show()
sumhist = create_sum_histogram(h)
new_I = I.copy()
for x in range(I.shape[0]):
for y in range(I.shape[1]):
new_I[x][y] = int(np.round(sumhist[I[x][y]]*7))
new_h = create_histogram(new_I)
new_h_sum = create_sum_histogram(new_h)
plt.plot(sumhist,color = 'r')
plt.plot(new_h_sum,color = 'b')
plt.xlim([0,7])
plt.show()
print(new_I)
def bai2():
# a)
print('Cau 2a)')
show_dft_vector(2)
print(dft([1,3]))
# b)
print('Cau b)')
fx = np.array([1,3])
fu = dft(fx)
print(fu)
print('Chung minh truc giao chuan:')
base_vector = show_dct(4)
for v in base_vector:
print(np.sum(v**2))
for x in range(base_vector.shape[0]):
for y in range(x,base_vector.shape[0]):
if x == y:
continue
print(np.dot(base_vector[x],base_vector[y]))
fx = np.array([1,0,1])
fxx = np.array([1,0,1,0])
print(dct(fxx))
def bai3():
A = np.array([[1/np.sqrt(2),-1/np.sqrt(2),3],
[1/np.sqrt(2),1/np.sqrt(2),-3*2**0.5+3],
[0,0,1]])
P1 = np.array([2,3,1])
pixel = np.round(np.matmul(np.linalg.inv(A),P1))
print(pixel)
bai1()
bai2()
bai3()

View File

@ -0,0 +1,107 @@
from skimage.exposure import rescale_intensity
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt
import math
def convolve(image, kernel):
(iH, iW) = image.shape[:2]
(kH, kW) = kernel.shape[:2]
kernel = kernel[::-1]
pad = (kW - 1) // 2
image = cv.copyMakeBorder(image, pad, pad, pad, pad, cv.BORDER_REPLICATE)
output = np.zeros((iH,iW), dtype="float32")
for y in np.arange(pad, iH + pad):
for x in np.arange(pad, iW + pad):
roi = image[y - pad:y+pad+1, x - pad:x + pad + 1]
k =(roi * kernel).sum()
output[y - pad, x - pad] = k
output = rescale_intensity(output, in_range=(0,255))
output = (output * 255).astype("uint8")
return output
I = np.array([ [5,0,0,1,2],
[2,1,5,1,2],
[7,1,5,1,2],
[7,4,5,4,3],
[7,1,6,1,3] ])
sobelX = np.array((
[-1,0,1],
[-2,0,2],
[-1,0,1]), dtype="int")
sobelY = np.array((
[-1,-1,-1],
[-2, 0, 2],
[-1, 0, 1]), dtype="int")
H,W = I.shape
D_x = convolve(I,sobelX)
D_y = convolve(I,sobelY)
result_a = []
for i in range(H):
temp = []
for j in range(W):
temp += [(D_x[i,j],D_y[i,j])]
result_a.append(temp)
print("1A\n",result_a)
def create_histogram(img):
assert len(img.shape) == 2
H,W = img.shape
sum = H * W
histogram = np.zeros(shape=(8,), dtype = float)
for row in range(img.shape[0]):
for col in range(img.shape[1]):
histogram[img[row,col]] += 1 / sum
return histogram
def visualize_histogram(histogram, name):
index = np.arange(len(histogram))
plt.bar(index,histogram)
plt.xlabel('Intensity', fontsize = 5)
plt.ylabel('Frequency', fontsize = 5)
plt.title(name)
plt.show()
def histogram_equation(histogram, img):
c = np.cumsum(histogram)
print(c)
m_table = np.array([]).astype(np.uint8)
m_table = c * 7
for row in range(img.shape[0]):
for col in range(img.shape[1]):
img[row,col] = m_table[img[row,col]]
return img
visualize_histogram(create_histogram(I),"1B")
print("1C\n",histogram_equation(create_histogram(I),I))
def DFT1D(array):
N = array.shape[0]
# (a[x, y], b[x, y]) = (x, y)
a = np.tile(np.arange(0, N), (N, 1))
b = a.copy().T
W = np.exp(-2j*np.pi/N*a*b)
return np.around(np.dot(W, array), 2)
def DCT1D(array):
N = array.shape[0]
factor = math.pi / N
C = np.zeros((N, N), dtype = np.float32)
for x in range(N):
C[0][x] = math.sqrt(1/N) * math.cos((x + 0.5) * 0 * factor)
for u in range(N)[1:]:
for x in range(N):
C[u][x] = math.sqrt(2/N) * math.cos((x + 0.5) * u * factor)
return C, np.matmul(C, array)
print("2A\n",DFT1D(np.array([1,3])))
C, F = DCT1D(np.array([1,0,1,0]))
print("2B\nC=\n", C)
print("F=",F)

84
python_scripts/FTs.py Normal file
View File

@ -0,0 +1,84 @@
import numpy as np
import scipy.ndimage as ndi
import matplotlib.pyplot as plt
def imshow(img, cap=None):
if np.amax(img) > 255:
img = img / (np.amax(img)) * 255
img.astype(np.uint8)
fig = plt.figure(figsize=(4, 4))
if cap is not None:
plt.title(cap)
plt.imshow(img, cmap="gray")
plt.axis("off")
plt.show()
def shift(array):
n = array.shape[0]
t = array[0:int(n / 2), 0:int(n / 2)].copy()
array[0:int(n / 2), 0:int(n / 2)] = array[int(n / 2):n, int(n / 2):n]
array[int(n / 2):n, int(n / 2):n] = t
t = array[0:int(n / 2), int(n / 2):n].copy()
array[0:int(n / 2), int(n / 2):n] = array[int(n / 2):n, 0:int(n / 2)]
array[int(n / 2):n, 0:int(n / 2)] = t
return array
def padding(img):
s = 2**np.ceil(np.log2(np.amax(img.shape))).astype(np.int32)
height = s - img.shape[0]
width = s - img.shape[1]
left = width // 2
right = width - left
top = height // 2
down = height - top
shape_ = [[top, down], [left, right]]
return np.pad(img, shape_, 'constant')
def dft1d(array):
N = array.shape[0]
# (a[x, y], b[x, y]) = (x, y)
a = np.tile(np.arange(0, N), (N, 1))
b = a.copy().T
W = np.exp(-2j * np.pi / N * a * b)
return np.around(np.dot(W, array), 2)
def idft1d(array):
N = array.shape[0]
# (a[x, y], b[x, y]) = (x, y)
a = np.tile(np.arange(0, N), (N, 1))
b = a.copy().T
W = np.exp(2j * np.pi / N * a * b) / N
return np.around(np.dot(W, array), 2)
def fft1d(array):
m = array.shape[0]
if m == 1:
return array
elif m % 2 == 0:
even = fft1d(array[::2])
odd = fft1d(array[1::2])
Wm = np.exp(-2j * np.pi / m * np.arange(int(m / 2)))
half1 = even + odd * Wm
half2 = even - odd * Wm
return np.concatenate([half1, half2])
else:
raise ValueError("Wrong dimension")
def fft(array):
n = array.shape[0]
if np.log2(n) % 1 != 0:
return dft1d(array)
else:
return np.around(fft1d(array), 2)
def fft2d(matrix):
temp = np.array([fft(x) for x in matrix]).T
return np.around(np.array([fft(x) for x in temp]).T, 2)

114
python_scripts/Filters.py Normal file
View File

@ -0,0 +1,114 @@
import cv2
import numpy as np
import scipy.ndimage as ndi
import matplotlib.pyplot as plt
# customized imshow function
def imshow(img, cap=None):
if np.amax(img) > 255:
img = img / (np.amax(img)) * 255
img.astype(np.uint8)
fig = plt.figure(figsize=(4, 4))
if cap is not None:
plt.title(cap)
plt.imshow(img, cmap="gray")
plt.axis("off")
plt.show()
def apply(img, ker):
return np.abs(np.fft.ifft2(np.fft.fftshift(np.fft.fft2(img)) * ker).real)
################################################################
# Ideal LowPass Filter kernel
def ilpf(m, n, r):
a = np.tile(np.arange(-n / 2, n / 2), (m, 1))
b = np.tile(np.arange(-m / 2, m / 2), (n, 1)).T
return (a * a + b * b < r * r).astype(np.uint8)
# Print ILPF Result
def apply_ilpf(img, r):
row, col = img.shape
imshow(img(*ilpf(row, col, r)), 'Ideal LowPass Filter\nwith r = ' + str(r))
img = cv2.imread("C:/Users/NGPD/Desktop/2.jpg", cv2.IMREAD_GRAYSCALE)
imshow(img, 'Loaded Image')
apply_ilpf(img, 5)
apply_ilpf(img, 15)
apply_ilpf(img, 30)
apply_ilpf(img, 80)
################################################################
# Butterworth LPF kernel
def blpf(m, n, N, r):
a = np.tile(np.arange(-n / 2, n / 2), (m, 1))
b = np.tile(np.arange(-m / 2, m / 2), (n, 1)).T
return (1 / (1 + ((a * a + b * b) / (r * r))**N))
# Print BLPF Result
def apply_blpf(img, N, r):
row, col = img.shape
imshow(img(*blpf(row, col, N, r)),
'Butterworth LowPass Filter\nwith r = ' + str(r) + ' and n = ' + str(N))
img = cv2.imread("C:/Users/NGPD/Desktop/2.jpg", cv2.IMREAD_GRAYSCALE)
imshow(img, 'Loaded Image')
n = 2
apply_blpf(img, n, 5)
apply_blpf(img, n, 15)
apply_blpf(img, n, 30)
apply_blpf(img, n, 80)
################################################################
# Gaussian LPF kernel
def glpf(m, n, r):
a = np.tile(np.arange(-n / 2, n / 2), (m, 1))
b = np.tile(np.arange(-m / 2, m / 2), (n, 1)).T
return np.exp(-(a * a + b * b) / (2 * r * r))
# Print GLPF Result
def apply_glpf(img, r):
row, col = img.shape
imshow(img(*glpf(row, col, r)), 'Gaussian LowPass Filter\nwith r = ' + str(r))
img = cv2.imread("C:/Users/NGPD/Desktop/2.jpg", cv2.IMREAD_GRAYSCALE)
imshow(img, 'Loaded Image')
apply_glpf(img, 5)
apply_glpf(img, 15)
apply_glpf(img, 30)
apply_glpf(img, 80)
################################################################
img = cv2.imread("C:/Users/NGPD/Desktop/2.jpg", cv2.IMREAD_GRAYSCALE)
m, n = img.shape
a = np.tile(np.arange(-n / 2, n / 2), (m, 1))
b = np.tile(np.arange(-m / 2, m / 2), (n, 1)).T
lap = img(*-(a * a + b * b))
if np.amax(lap) > 255:
lap = lap / (np.amax(lap)) * 255
imshow(img, 'Loaded Image')
imshow(lap, 'Laplacian Filter')
imshow(img - lap, 'g(x, y)')

View File

@ -0,0 +1,46 @@
import cv2
import numpy as np
import scipy.ndimage as ndi
import matplotlib.pyplot as plt
# customized imshow function
def imshow(img, cap=None):
if np.amax(img) > 255:
img = img / (np.amax(img)) * 255
img.astype(np.uint8)
fig = plt.figure(figsize=(4, 4))
if cap is not None:
plt.title(cap)
plt.imshow(img, cmap="gray")
plt.axis("off")
plt.show()
def ilpf(m, n, r):
a = np.tile(np.arange(-n / 2, n / 2), (m, 1))
b = np.tile(np.arange(-m / 2, m / 2), (n, 1)).T
return (a * a + b * b < r * r).astype(np.uint8)
def apply(img, ker):
return np.abs(np.fft.ifft2(np.fft.fftshift(np.fft.fft2(img)) * ker).real)
# generate chess board with size NxN
N = 64
a = np.tile(np.array(1), (int(N / 4), int(N / 4)))
b = np.tile(np.array(0), (int(N / 4), int(N / 4)))
img1 = np.concatenate([a, b], axis=0)
img2 = np.concatenate([b, a], axis=0)
img = np.concatenate([img1, img2], axis=1)
img = np.tile(img, (4, 4))
r, c = img.shape
ker = ilpf(r, c, 30)
res = img(*ker)
imshow(img, 'Created Image')
imshow(ker, 'ILPF Kernel')
imshow(res, 'ILPF Result')

90
python_scripts/hough.py Normal file
View File

@ -0,0 +1,90 @@
import numpy as np
import imageio
import math
def rgb2gray(rgb):
return np.dot(rgb[..., :3], [0.299, 0.587, 0.114]).astype(np.uint8)
def hough_line(img, angle_step=1, lines_are_white=True, value_threshold=5):
"""
Hough transform for lines
Input:
img - 2D binary image with nonzeros representing edges
angle_step - Spacing between angles to use every n-th angle
between -90 and 90 degrees. Default step is 1.
lines_are_white - boolean indicating whether lines to be detected are white
value_threshold - Pixel values above or below the value_threshold are edges
Returns:
accumulator - 2D array of the hough transform accumulator
theta - array of angles used in computation, in radians.
rhos - array of rho values. Max size is 2 times the diagonal
distance of the input image.
"""
# Rho and Theta ranges
thetas = np.deg2rad(np.arange(-90.0, 90.0, angle_step))
width, height = img.shape
diag_len = int(round(math.sqrt(width * width + height * height)))
rhos = np.linspace(-diag_len, diag_len, diag_len * 2)
# Cache some resuable values
cos_t = np.cos(thetas)
sin_t = np.sin(thetas)
num_thetas = len(thetas)
# Hough accumulator array of theta vs rho
accumulator = np.zeros((2 * diag_len, num_thetas), dtype=np.uint8)
# (row, col) indexes to edges
are_edges = img > value_threshold if lines_are_white else img < value_threshold
y_idxs, x_idxs = np.nonzero(are_edges)
# Vote in the hough accumulator
for i in range(len(x_idxs)):
x = x_idxs[i]
y = y_idxs[i]
for t_idx in range(num_thetas):
# Calculate rho. diag_len is added for a positive index
rho = diag_len + int(round(x * cos_t[t_idx] + y * sin_t[t_idx]))
accumulator[rho, t_idx] += 1
return accumulator, thetas, rhos
def show_hough_line(img, accumulator, thetas, rhos, save_path=None):
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 2, figsize=(10, 10))
ax[0].imshow(img, cmap=plt.cm.gray)
ax[0].set_title('Input image')
ax[0].axis('image')
ax[1].imshow(
accumulator, cmap='jet',
extent=[np.rad2deg(thetas[-1]), np.rad2deg(thetas[0]), rhos[-1], rhos[0]])
ax[1].set_aspect('equal', adjustable='box')
ax[1].set_title('Hough transform')
ax[1].set_xlabel('Angles (degrees)')
ax[1].set_ylabel('Distance (pixels)')
ax[1].axis('image')
# plt.axis('off')
if save_path is not None:
plt.savefig(save_path, bbox_inches='tight')
plt.show()
if __name__ == '__main__':
imgpath = '../images/bangdiem.png'
img = imageio.imread(imgpath)
if img.ndim == 3:
img = rgb2gray(img)
accumulator, thetas, rhos = hough_line(img)
idx = np.argmax(accumulator)
rho = rhos[idx / accumulator.shape[1]]
theta = thetas[idx % accumulator.shape[1]]
print ("rho={0:.2f}, theta={1:.0f}".format(rho, np.rad2deg(theta)))
# show_hough_line(img, accumulator, save_path='imgs/output.png')

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
resource/IPCV/2-3/_DS_Store Normal file

Binary file not shown.

BIN
resource/IPCV/4-5/DCT.pdf Normal file

Binary file not shown.

BIN
resource/IPCV/4-5/FFT.pdf Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

View File

@ -0,0 +1,236 @@
% Copyright 2007 by Till Tantau
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Public License.
%
% See the file doc/licenses/LICENSE for more details.
% Common packages
\usepackage[utf8x]{inputenc}
\usepackage[vietnam,english]{babel}
\usepackage[utf8]{vietnam}
%\usepackage{times}
\usefonttheme[onlymath]{serif}
\usecolortheme{default}
\usepackage{booktabs}
\usepackage{mathpartir}
\usepackage{listings}
\usepackage{listingsutf8}
\usepackage{pbox}
\mprset{flushleft}
\mode<article>
{
\usepackage{times}
\usepackage{mathptmx}
\usepackage[left=1.5cm,right=6cm,top=1.5cm,bottom=3cm]{geometry}
}
\usepackage{hyperref}
\usepackage{tikz}
\usetikzlibrary{arrows,backgrounds}
%\tikzstyle{mnode}=[circle, draw, fill=black, inner sep=0pt, minimum width=4pt]
\usepackage{colortbl}
%\usepackage{yfonts}
\usepackage{translator} % comment this, if not available
% Common settings for all lectures in this course
\def\lecturename{Image Processing and Computer Vision}
\title{\insertlecture}
\author{\textbf{LE Thanh Sach}}
\institute
{
\textit{Faculty of Computer Science and Engineering}\\
\textit{Ho Chi Minh University of Technology, VNU-HCM}
}
\subject{Lecturer \lecturename}
% Beamer version theme settings
\useoutertheme[height=0pt,width=2cm,right]{sidebar}
\usecolortheme{rose,sidebartab}
\useinnertheme{circles}
\usefonttheme[only large]{structurebold}
\setbeamercolor{sidebar right}{bg=black!15}
\setbeamercolor{structure}{fg=blue}
\setbeamercolor{author}{parent=structure}
\setbeamerfont{title}{series=\normalfont,size=\LARGE}
\setbeamerfont{title in sidebar}{series=\bfseries}
\setbeamerfont{author in sidebar}{series=\bfseries}
\setbeamerfont*{item}{series=}
\setbeamerfont{frametitle}{size=}
\setbeamerfont{block title}{size=\small}
\setbeamerfont{subtitle}{size=\normalsize,series=\normalfont}
\setbeamertemplate{navigation symbols}{}
\setbeamertemplate{bibliography item}[book]
\setbeamertemplate{sidebar right}
{
{\usebeamerfont{title in sidebar}%
\vskip1.5em%
\hskip3pt%
\usebeamercolor[fg]{title in sidebar}%
\insertshorttitle[width=2cm,center,respectlinebreaks]\par%
\vskip1.25em%
}%
{%
\hskip3pt%
\usebeamercolor[fg]{author in sidebar}%
\usebeamerfont{author in sidebar}%
\insertshortauthor[width=2cm,center,respectlinebreaks]\par%
\vskip1.25em%
}%
\hbox to2cm{\hss\insertlogo\hss}
\vskip1.25em%
\insertverticalnavigation{2cm}%
\vfill
\hbox to 2cm{\hfill\usebeamerfont{subsection in
sidebar}\strut\usebeamercolor[fg]{subsection in
sidebar}\insertshortlecture.\insertframenumber\hskip5pt}%
\vskip3pt%
}%
\setbeamertemplate{title page}
{
\vbox{}
\vskip1em
{\huge Chapter \insertshortlecture\par}
{\usebeamercolor[fg]{title}\usebeamerfont{title}\inserttitle\par}%
\ifx\insertsubtitle\@empty%
\else%
\vskip0.25em%
{\usebeamerfont{subtitle}\usebeamercolor[fg]{subtitle}\insertsubtitle\par}%
\fi%
\vskip1em\par
\emph{\lecturename}\
%on \insertdate\par
\vskip3em\par
\leftskip=0pt plus1fill\insertauthor\par
\insertinstitute\vskip1em
}
\logo{\includegraphics[width=1.5cm]{hcmut.png}}
% Article version layout settings
\mode<article>
\makeatletter
\def\@listI{\leftmargin\leftmargini
\parsep 0pt
\topsep 5\p@ \@plus3\p@ \@minus5\p@
\itemsep0pt}
\let\@listi=\@listI
\setbeamertemplate{frametitle}{\paragraph*{\insertframetitle\
\ \small\insertframesubtitle}\ \par
}
\setbeamertemplate{frame end}{%
\marginpar{\scriptsize\hbox to 1cm{\sffamily%
\hfill\strut\insertshortlecture.\insertframenumber}\hrule height .2pt}}
\setlength{\marginparwidth}{1cm}
\setlength{\marginparsep}{4.5cm}
\def\@maketitle{\makechapter}
\def\makechapter{
\newpage
\null
\vskip 2em%
{%
\parindent=0pt
\raggedright
\sffamily
\vskip8pt
{\fontsize{36pt}{36pt}\selectfont Chapter \insertshortlecture \par\vskip2pt}
{\fontsize{24pt}{28pt}\selectfont \color{blue!50!black} \insertlecture\par\vskip4pt}
{\Large\selectfont \color{blue!50!black} \insertsubtitle\par}
\vskip10pt
\normalsize\selectfont Print version of
Lecturer \emph{\lecturename} of \@date\par\vskip1.5em
\hfill Le Thanh Sach and Luong The Nhan, Faculty of CSE, HCMC University of Technology
}
\par
\vskip 1.5em%
}
\let\origstartsection=\@startsection
\def\@startsection#1#2#3#4#5#6{%
\origstartsection{#1}{#2}{#3}{#4}{#5}{#6\normalfont\sffamily\color{blue!50!black}\selectfont}}
\makeatother
\mode
<all>
% Typesetting Listings
\usepackage{listings}
\lstset{language=Java}
\alt<presentation>
{\lstset{%
basicstyle=\footnotesize\ttfamily,
commentstyle=\slshape\color{green!50!black},
keywordstyle=\bfseries\color{blue!50!black},
identifierstyle=\color{blue},
stringstyle=\color{orange},
escapechar=\#,
emphstyle=\color{red}}
}
{
\lstset{%
basicstyle=\ttfamily,
keywordstyle=\bfseries,
commentstyle=\itshape,
escapechar=\#,
emphstyle=\bfseries\color{red}
}
}
% Common theorem-like environments
\theoremstyle{example}
\newtheorem{exercise}[theorem]{\translate{Exercise}}
% New useful definitions:
\newbox\mytempbox
\newdimen\mytempdimen
\newcommand\includegraphicscopyright[3][]{%
\leavevmode\vbox{\vskip3pt\raggedright\setbox\mytempbox=\hbox{\includegraphics[#1]{#2}}%
\mytempdimen=\wd\mytempbox\box\mytempbox\par\vskip1pt%
\fontsize{3}{3.5}\selectfont{\color{black!25}{\vbox{\hsize=\mytempdimen#3}}}\vskip3pt%
}}
\newenvironment{colortabular}[1]{\medskip\rowcolors[]{1}{blue!20}{blue!10}\tabular{#1}\rowcolor{blue!40}}{\endtabular\medskip}
\def\equad{\leavevmode\hbox{}\quad}
\newenvironment{greencolortabular}[1]
{\medskip\rowcolors[]{1}{green!50!black!20}{green!50!black!10}%
\tabular{#1}\rowcolor{green!50!black!40}}%
{\endtabular\medskip}

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 KiB

View File

@ -0,0 +1,446 @@
% Mathpartir --- Math Paragraph for Typesetting Inference Rules
%
% Copyright (C) 2001, 2002, 2003, 2004, 2005 Didier Rémy
%
% Author : Didier Remy
% Version : 1.2.0
% Bug Reports : to author
% Web Site : http://pauillac.inria.fr/~remy/latex/
%
% Mathpartir is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2, or (at your option)
% any later version.
%
% Mathpartir is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details
% (http://pauillac.inria.fr/~remy/license/GPL).
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File mathpartir.sty (LaTeX macros)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mathpartir}
[2005/12/20 version 1.2.0 Math Paragraph for Typesetting Inference Rules]
%%
%% Identification
%% Preliminary declarations
\RequirePackage {keyval}
%% Options
%% More declarations
%% PART I: Typesetting maths in paragraphe mode
%% \newdimen \mpr@tmpdim
%% Dimens are a precious ressource. Uses seems to be local.
\let \mpr@tmpdim \@tempdima
% To ensure hevea \hva compatibility, \hva should expands to nothing
% in mathpar or in inferrule
\let \mpr@hva \empty
%% normal paragraph parametters, should rather be taken dynamically
\def \mpr@savepar {%
\edef \MathparNormalpar
{\noexpand \lineskiplimit \the\lineskiplimit
\noexpand \lineskip \the\lineskip}%
}
\def \mpr@rulelineskip {\lineskiplimit=0.3em\lineskip=0.2em plus 0.1em}
\def \mpr@lesslineskip {\lineskiplimit=0.6em\lineskip=0.5em plus 0.2em}
\def \mpr@lineskip {\lineskiplimit=1.2em\lineskip=1.2em plus 0.2em}
\let \MathparLineskip \mpr@lineskip
\def \mpr@paroptions {\MathparLineskip}
\let \mpr@prebindings \relax
\newskip \mpr@andskip \mpr@andskip 2em plus 0.5fil minus 0.5em
\def \mpr@goodbreakand
{\hskip -\mpr@andskip \penalty -1000\hskip \mpr@andskip}
\def \mpr@and {\hskip \mpr@andskip}
\def \mpr@andcr {\penalty 50\mpr@and}
\def \mpr@cr {\penalty -10000\mpr@and}
\def \mpr@eqno #1{\mpr@andcr #1\hskip 0em plus -1fil \penalty 10}
\def \mpr@bindings {%
\let \and \mpr@andcr
\let \par \mpr@andcr
\let \\\mpr@cr
\let \eqno \mpr@eqno
\let \hva \mpr@hva
}
\let \MathparBindings \mpr@bindings
% \@ifundefined {ignorespacesafterend}
% {\def \ignorespacesafterend {\aftergroup \ignorespaces}
\newenvironment{mathpar}[1][]
{$$\mpr@savepar \parskip 0em \hsize \linewidth \centering
\vbox \bgroup \mpr@prebindings \mpr@paroptions #1\ifmmode $\else
\noindent $\displaystyle\fi
\MathparBindings}
{\unskip \ifmmode $\fi\egroup $$\ignorespacesafterend}
\newenvironment{mathparpagebreakable}[1][]
{\begingroup
\par
\mpr@savepar \parskip 0em \hsize \linewidth \centering
\mpr@prebindings \mpr@paroptions #1%
\vskip \abovedisplayskip \vskip -\lineskip%
\ifmmode \else $\displaystyle\fi
\MathparBindings
}
{\unskip
\ifmmode $\fi \par\endgroup
\vskip \belowdisplayskip
\noindent
\ignorespacesafterend}
% \def \math@mathpar #1{\setbox0 \hbox {$\displaystyle #1$}\ifnum
% \wd0 < \hsize $$\box0$$\else \bmathpar #1\emathpar \fi}
%%% HOV BOXES
\def \mathvbox@ #1{\hbox \bgroup \mpr@normallineskip
\vbox \bgroup \tabskip 0em \let \\ \cr
\halign \bgroup \hfil $##$\hfil\cr #1\crcr \egroup \egroup
\egroup}
\def \mathhvbox@ #1{\setbox0 \hbox {\let \\\qquad $#1$}\ifnum \wd0 < \hsize
\box0\else \mathvbox {#1}\fi}
%% Part II -- operations on lists
\newtoks \mpr@lista
\newtoks \mpr@listb
\long \def\mpr@cons #1\mpr@to#2{\mpr@lista {\\{#1}}\mpr@listb \expandafter
{#2}\edef #2{\the \mpr@lista \the \mpr@listb}}
\long \def\mpr@snoc #1\mpr@to#2{\mpr@lista {\\{#1}}\mpr@listb \expandafter
{#2}\edef #2{\the \mpr@listb\the\mpr@lista}}
\long \def \mpr@concat#1=#2\mpr@to#3{\mpr@lista \expandafter {#2}\mpr@listb
\expandafter {#3}\edef #1{\the \mpr@listb\the\mpr@lista}}
\def \mpr@head #1\mpr@to #2{\expandafter \mpr@head@ #1\mpr@head@ #1#2}
\long \def \mpr@head@ #1#2\mpr@head@ #3#4{\def #4{#1}\def#3{#2}}
\def \mpr@flatten #1\mpr@to #2{\expandafter \mpr@flatten@ #1\mpr@flatten@ #1#2}
\long \def \mpr@flatten@ \\#1\\#2\mpr@flatten@ #3#4{\def #4{#1}\def #3{\\#2}}
\def \mpr@makelist #1\mpr@to #2{\def \mpr@all {#1}%
\mpr@lista {\\}\mpr@listb \expandafter {\mpr@all}\edef \mpr@all {\the
\mpr@lista \the \mpr@listb \the \mpr@lista}\let #2\empty
\def \mpr@stripof ##1##2\mpr@stripend{\def \mpr@stripped{##2}}\loop
\mpr@flatten \mpr@all \mpr@to \mpr@one
\expandafter \mpr@snoc \mpr@one \mpr@to #2\expandafter \mpr@stripof
\mpr@all \mpr@stripend
\ifx \mpr@stripped \empty \let \mpr@isempty 0\else \let \mpr@isempty 1\fi
\ifx 1\mpr@isempty
\repeat
}
\def \mpr@rev #1\mpr@to #2{\let \mpr@tmp \empty
\def \\##1{\mpr@cons ##1\mpr@to \mpr@tmp}#1\let #2\mpr@tmp}
%% Part III -- Type inference rules
\newif \if@premisse
\newbox \mpr@hlist
\newbox \mpr@vlist
\newif \ifmpr@center \mpr@centertrue
\def \mpr@htovlist {%
\setbox \mpr@hlist
\hbox {\strut
\ifmpr@center \hskip -0.5\wd\mpr@hlist\fi
\unhbox \mpr@hlist}%
\setbox \mpr@vlist
\vbox {\if@premisse \box \mpr@hlist \unvbox \mpr@vlist
\else \unvbox \mpr@vlist \box \mpr@hlist
\fi}%
}
% OLD version
% \def \mpr@htovlist {%
% \setbox \mpr@hlist
% \hbox {\strut \hskip -0.5\wd\mpr@hlist \unhbox \mpr@hlist}%
% \setbox \mpr@vlist
% \vbox {\if@premisse \box \mpr@hlist \unvbox \mpr@vlist
% \else \unvbox \mpr@vlist \box \mpr@hlist
% \fi}%
% }
\def \mpr@item #1{$\displaystyle #1$}
\def \mpr@sep{2em}
\def \mpr@blank { }
\def \mpr@hovbox #1#2{\hbox
\bgroup
\ifx #1T\@premissetrue
\else \ifx #1B\@premissefalse
\else
\PackageError{mathpartir}
{Premisse orientation should either be T or B}
{Fatal error in Package}%
\fi \fi
\def \@test {#2}\ifx \@test \mpr@blank\else
\setbox \mpr@hlist \hbox {}%
\setbox \mpr@vlist \vbox {}%
\if@premisse \let \snoc \mpr@cons \else \let \snoc \mpr@snoc \fi
\let \@hvlist \empty \let \@rev \empty
\mpr@tmpdim 0em
\expandafter \mpr@makelist #2\mpr@to \mpr@flat
\if@premisse \mpr@rev \mpr@flat \mpr@to \@rev \else \let \@rev \mpr@flat \fi
\def \\##1{%
\def \@test {##1}\ifx \@test \empty
\mpr@htovlist
\mpr@tmpdim 0em %%% last bug fix not extensively checked
\else
\setbox0 \hbox{\mpr@item {##1}}\relax
\advance \mpr@tmpdim by \wd0
%\mpr@tmpdim 1.02\mpr@tmpdim
\ifnum \mpr@tmpdim < \hsize
\ifnum \wd\mpr@hlist > 0
\if@premisse
\setbox \mpr@hlist
\hbox {\unhbox0 \hskip \mpr@sep \unhbox \mpr@hlist}%
\else
\setbox \mpr@hlist
\hbox {\unhbox \mpr@hlist \hskip \mpr@sep \unhbox0}%
\fi
\else
\setbox \mpr@hlist \hbox {\unhbox0}%
\fi
\else
\ifnum \wd \mpr@hlist > 0
\mpr@htovlist
\mpr@tmpdim \wd0
\fi
\setbox \mpr@hlist \hbox {\unhbox0}%
\fi
\advance \mpr@tmpdim by \mpr@sep
\fi
}%
\@rev
\mpr@htovlist
\ifmpr@center \hskip \wd\mpr@vlist\fi \box \mpr@vlist
\fi
\egroup
}
%%% INFERENCE RULES
\@ifundefined{@@over}{%
\let\@@over\over % fallback if amsmath is not loaded
\let\@@overwithdelims\overwithdelims
\let\@@atop\atop \let\@@atopwithdelims\atopwithdelims
\let\@@above\above \let\@@abovewithdelims\abovewithdelims
}{}
%% The default
\def \mpr@@fraction #1#2{\hbox {\advance \hsize by -0.5em
$\displaystyle {#1\mpr@over #2}$}}
\def \mpr@@nofraction #1#2{\hbox {\advance \hsize by -0.5em
$\displaystyle {#1\@@atop #2}$}}
\let \mpr@fraction \mpr@@fraction
%% A generic solution to arrow
\def \mpr@make@fraction #1#2#3#4#5{\hbox {%
\def \mpr@tail{#1}%
\def \mpr@body{#2}%
\def \mpr@head{#3}%
\setbox1=\hbox{$#4$}\setbox2=\hbox{$#5$}%
\setbox3=\hbox{$\mkern -3mu\mpr@body\mkern -3mu$}%
\setbox3=\hbox{$\mkern -3mu \mpr@body\mkern -3mu$}%
\dimen0=\dp1\advance\dimen0 by \ht3\relax\dp1\dimen0\relax
\dimen0=\ht2\advance\dimen0 by \dp3\relax\ht2\dimen0\relax
\setbox0=\hbox {$\box1 \@@atop \box2$}%
\dimen0=\wd0\box0
\box0 \hskip -\dimen0\relax
\hbox to \dimen0 {$%
\mathrel{\mpr@tail}\joinrel
\xleaders\hbox{\copy3}\hfil\joinrel\mathrel{\mpr@head}%
$}}}
%% Old stuff should be removed in next version
\def \mpr@@nothing #1#2
{$\lower 0.01pt \mpr@@nofraction {#1}{#2}$}
\def \mpr@@reduce #1#2{\hbox
{$\lower 0.01pt \mpr@@fraction {#1}{#2}\mkern -15mu\rightarrow$}}
\def \mpr@@rewrite #1#2#3{\hbox
{$\lower 0.01pt \mpr@@fraction {#2}{#3}\mkern -8mu#1$}}
\def \mpr@infercenter #1{\vcenter {\mpr@hovbox{T}{#1}}}
\def \mpr@empty {}
\def \mpr@inferrule
{\bgroup
\ifnum \linewidth<\hsize \hsize \linewidth\fi
\mpr@rulelineskip
\let \and \qquad
\let \hva \mpr@hva
\let \@rulename \mpr@empty
\let \@rule@options \mpr@empty
\let \mpr@over \@@over
\mpr@inferrule@}
\newcommand {\mpr@inferrule@}[3][]
{\everymath={\displaystyle}%
\def \@test {#2}\ifx \empty \@test
\setbox0 \hbox {$\vcenter {\mpr@hovbox{B}{#3}}$}%
\else
\def \@test {#3}\ifx \empty \@test
\setbox0 \hbox {$\vcenter {\mpr@hovbox{T}{#2}}$}%
\else
\setbox0 \mpr@fraction {\mpr@hovbox{T}{#2}}{\mpr@hovbox{B}{#3}}%
\fi \fi
\def \@test {#1}\ifx \@test\empty \box0
\else \vbox
%%% Suggestion de Francois pour les etiquettes longues
%%% {\hbox to \wd0 {\RefTirName {#1}\hfil}\box0}\fi
{\hbox {\RefTirName {#1}}\box0}\fi
\egroup}
\def \mpr@vdotfil #1{\vbox to #1{\leaders \hbox{$\cdot$} \vfil}}
% They are two forms
% \inferrule [label]{[premisses}{conclusions}
% or
% \inferrule* [options]{[premisses}{conclusions}
%
% Premisses and conclusions are lists of elements separated by \\
% Each \\ produces a break, attempting horizontal breaks if possible,
% and vertical breaks if needed.
%
% An empty element obtained by \\\\ produces a vertical break in all cases.
%
% The former rule is aligned on the fraction bar.
% The optional label appears on top of the rule
% The second form to be used in a derivation tree is aligned on the last
% line of its conclusion
%
% The second form can be parameterized, using the key=val interface. The
% folloiwng keys are recognized:
%
% width set the width of the rule to val
% narrower set the width of the rule to val\hsize
% before execute val at the beginning/left
% lab put a label [Val] on top of the rule
% lskip add negative skip on the right
% left put a left label [Val]
% Left put a left label [Val], ignoring its width
% right put a right label [Val]
% Right put a right label [Val], ignoring its width
% leftskip skip negative space on the left-hand side
% rightskip skip negative space on the right-hand side
% vdots lift the rule by val and fill vertical space with dots
% after execute val at the end/right
%
% Note that most options must come in this order to avoid strange
% typesetting (in particular leftskip must preceed left and Left and
% rightskip must follow Right or right; vdots must come last
% or be only followed by rightskip.
%
%% Keys that make sence in all kinds of rules
\def \mprset #1{\setkeys{mprset}{#1}}
\define@key {mprset}{andskip}[]{\mpr@andskip=#1}
\define@key {mprset}{lineskip}[]{\lineskip=#1}
\define@key {mprset}{flushleft}[]{\mpr@centerfalse}
\define@key {mprset}{center}[]{\mpr@centertrue}
\define@key {mprset}{rewrite}[]{\let \mpr@fraction \mpr@@rewrite}
\define@key {mprset}{atop}[]{\let \mpr@fraction \mpr@@nofraction}
\define@key {mprset}{myfraction}[]{\let \mpr@fraction #1}
\define@key {mprset}{fraction}[]{\def \mpr@fraction {\mpr@make@fraction #1}}
\define@key {mprset}{sep}{\def\mpr@sep{#1}}
\newbox \mpr@right
\define@key {mpr}{flushleft}[]{\mpr@centerfalse}
\define@key {mpr}{center}[]{\mpr@centertrue}
\define@key {mpr}{rewrite}[]{\let \mpr@fraction \mpr@@rewrite}
\define@key {mpr}{myfraction}[]{\let \mpr@fraction #1}
\define@key {mpr}{fraction}[]{\def \mpr@fraction {\mpr@make@fraction #1}}
\define@key {mpr}{left}{\setbox0 \hbox {$\TirName {#1}\;$}\relax
\advance \hsize by -\wd0\box0}
\define@key {mpr}{width}{\hsize #1}
\define@key {mpr}{sep}{\def\mpr@sep{#1}}
\define@key {mpr}{before}{#1}
\define@key {mpr}{lab}{\let \RefTirName \TirName \def \mpr@rulename {#1}}
\define@key {mpr}{Lab}{\let \RefTirName \TirName \def \mpr@rulename {#1}}
\define@key {mpr}{narrower}{\hsize #1\hsize}
\define@key {mpr}{leftskip}{\hskip -#1}
\define@key {mpr}{reduce}[]{\let \mpr@fraction \mpr@@reduce}
\define@key {mpr}{rightskip}
{\setbox \mpr@right \hbox {\unhbox \mpr@right \hskip -#1}}
\define@key {mpr}{LEFT}{\setbox0 \hbox {$#1$}\relax
\advance \hsize by -\wd0\box0}
\define@key {mpr}{left}{\setbox0 \hbox {$\TirName {#1}\;$}\relax
\advance \hsize by -\wd0\box0}
\define@key {mpr}{Left}{\llap{$\TirName {#1}\;$}}
\define@key {mpr}{right}
{\setbox0 \hbox {$\;\TirName {#1}$}\relax \advance \hsize by -\wd0
\setbox \mpr@right \hbox {\unhbox \mpr@right \unhbox0}}
\define@key {mpr}{RIGHT}
{\setbox0 \hbox {$#1$}\relax \advance \hsize by -\wd0
\setbox \mpr@right \hbox {\unhbox \mpr@right \unhbox0}}
\define@key {mpr}{Right}
{\setbox \mpr@right \hbox {\unhbox \mpr@right \rlap {$\;\TirName {#1}$}}}
\define@key {mpr}{vdots}{\def \mpr@vdots {\@@atop \mpr@vdotfil{#1}}}
\define@key {mpr}{after}{\edef \mpr@after {\mpr@after #1}}
\newcommand \mpr@inferstar@ [3][]{\setbox0
\hbox {\let \mpr@rulename \mpr@empty \let \mpr@vdots \relax
\setbox \mpr@right \hbox{}%
$\setkeys{mpr}{#1}%
\ifx \mpr@rulename \mpr@empty \mpr@inferrule {#2}{#3}\else
\mpr@inferrule [{\mpr@rulename}]{#2}{#3}\fi
\box \mpr@right \mpr@vdots$}
\setbox1 \hbox {\strut}
\@tempdima \dp0 \advance \@tempdima by -\dp1
\raise \@tempdima \box0}
\def \mpr@infer {\@ifnextchar *{\mpr@inferstar}{\mpr@inferrule}}
\newcommand \mpr@err@skipargs[3][]{}
\def \mpr@inferstar*{\ifmmode
\let \@do \mpr@inferstar@
\else
\let \@do \mpr@err@skipargs
\PackageError {mathpartir}
{\string\inferrule* can only be used in math mode}{}%
\fi \@do}
%%% Exports
% Envirnonment mathpar
\let \inferrule \mpr@infer
% make a short name \infer is not already defined
\@ifundefined {infer}{\let \infer \mpr@infer}{}
\def \TirNameStyle #1{\small \textsc{#1}}
\def \tir@name #1{\hbox {\small \TirNameStyle{#1}}}
\let \TirName \tir@name
\let \DefTirName \TirName
\let \RefTirName \TirName
%%% Other Exports
% \let \listcons \mpr@cons
% \let \listsnoc \mpr@snoc
% \let \listhead \mpr@head
% \let \listmake \mpr@makelist
\endinput

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,166 @@
%%
%% This is file `mhsetup.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% mhsetup.dtx (with options: `package')
%%
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%% http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2003/12/01 or later.
%%
%% This work has the LPPL maintenance status "maintained".
%%
%% The Current Maintainer of this work is Morten H\o gholm.
%%
%% This work consists of the files mhsetup.dtx and mhsetup.ins and
%% the derived file mhsetup.sty.
%%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mhsetup}
[2004/10/10 v1.0b programming setup (MH)]
\def\MHInternalSyntaxOn{
\edef\MHInternalSyntaxOff{%
\catcode`\noexpand\~=\the\catcode`\~\relax
\catcode`\noexpand\ =\the\catcode`\ \relax
\catcode`\noexpand\^^I=\the\catcode`\^^I\relax
\catcode`\noexpand\@=\the\catcode`\@\relax
\catcode`\noexpand\:=\the\catcode`\:\relax
\catcode`\noexpand\_=\the\catcode`\_\relax
\endlinechar=\the\endlinechar\relax
}%
\catcode`\~=10\relax
\catcode`\ =9\relax
\catcode`\^^I=9\relax
\makeatletter
\catcode`\_=11\relax
\catcode`\:=11\relax
\endlinechar=` %
\relax
}
\MHInternalSyntaxOn
\AtEndOfPackage{\MHInternalSyntaxOff}
\let\MH_let:NwN \let
\def\MH_let:cN #1#2{
\expandafter\MH_let:NwN \csname#1\endcsname#2}
\def\MH_let:cc #1#2{
\expandafter\MH_let:NwN\csname#1\expandafter\endcsname
\csname#2\endcsname}
\def\MH_new_boolean:n #1{
\expandafter\@ifdefinable\csname if_boolean_#1:\endcsname{
\@namedef{boolean_#1_true:}
{\MH_let:cN{if_boolean_#1:}\iftrue}
\@namedef{boolean_#1_false:}
{\MH_let:cN{if_boolean_#1:}\iffalse}
\@nameuse{boolean_#1_false:}%
}
}
\def\MH_set_boolean_F:n #1{ \@nameuse{boolean_#1_false:} }
\def\MH_set_boolean_T:n #1{ \@nameuse{boolean_#1_true:} }
\def\MH_if_boolean:nTF #1{
\@nameuse{if_boolean_#1:}
\expandafter\@firstoftwo
\else:
\expandafter\@secondoftwo
\fi:
}
\def\MH_if_boolean:nT #1{
\@nameuse{if_boolean_#1:}
\expandafter\@firstofone
\else:
\expandafter\@gobble
\fi:
}
\def\MH_if_boolean:nF #1{
\@nameuse{if_boolean_#1:}
\expandafter\@gobble
\else:
\expandafter\@firstofone
\fi:
}
\@ifundefined{if:w}{\MH_let:NwN \if:w =\if}{}
\@ifundefined{if_meaning:NN}{\MH_let:NwN \if_meaning:NN =\ifx}{}
\@ifundefined{else:}{\MH_let:NwN \else:=\else}{}
\@ifundefined{fi:}{\MH_let:NwN \fi:=\fi}{}
\@ifundefined{if_num:w}{\MH_let:NwN \if_num:w =\ifnum}{}
\@ifundefined{if_dim:w}{\MH_let:NwN \if_dim:w =\ifdim}{}
\@ifundefined{if_case:w}{\MH_let:NwN \if_case:w =\ifcase}{}
\@ifundefined{or:}{\MH_let:NwN \or:=\or}{}
\def\MH_cs_to_str:N {\expandafter\@gobble\string}
\@ifundefined{eTeXversion}
{
\MH_let:NwN \MH_protected:\relax
\def\MH_setlength:dn{\setlength}
\def\MH_addtolength:dn{\addtolength}
}
{
\MH_let:NwN \MH_protected:\protected
\def\MH_setlength:dn #1#2{#1=\dimexpr#2\relax\relax}
\def\MH_addtolength:dn #1#2{\advance#1 \dimexpr#2\relax\relax}
}
\def\MH_keyval_alias_with_addon:nnnn #1#2#3#4{
\@namedef{KV@#1@#2}{\@nameuse{KV@#1@#3}#4}
\@namedef{KV@#1@#2@default}{\@nameuse{KV@#1@#3@default}#4}}
\def\MH_keyval_alias:nnn #1#2#3{
\MH_keyval_alias_with_addon:nnnn {#1}{#2}{#3}{}}
\def\MH_use_choice_i:nnnn #1#2#3#4{#1}
\def\MH_use_choice_ii:nnnn #1#2#3#4{#2}
\def\MH_use_choice_iii:nnnn #1#2#3#4{#3}
\def\MH_use_choice_iv:nnnn #1#2#3#4{#4}
\long\def\MH_nospace_ifnextchar:Nnn #1#2#3{
\MH_let:NwN\reserved@d=~#1
\def\reserved@a{#2}
\def\reserved@b{#3}
\futurelet\@let@token\MH_nospace_nextchar:
}
\def\MH_nospace_nextchar:{
\if_meaning:NN \@let@token\reserved@d
\MH_let:NwN \reserved@b\reserved@a
\fi:
\reserved@b
}
\long\def\MH_nospace_testopt:nn #1#2{
\MH_nospace_ifnextchar:Nnn[
{#1}
{#1[{#2}]}
}
\def\MH_nospace_protected_testopt:n #1{
\if_meaning:NN \protect\@typeset@protect
\expandafter\MH_nospace_testopt:nn
\else:
\@x@protect#1
\fi:
}
\@ifundefined{kernel@ifnextchar}
{\MH_let:NwN \kernel@ifnextchar \@ifnextchar}
{}
\MH_let:NwN \MH_kernel_xargdef:nwwn \@xargdef
\long\def\MH_nospace_xargdef:nwwn #1[#2][#3]#4{
\@ifdefinable#1{
\expandafter\def\expandafter#1\expandafter{
\expandafter
\MH_nospace_protected_testopt:n
\expandafter
#1
\csname\string#1\endcsname
{#3}}
\expandafter\@yargdef
\csname\string#1\endcsname
\tw@
{#2}
{#4}}}
\providecommand*\MHPrecedingSpacesOff{
\MH_let:NwN \@xargdef \MH_nospace_xargdef:nwwn
}
\providecommand*\MHPrecedingSpacesOn{
\MH_let:NwN \@xargdef \MH_kernel_xargdef:nwwn
}
\endinput
%%
%% End of file `mhsetup.sty'.

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 709 KiB

Some files were not shown because too many files have changed in this diff Show More