init
This commit is contained in:
528
julia_notebook/1611617_NGUYEN_ANH_KHOA_new.ipynb
Normal file
528
julia_notebook/1611617_NGUYEN_ANH_KHOA_new.ipynb
Normal 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
|
||||
}
|
443
julia_notebook/assignment.ipynb
Normal file
443
julia_notebook/assignment.ipynb
Normal file
File diff suppressed because one or more lines are too long
192
julia_notebook/convolution.ipynb
Normal file
192
julia_notebook/convolution.ipynb
Normal file
File diff suppressed because one or more lines are too long
150
julia_notebook/dct.ipynb
Normal file
150
julia_notebook/dct.ipynb
Normal 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
|
||||
}
|
211
julia_notebook/dft_fft.ipynb
Normal file
211
julia_notebook/dft_fft.ipynb
Normal 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
235
julia_notebook/fiters.ipynb
Normal file
File diff suppressed because one or more lines are too long
544
julia_notebook/geometric.ipynb
Normal file
544
julia_notebook/geometric.ipynb
Normal file
File diff suppressed because one or more lines are too long
818
julia_notebook/histogram.ipynb
Normal file
818
julia_notebook/histogram.ipynb
Normal file
File diff suppressed because one or more lines are too long
824
julia_notebook/hough.ipynb
Normal file
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
409
julia_notebook/jpeg.ipynb
Normal 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
|
||||
}
|
Reference in New Issue
Block a user