GNUCLSAHOVDKSAHOVDK...

(* Content-type: application/mathematica *)
(*** Wolfram Notebook File ***)
(* CreatedBy='Mathematica 6.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[
NotebookDataLength[
NotebookOptionsPosition[
NotebookOutlinePosition[
CellTagsIndexPosition[
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[CellGroupData[{
Cell["\", "Title"],
Cell["\", "Subsubtitle"],
Cell[CellGroupData[{
Cell["Introduction", "Section"],
Cell[TextData[{
StyleBox["discrete Cosine transfrom",
FontSlant->"Italic"],
" (DCT) is commonly used in digital signal processing. It converts a \
sequence of ",
StyleBox["real numbers",
FontWeight->"Bold",
FontColor->RGBColor[0, 0, 1]],
" to a sequence of ",
StyleBox["real numbers",
FontWeight->"Bold",
FontColor->RGBColor[0, 0, 1]],
" of the same length. (Recall, the DFT converts a sequence of ",
StyleBox["real numbers (or ",
FontColor->RGBColor[0, 0, 1]],
StyleBox["complex",
FontColor->RGBColor[1, 0, 0]],
StyleBox[")",
FontColor->RGBColor[0, 0, 1]],
" to a sequence of ",
StyleBox["complex numbers",
FontColor->RGBColor[1, 0, 0]],
".) The use of the DCT for image compression was introduced in 1974, and it \
plays an important role in JPEG and MPEG compression schemes."
}], "Text"],
Cell["\", "Text"],
Cell[TextData[{
"I've used two references. First is \"Image Compression Using the Discrete \
Cosine Transform\" by Andrew Watson, ",
StyleBox["Mathematica Journal",
FontSlant->"Italic"],
StyleBox["4",
FontWeight->"Bold"],
" (1994) p. 81. This is a wonderful collection of ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" routines from which I have based this lecture. Second is \"The JPEG Still \
Picture Compression Standard\" by Gregory Wallace, ",
StyleBox["Communications of the ACM",
FontSlant->"Italic"],
" (1991) p. 35. Both articles are available online
however, you do not need to read these articles in order to understand this \
notebook."
}], "Text"],
Cell[CellGroupData[{
Cell["DSP Hardware", "Subsubsection"],
Cell["\", "Text"],
Cell[GraphicsData["CompressedBitmap", "\"], "Graphics",
Evaluatable->False,
ImageSize->{466, 442},
ImageMargins->{{0, 0}, {0, 0}},
ImageRegion->{{0, 1}, {0, 1}}],
Cell["\", "Text"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell["DCT Matrix", "Section"],
Cell["\", "Text"],
Cell[BoxData[
RowBox[{"dctMatrix", "[",
RowBox[{"nSize_:", "8"}], "]"}], " ", ":=", " ",
RowBox[{"Table", "[",
RowBox[{"If", "[",
RowBox[{"m", " ", "\[Equal]", " ", "0"}], ",", " ",
RowBox[{"Sqrt", "[",
RowBox[{"1", "/", "2"}], "]"}], ",", "1"}], "]"}], " ",
RowBox[{"Sqrt", "[",
RowBox[{"2", "/", "nSize"}], "]"}], " ",
RowBox[{"Cos", "[",
RowBox[{"(",
RowBox[{"2", " ", "n"}], " ", "+", "1"}], ")"}], " ", "m", " ",
RowBox[{"\[Pi]", "/",
RowBox[{"(",
RowBox[{"2", " ", "nSize"}], ")"}]}]}], "]"}]}], ",", " ",
RowBox[{"{",
RowBox[{"m", ",", " ", "0", ",", " ",
RowBox[{"nSize", "-", "1"}]}], "}"}], ",", " ",
RowBox[{"{",
RowBox[{"n", ",", " ", "0", ",", " ",
RowBox[{"nSize", "-", "1"}]}], "}"}]}], "]"}]}]], "Input",
CellLabel->"In[1]:="],
Cell[BoxData[
RowBox[{"(",
RowBox[{"dct4", " ", "=", " ",
RowBox[{"dctMatrix", "[", "4", "]"}]}], ")"}], " ", "//", " ",
"TableForm"}]], "Input",
CellLabel->"In[2]:="],
Cell["\", "Text"],
Cell[BoxData[
RowBox[{"dct4", "
RowBox[{"Transpose", "[", "dct4", "]"}]}], " ", "//", " ", "Simplify"}],
" ", "//", " ", "TableForm"}]], "Input",
CellLabel->"In[3]:="],
Cell[TextData[{
"The DCT of a signal ",
StyleBox["s, ",
FontSlant->"Italic"],
"of length 4, is"
}], "Text"],
Cell[BoxData[
RowBox[{"dctMatrix", "[", "4", "]"}], " ", ".", " ",
RowBox[{"{",
RowBox[{"s", "[", "1", "]"}], ",", " ",
RowBox[{"s", "[", "2", "]"}], ",", " ",
RowBox[{"s", "[", "3", "]"}], ",", " ",
RowBox[{"s", "[", "4", "]"}]}], "}"}]}], " ", "//", " ",
"TableForm"}]], "Input",
CellLabel->"In[4]:="],
Cell["A simple-to-write DCT\[Ellipsis]", "Text"],
Cell[BoxData[
RowBox[{"dct1", "[", "x_List", "]"}], " ", ":=", " ",
RowBox[{"Module", "[",
RowBox[{"{",
RowBox[{"mDCT", ",", "n"}], "}"}], ",", "\[IndentingNewLine]",
RowBox[{"n", " ", "=", " ",
RowBox[{"Length", "[", "x", "]"}]}], ";", "\[IndentingNewLine]",
RowBox[{"mDCT", " ", "=", " ",
RowBox[{"N", "[",
RowBox[{"dctMatrix", "[", "n", "]"}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"mDCT", " ", ".", " ", "x"}]}]}], "]"}]}], ";"}]], "Input",
CellLabel->"In[5]:="],
Cell[BoxData[
RowBox[{"dct1", "[",
RowBox[{"{",
RowBox[{"s", "[", "1", "]"}], ",", " ",
RowBox[{"s", "[", "2", "]"}], ",", " ",
RowBox[{"s", "[", "3", "]"}], ",", " ",
RowBox[{"s", "[", "4", "]"}]}], "}"}], "]"}], " "}]], "Input",
CellLabel->"In[6]:="],
Cell[BoxData[
RowBox[{"dct1", "[",
RowBox[{"{",
"1", ",", "2", ",", "3", ",", "4", ",", "4", ",", "3", ",", "2", ",",
"1"}], "}"}], "]"}], " "}]], "Input",
CellLabel->"In[7]:="],
Cell[TextData[{
"To create an inverse transform, we simply Transpose the conversion matrix. \
(The transpose is the inverse since the matrix is ",
StyleBox["orthogonal",
FontSlant->"Italic"],
". Since the DCT is real it is also ",
StyleBox["unitary",
FontSlant->"Italic"],
" as is the FFT,)"
}], "Text"],
Cell[BoxData[
RowBox[{"idct1", "[", "x_List", "]"}], " ", ":=", " ",
RowBox[{"Module", "[",
RowBox[{"{",
RowBox[{"mDCT", ",", "n"}], "}"}], ",", "\[IndentingNewLine]",
RowBox[{"n", " ", "=", " ",
RowBox[{"Length", "[", "x", "]"}]}], ";", "\[IndentingNewLine]",
RowBox[{"mDCT", " ", "=", " ",
RowBox[{"Transpose", "[",
RowBox[{"N", "[",
RowBox[{"dctMatrix", "[", "n", "]"}], "]"}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"mDCT", " ", ".", " ", "x"}]}]}], "]"}]}], ";"}]], "Input",
CellLabel->"In[8]:="],
Cell[BoxData[
RowBox[{"idct1", "[",
RowBox[{"dct1", "[",
RowBox[{"{",
RowBox[{"s", "[", "1", "]"}], ",", " ",
RowBox[{"s", "[", "2", "]"}], ",", " ",
RowBox[{"s", "[", "3", "]"}], ",", " ",
RowBox[{"s", "[", "4", "]"}]}], "}"}], "]"}], "]"}], " ", "//", " ",
"Simplify"}], " ", "//", " ", "Chop", " "}]], "Input",
CellLabel->"In[9]:="],
Cell[CellGroupData[{
Cell["Modes of Length 8", "Subsubsection"],
Cell[BoxData[
RowBox[{"Show", "[",
RowBox[{"GraphicsGrid", "[",
RowBox[{"Partition", "[",
RowBox[{"(",
RowBox[{"BarChart", "[",
RowBox[{"#1", ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}], ",",
RowBox[{"PlotRange", "\[Rule]",
RowBox[{"{",
RowBox[{"-", "0.5`"}], ",", "0.5`"}], "}"}]}]}], "]"}], "&"}],
")"}], "/@",
RowBox[{"dctMatrix", "[", "8", "]"}]}], ",", "2"}], "]"}], "]"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellLabel->"In[10]:="],
Cell[BoxData[
RowBox[{"dct1", "[",
RowBox[{"{",
"1", ",", "2", ",", "3", ",", "4", ",", "4", ",", "3", ",", "2", ",",
"1"}], "}"}], "]"}], " "}]], "Input",
CellLabel->"In[11]:="]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell["Example 1", "Section"],
Cell[BoxData[{
RowBox[{"sData", "=",
RowBox[{"Table", "[",
FractionBox[
RowBox[{"Sin", "[",
FractionBox[
RowBox[{"i", " ", "\[Pi]", " ", "6"}], "32"], "]"}],
RowBox[{"1", "+",
RowBox[{"Abs", "[",
RowBox[{"i", "-", "16"}], "]"}]}]], ",",
RowBox[{"{",
RowBox[{"i", ",", "0", ",",
RowBox[{"32", "-", "1"}]}], "}"}]}], "]"}]}], ";"}], "\n",
RowBox[{"ListPlot", "[",
RowBox[{"sData", ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]}], "Input",
CellLabel->"In[12]:="],
Cell[BoxData[{
RowBox[{"sdct", "=",
RowBox[{"dct1", "[",
RowBox[{"N", "[", "sData", "]"}], "]"}]}], ";"}], "\n",
RowBox[{"ListPlot", "[",
RowBox[{"sdct", ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]}], "Input",
CellLabel->"In[14]:="],
Cell[BoxData[{
RowBox[{"st", "=",
RowBox[{"idct1", "[", "sdct", "]"}]}], ";"}], "\n",
RowBox[{"ListPlot", "[",
RowBox[{"st", ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"PointSize", "[", "0.02`", "]"}]}]}], "]"}]}], "Input",
CellLabel->"In[16]:="],
Cell[BoxData[{
RowBox[{"sf", "=",
RowBox[{"Fourier", "[", "sData", "]"}]}], ";"}], "\n",
RowBox[{"a1", "=",
RowBox[{"ListPlot", "[",
FractionBox[
RowBox[{"Arg", "[", "sf", "]"}], "\[Degree]"], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}]}], "]"}]}],
";"}], "\n",
RowBox[{"a2", "=",
RowBox[{"ListPlot", "[",
RowBox[{"Abs", "[", "sf", "]"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}]}], "]"}]}],
";"}], "\n",
RowBox[{"a3", "=",
RowBox[{"ListPlot", "[",
RowBox[{"Re", "[", "sf", "]"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"{",
RowBox[{"RGBColor", "[",
RowBox[{"0", ",", "0", ",", "1"}], "]"}], ",",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], "}"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}]}], "]"}]}],
";"}], "\n",
RowBox[{"a4", "=",
RowBox[{"ListPlot", "[",
RowBox[{"Im", "[", "sf", "]"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"{",
RowBox[{"RGBColor", "[",
RowBox[{"1", ",", "0", ",", "0"}], "]"}], ",",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], "}"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}]}], "]"}]}],
";"}], "\n",
RowBox[{"Show", "[",
RowBox[{"GraphicsGrid", "[",
RowBox[{"{",
RowBox[{"{",
RowBox[{"a1", ",", "a2"}], "}"}], ",",
RowBox[{"{",
RowBox[{"a3", ",", "a4"}], "}"}]}], "}"}], "]"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]}], "Input",
CellLabel->"In[18]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["DCT via the FFT", "Section"],
Cell["\", "Text"],
Cell[BoxData[{
RowBox[{"Clear", "[", "s", "]"}], ";"}], "\[IndentingNewLine]",
RowBox[{"s1", " ", "=", " ",
RowBox[{"Table", "[",
RowBox[{"s", "[", "i", "]"}], ",", " ",
RowBox[{"{",
RowBox[{"i", ",", " ", "1", ",", " ", "8"}], "}"}]}], "]"}]}]}], "Input",\
CellLabel->"In[24]:="],
Cell[BoxData[
RowBox[{"{",
RowBox[{"xeven", ",", " ", "xodd"}], "}"}], " ", "=", " ",
RowBox[{"Transpose", "[",
RowBox[{"Partition", "[",
RowBox[{"s1", ",", " ", "2"}], "]"}], "]"}]}]], "Input",
CellLabel->"In[26]:="],
Cell[BoxData[
RowBox[{"xeven", " ", "~", " ", "Join", " ", "~", " ",
RowBox[{"Reverse", "[", "xodd", "]"}]}]], "Input",
CellLabel->"In[27]:="],
Cell[BoxData[{
RowBox[{"xfirst", " ", "=", " ",
RowBox[{"Take", "[",
RowBox[{"s1", ",", "4"}], "]"}]}], ";"}], "\[IndentingNewLine]",
RowBox[{"xlast", " ", "=", " ",
RowBox[{"Take", "[",
RowBox[{"s1", ",",
RowBox[{"-", "4"}]}], "]"}]}], ";"}], "\[IndentingNewLine]",
RowBox[{"Flatten", "[",
RowBox[{"Transpose", "[",
RowBox[{"{",
RowBox[{"xfirst", ",", " ",
RowBox[{"Reverse", "[", "xlast", "]"}]}], "}"}], "]"}], "]"}]}], "Input",\
CellLabel->"In[28]:="],
Cell[BoxData[
RowBox[{"dctFourier", "[", "x_List", "]"}], " ", ":=", " ",
RowBox[{"Module", "[",
RowBox[{"{",
"n", ",", "e0", ",", " ", "tFactors", ",", " ", "xeven", ",", " ",
"xodd"}], "}"}], ",", "\[IndentingNewLine]",
RowBox[{"n", " ", "=", " ",
RowBox[{"Length", "[", "x", "]"}]}], ";", "\[IndentingNewLine]",
RowBox[{"{",
RowBox[{"xeven", ",", " ", "xodd"}], "}"}], " ", "=", " ",
RowBox[{"Transpose", "[",
RowBox[{"Partition", "[",
RowBox[{"x", ",", " ", "2"}], "]"}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"e0", " ", "=", " ",
RowBox[{"Exp", "[",
RowBox[{"-", "I"}], " ",
RowBox[{"\[Pi]", "/",
RowBox[{"(",
RowBox[{"2", " ", "n"}], ")"}]}]}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"tFactors", " ", "=", " ",
RowBox[{"{", "1", "}"}], " ", "~", " ", "Join", "~", " ",
RowBox[{"Table", "[",
RowBox[{"Sqrt", "[", "2", "]"}], " ",
RowBox[{"e0", "^", "i"}]}], ",", " ",
RowBox[{"{",
RowBox[{"i", ",", " ", "1", ",", " ",
RowBox[{"n", "-", "1"}]}], "}"}]}], "]"}]}]}], ";",
"\[IndentingNewLine]",
RowBox[{"Re", "[",
RowBox[{"tFactors", " ",
RowBox[{"InverseFourier", "[",
RowBox[{"Join", "[",
RowBox[{"xeven", ",", " ",
RowBox[{"Reverse", "[", "xodd", "]"}]}], "]"}], "]"}]}], "]"}]}]}],
"]"}]}]], "Input",
CellLabel->"In[31]:="],
Cell[BoxData[
RowBox[{"idctFourier", "[", "x_List", "]"}], " ", ":=", "
RowBox[{"Module", "[",
RowBox[{"{",
"n", ",", "e0", ",", "tFactors", ",", " ", "xt", ",", " ", "xfirst", ",",
" ", "xlast"}], "}"}], ",", "\[IndentingNewLine]",
RowBox[{"n", " ", "=", " ",
RowBox[{"Length", "[", "x", "]"}]}], ";", "\[IndentingNewLine]",
RowBox[{"e0", " ", "=", " ",
RowBox[{"Exp", "[",
RowBox[{"-", "I"}], " ",
RowBox[{"\[Pi]", "/",
RowBox[{"(",
RowBox[{"2", " ", "n"}], ")"}]}]}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"tFactors", " ", "=", " ",
RowBox[{"{", "1", "}"}], " ", "~", " ", "Join", "~", " ",
RowBox[{"Table", "[",
RowBox[{"Sqrt", "[", "2", "]"}], " ",
RowBox[{"e0", "^", "i"}]}], ",", " ",
RowBox[{"{",
RowBox[{"i", ",", " ", "1", ",", " ",
RowBox[{"n", "-", "1"}]}], "}"}]}], "]"}]}]}], ";",
"\[IndentingNewLine]",
RowBox[{"tFactors", " ", "=", " ",
RowBox[{"Conjugate", "[",
RowBox[{"N", "[", "tFactors", "]"}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"xt", " ", "=", " ",
RowBox[{"Re", "[",
RowBox[{"Fourier", "[",
RowBox[{"tFactors", " ", "x"}], "]"}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"xfirst", " ", "=", " ",
RowBox[{"Take", "[",
RowBox[{"xt", ",", " ",
RowBox[{"n", "/", "2"}]}], "]"}]}], ";", "\[IndentingNewLine]",
RowBox[{"xlast", " ", "=", " ",
RowBox[{"Take", "[",
RowBox[{"xt", ",",
RowBox[{"-", "n"}], "/", "2"}]}], "]"}]}], ";",
"\[IndentingNewLine]",
RowBox[{"Flatten", "[",
RowBox[{"Transpose", "[",
RowBox[{"{",
RowBox[{"xfirst", ",", " ",
RowBox[{"Reverse", "[", "xlast", "]"}]}], "}"}], "]"}], "]"}]}]}],
"]"}]}]], "Input",
CellLabel->"In[32]:="],
Cell[BoxData[{
RowBox[{"sdct2", "=",
RowBox[{"dctFourier", "[", "sData", "]"}]}], ";"}], "\n",
RowBox[{"ListPlot", "[",
RowBox[{"sdct2", ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]}], "Input",
CellLabel->"In[33]:="],
Cell[BoxData[{
RowBox[{"st2", "=",
RowBox[{"idctFourier", "[", "sdct2", "]"}]}], ";"}], "\n",
RowBox[{"ListPlot", "[",
RowBox[{"st2", ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]}], "Input",
CellLabel->"In[35]:="],
Cell[BoxData[
RowBox[{"sdct", " ", "-", " ", "sdct2"}], " ", "//", " ", "Chop"}]], "Input",\
CellLabel->"In[37]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["Sample", "Section"],
Cell[BoxData[{
RowBox[{"nSize", "=",
SuperscriptBox["2", "10"]}], ";"}], "\n",
RowBox[{"s2", "=",
RowBox[{"Table", "[",
RowBox[{"(",
RowBox[{"Sin", "[",
FractionBox[
RowBox[{"(",
RowBox[{"i", "-", "1"}], ")"}], " ", "2", " ", "\[Pi]", " ",
"6"}], "nSize"], "]"}], "+",
RowBox[{"Sin", "[",
FractionBox[
RowBox[{"(",
RowBox[{"i", "-", "1"}], ")"}], " ", "2", " ", "\[Pi]", " ",
"15"}], "nSize"], "]"}]}], ")"}], " ",
RowBox[{"Sin", "[",
FractionBox[
RowBox[{"\[Pi]", " ", "i"}], "nSize"], "]"}]}], ",",
RowBox[{"{",
RowBox[{"i", ",", "1", ",", "nSize"}], "}"}]}], "]"}]}], ";"}], "\n",
RowBox[{"p1", "=",
RowBox[{"ListPlot", "[",
RowBox[{"s2", ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]}]}], "Input",
CellLabel->"In[38]:="],
Cell[BoxData[{
RowBox[{"sf", "=",
RowBox[{"Fourier", "[", "s2", "]"}]}], ";"}], "\n",
RowBox[{"a1", "=",
RowBox[{"ListPlot", "[",
FractionBox[
RowBox[{"Arg", "[", "sf", "]"}], "\[Degree]"], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}]}], "]"}]}],
";"}], "\n",
RowBox[{"a2", "=",
RowBox[{"ListPlot", "[",
RowBox[{"Abs", "[", "sf", "]"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}]}], "]"}]}],
";"}], "\n",
RowBox[{"Show", "[",
RowBox[{"GraphicsRow", "[",
RowBox[{"{",
RowBox[{"a1", ",", "a2"}], "}"}], "]"}], "]"}]}], "Input",
CellLabel->"In[41]:="],
Cell[BoxData[
RowBox[{"ListPlot", "[",
RowBox[{"Abs", "[",
RowBox[{"sf", "\[LeftDoubleBracket]",
RowBox[{"Range", "[",
RowBox[{"1", ",", "50"}], "]"}], "\[RightDoubleBracket]"}], "]"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}], "]"}]], "Input",
CellLabel->"In[45]:="],
Cell[BoxData[
RowBox[{"ListPlotComplex", "[",
RowBox[{"sf", "\[LeftDoubleBracket]",
RowBox[{"Range", "[",
RowBox[{"1", ",", "50"}], "]"}], "\[RightDoubleBracket]"}], ",", " ",
RowBox[{"PlotRange", "\[Rule]", " ", "All"}], ",", " ",
RowBox[{"PlotStyle", "\[Rule]", " ",
RowBox[{"PointSize", "[", "0.02", "]"}]}], ",", " ",
RowBox[{"PlotLabel", " ", "\[Rule]", " ", "\"\\""}]}], "]"}],
";"}]], "Input",
CellLabel->"In[46]:="],
Cell[BoxData[
RowBox[{"s2c", " ", "=", " ",
RowBox[{"dctFourier", "[", "s2", "]"}]}], ";"}]], "Input",
CellLabel->"In[47]:="],
Cell[BoxData[
RowBox[{"ListPlot", "[",
RowBox[{"s2c", ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}], "]"}]], "Input",
CellLabel->"In[48]:="],
Cell[BoxData[
RowBox[{"ListPlot", "[",
RowBox[{"s2c", "\[LeftDoubleBracket]",
RowBox[{"Range", "[",
RowBox[{"1", ",", "50"}], "]"}], "\[RightDoubleBracket]"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"PointSize", "[", "0.02`", "]"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellLabel->"In[49]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["Importing Sampled Data", "Section"],
Cell[TextData[{
StyleBox["Mathematica",
FontSlant->"Italic"],
" can import common file formats. AIFF (or .aif) stands for \"audio \
interchange file format\" is one of the most widely used format for storing \
and transmitting sampled sound. (Another format, that uses lossy data \
compression, is MP3 (or MPEG-1 Audio Layer-3). ",
StyleBox["Mathematica",
FontSlant->"Italic"],
" can not import an MP3 file. MP3 generally reduces data size by a factor of \
12 while retaining the perception of high fidelity.)"
}], "Text"],
Cell[CellGroupData[{
Cell["Set Directory Path", "Subsection"],
Cell["\", "Text"],
Cell[BoxData[
RowBox[{"SetDirectory", "[", "\"\\"", "]"}]], "Input",
CellLabel->"In[50]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["Audio File Import", "Subsection"],
Cell["\", "Text"],
Cell[BoxData[
RowBox[{"FileNames", "[", "\"\\"", "]"}]], "Input",
CellChangeTimes->{{3.8803`*^9, 3.818*^9}},
CellLabel->"In[51]:="],
Cell[BoxData[
RowBox[{"s", " ", "=", " ",
"Import", "[", "\"\\"", "]"}]}]], "Input",
CellLabel->"In[52]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["Examine Sound Object", "Subsection"],
Cell[BoxData[
RowBox[{"rate", " ", "=", " ",
RowBox[{"Part", "[",
RowBox[{"s", ",", "1", ",", "2"}], "]"}],
RowBox[{"(*", " ",
RowBox[{"Sample", " ",
RowBox[{"Rate", ":", " ",
RowBox[{"Samples", " ", "Per", " ", "Second"}]}]}], " ", "*)"}],
FontColor->RGBColor[0, 1, 0]]}]], "Input",
CellLabel->"In[53]:="],
Cell[BoxData[
RowBox[{"1", "/", "rate"}], " ", "//", " ", "EngineeringForm",
RowBox[{"(*", " ",
RowBox[{"time", " ", "per", " ", "sample"}], " ", "*)"}]}]], "Input",
CellLabel->"In[54]:="],
Cell[BoxData[
RowBox[{"Shallow", "[",
RowBox[{"Part", "[",
RowBox[{"s", ",", "1", ",", "1", ",", "1"}], "]"}], "]"}],
StyleBox[" ",
FontColor->RGBColor[0, 1, 0]],
RowBox[{"(*", " ",
RowBox[{"Data", " ", "List"}], " ", "*)"}],
FontColor->RGBColor[0, 1, 0]]}]], "Input",
CellChangeTimes->{{3.6173`*^9, 3.768*^9}},
CellLabel->"In[55]:="],
Cell[BoxData[
RowBox[{"sData", " ", "=", " ",
RowBox[{"Drop", "[",
RowBox[{"Part", "[",
RowBox[{"s", ",", "1", ",", "1", ",", "1"}], "]"}], ",", "1"}],
"]"}]}], ";"}], " ",
RowBox[{"(*", " ",
RowBox[{"Make", " ", "exactly", " ",
RowBox[{"2", "^", "16"}]}], " ", "=", " ",
RowBox[{"64", " ", "kS"}]}], " ", "*)"}]}]], "Input",
CellChangeTimes->{{3.5014`*^9, 3.82*^9}},
CellLabel->"In[56]:="],
Cell[BoxData[
RowBox[{"nData", " ", "=", " ",
RowBox[{"Length", "[", "sData", "]"}]}]], "Input",
CellLabel->"In[57]:="],
Cell[BoxData[
RowBox[{"(",
RowBox[{"rate", "/", "nData"}], ")"}], " ", "//", " ", "N", " ",
RowBox[{"(*", " ",
RowBox[{"\[CapitalDelta]Frequency", " ", "Interval", " ", "Hz"}], " ",
FontColor->RGBColor[0, 1, 0]]}]], "Input",
CellChangeTimes->{{3.37*^9, 3.605*^9}},
CellLabel->"In[58]:="],
Cell[BoxData[
RowBox[{"{",
RowBox[{"Max", "[", "sData", "]"}], ",", " ",
RowBox[{"Min", "[", "sData", "]"}]}], "}"}]], "Input",
CellLabel->"In[59]:="],
Cell[BoxData[
RowBox[{"ListPlot", "[",
RowBox[{"Take", "[",
RowBox[{"sData", ",",
RowBox[{"{",
RowBox[{"1", ",", "nData", ",", "10"}], "}"}]}], "]"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellLabel->"In[60]:="]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell["Comparing DCT and FFT", "Section"],
Cell[BoxData[{
RowBox[{"scDylan", "=",
RowBox[{"dctFourier", "[", "sData", "]"}]}], ";"}], "\n",
RowBox[{"ListPlot", "[",
RowBox[{"scDylan", ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]}], "Input",
CellLabel->"In[61]:="],
Cell[BoxData[{
RowBox[{"sfDylan", "=",
RowBox[{"Fourier", "[", "sData", "]"}]}], ";"}], "\n",
RowBox[{"ListPlot", "[",
RowBox[{"Abs", "[", "sfDylan", "]"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]}], "Input",
CellLabel->"In[63]:="],
Cell[CellGroupData[{
Cell["Energy DCT", "Subsubsection"],
Cell[BoxData[
RowBox[{"eTotal", " ", "=", " ",
RowBox[{"scDylan", " ", ".", " ", "scDylan"}]}]], "Input",
CellLabel->"In[65]:="],
Cell[BoxData[
RowBox[{"FoldList", "[",
RowBox[{"Plus", ",", " ", "0.0", ",", " ",
RowBox[{"{",
"a", ",", " ", "b", ",", " ", "c", ",", " ", "d", ",", " ", "e", ",", " ",
"f"}], "}"}]}], "]"}]], "Input",
CellLabel->"In[66]:="],
Cell[BoxData[
RowBox[{"eDCT", " ", "=", " ",
RowBox[{"FoldList", "[",
RowBox[{"Plus", ",", " ", "0", ",", " ",
RowBox[{"scDylan", " ", "scDylan"}]}], "]"}], "/", "eTotal"}]}],
";"}]], "Input",
CellLabel->"In[67]:="],
Cell[BoxData[
RowBox[{"ListPlot", "[",
RowBox[{"eDCT", ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellLabel->"In[68]:="],
Cell[BoxData[
RowBox[{"ListPlot", "[",
RowBox[{"eDCT", "\[LeftDoubleBracket]",
RowBox[{"Range", "[",
RowBox[{"1", ",", "4000"}], "]"}], "\[RightDoubleBracket]"}], ",",
RowBox[{"PlotRange", "\[Rule]",
RowBox[{"{",
RowBox[{"0", ",", "1"}], "}"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellLabel->"In[69]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["Energy Fourier", "Subsubsection"],
Cell[BoxData[
RowBox[{"nDylan", " ", "=", " ",
RowBox[{"Length", "[", "sfDylan", "]"}]}]], "Input",
CellLabel->"In[70]:="],
Cell[BoxData[
RowBox[{"sfDylanR", " ", "=", " ",
RowBox[{"sfDylan", "\[LeftDoubleBracket]",
RowBox[{"Range", "[",
RowBox[{"nDylan", "/", "2"}], "+", "1"}], ",", " ", "nDylan"}], "]"}],
"\[RightDoubleBracket]"}], " ", "~", "Join", "~", " ",
RowBox[{"sfDylan", "\[LeftDoubleBracket]",
RowBox[{"Range", "[",
RowBox[{"1", ",",
RowBox[{"nDylan", "/", "2"}]}], "]"}], "\[RightDoubleBracket]"}]}]}],
";"}]], "Input",
CellLabel->"In[71]:="],
Cell[BoxData[
RowBox[{"ListPlot", "[",
RowBox[{"Abs", "[", "sfDylanR", "]"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellLabel->"In[72]:="],
Cell[BoxData[
RowBox[{"eTotal", " ", "=", " ",
RowBox[{"sfDylan", " ", ".", " ",
RowBox[{"Conjugate", "[", "sfDylan", "]"}]}], " ", "//", " ",
"Chop"}]}]], "Input",
CellLabel->"In[73]:="],
Cell[BoxData[
RowBox[{"eTotal", " ", "=", " ",
RowBox[{"sfDylanR", " ", ".", " ",
RowBox[{"Conjugate", "[", "sfDylanR", "]"}]}], " ", "//", " ",
"Chop"}]}]], "Input",
CellLabel->"In[74]:="],
Cell[BoxData[
RowBox[{"eFFT", " ", "=", " ",
RowBox[{"Chop", "[",
RowBox[{"FoldList", "[",
RowBox[{"Plus", ",", " ", "0", ",", " ",
RowBox[{"sfDylanR", " ",
RowBox[{"Conjugate", "[", "sfDylanR", "]"}]}]}], "]"}], "]"}], "/",
"eTotal"}]}], ";"}]], "Input",
CellLabel->"In[75]:="],
Cell[BoxData[
RowBox[{"ListPlot", "[",
RowBox[{"eFFT", ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellLabel->"In[76]:="],
Cell[BoxData[
RowBox[{"ListPlot", "[",
RowBox[{"eFFT", "\[LeftDoubleBracket]",
RowBox[{"Range", "[",
FractionBox["nDylan", "2"], "-", "2000"}], ",",
FractionBox["nDylan", "2"], "+", "2000"}]}], "]"}],
"\[RightDoubleBracket]"}], ",",
RowBox[{"PlotRange", "\[Rule]",
RowBox[{"{",
RowBox[{"0", ",", "1"}], "}"}]}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellLabel->"In[77]:="]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell["Reconstructed (Filtered) Dylan", "Section"],
Cell[BoxData[
RowBox[{"cFilter", " ", "=", " ",
RowBox[{"Table", "[",
RowBox[{"If", "[", " ",
"500", " ", "\[LessEqual]", " ", "i", " ", "\[LessEqual]", " ",
"4000"}], ",", " ", "1", ",", " ", "0"}], "]"}], ",", " ",
RowBox[{"{",
RowBox[{"i", ",", "1", ",", " ",
RowBox[{"Length", "[", "scDylan", "]"}]}], "}"}]}], "]"}]}], ";"}],
RowBox[{"(*", " ",
RowBox[{"300", " ", "Hz", " ", "to", " ", "2.5", " ", "kHz"}], " ", "*)"}],
FontColor->RGBColor[0, 1, 0]]}]], "Input",
CellLabel->"In[78]:="],
Cell[BoxData[
RowBox[{"dylanC", " ", "=", " ",
RowBox[{"idctFourier", "[",
RowBox[{"cFilter", " ", "scDylan"}], "]"}]}], ";"}]], "Input",
CellLabel->"In[79]:="],
Cell[BoxData[
RowBox[{"ListPlay", "[",
RowBox[{"dylanC", ",",
RowBox[{"SampleRate", " ", "\[Rule]", " ", "rate"}]}], "]"}]], "Input",
CellChangeTimes->{3.133*^9},
CellLabel->"In[80]:="],
Cell[BoxData[
RowBox[{"ListPlay", "[",
RowBox[{"sData", ",",
RowBox[{"SampleRate", " ", "\[Rule]", " ", "rate"}]}], "]"}]], "Input",
CellChangeTimes->{3.872*^9},
CellLabel->"In[81]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["2D DCT Modes", "Section"],
Cell["\", "Text"],
Cell[BoxData[
RowBox[{"Array", "[",
RowBox[{"f", ",", " ",
RowBox[{"{",
RowBox[{"8", ",", "8"}], "}"}]}], "]"}]], "Input",
CellLabel->"In[78]:="],
Cell[BoxData[
RowBox[{"Outer", "[",
RowBox[{"Times", ",", " ",
RowBox[{"{",
"m1", ",", " ", "m2", ",", " ", "m3", ",", " ", "m4", ",", " ", "m5"}],
"}"}], ",", " ",
RowBox[{"{",
"n1", ",", " ", "n2", ",", " ", "n3", ",", " ", "n4", ",", " ", "n5"}],
"}"}]}], "]"}], "
", "//", " ", "MatrixForm"}]], "Input",
CellLabel->"In[79]:="],
Cell[BoxData[
RowBox[{"dctTensor", " ", "=", " ",
RowBox[{"Array", "[",
RowBox[{"(",
RowBox[{"Outer", "[",
RowBox[{"Times", ",", " ",
RowBox[{"dctMatrix", "[", "8", "]"}], "\[LeftDoubleBracket]", "#1",
"\[RightDoubleBracket]"}], ",", " ",
RowBox[{"dctMatrix", "[", "8", "]"}], "\[LeftDoubleBracket]", "#2",
"\[RightDoubleBracket]"}]}], "]"}], ")"}], "&"}], ",", " ",
RowBox[{"{",
RowBox[{"8", ",", " ", "8"}], "}"}]}], "]"}]}], ";"}]], "Input",
CellLabel->"In[80]:="],
Cell[BoxData[
RowBox[{"Dimensions", "[", "dctTensor", "]"}]], "Input",
CellLabel->"In[81]:="],
Cell[BoxData[
RowBox[{"dctTensor", " ", "//", " ", "Shallow"}]], "Input",
CellLabel->"In[82]:="],
Cell[BoxData[
RowBox[{"ListDensityPlot", "[",
RowBox[{"dctTensor", "\[LeftDoubleBracket]",
RowBox[{"2", ",", "2"}], "\[RightDoubleBracket]"}], ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellChangeTimes->{{3.0577`*^9, 3.558*^9},
3.372*^9},
CellLabel->"In[83]:="],
Cell[BoxData[
RowBox[{"Show", "[",
RowBox[{"GraphicsGrid", "[",
RowBox[{"Map", "[",
RowBox[{"ListDensityPlot", "[",
RowBox[{"#1", ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"Frame", "\[Rule]", "False"}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}]}], "]"}], "&"}],
",", "dctTensor", ",",
RowBox[{"{", "2", "}"}]}], "]"}], "]"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellChangeTimes->{3.4543`*^9, 3.709*^9},
CellLabel->"In[84]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["A DCT 2d Procedure", "Section"],
Cell[BoxData[
RowBox[{"dct2D", "[",
RowBox[{"array_", "?", "MatrixQ"}], "]"}], " ", ":=", " ",
RowBox[{"Transpose", "[",
RowBox[{"dctFourier", " ", "/@", " ",
RowBox[{"Transpose", "[",
RowBox[{"dctFourier", " ", "/@", " ", "array"}], "]"}]}], "]"}]}],
";"}]], "Input",
CellLabel->"In[85]:="],
Cell[BoxData[
RowBox[{"idct2D", "[",
RowBox[{"array_", "?", "MatrixQ"}], "]"}], " ", ":=", " ",
RowBox[{"Transpose", "[",
RowBox[{"idctFourier", " ", "/@", " ",
RowBox[{"Transpose", "[",
RowBox[{"idctFourier", " ", "/@", " ", "array"}], "]"}]}], "]"}]}],
";"}]], "Input",
CellLabel->"In[86]:="],
Cell[BoxData[{
RowBox[{"iSize", "=",
SuperscriptBox["2", "6"]}], ";"}], "\n",
StyleBox["image1",
FontColor->RGBColor[1, 0, 1]], "=",
RowBox[{"Table", "[",
RowBox[{"Sin", "[",
FractionBox[
RowBox[{"\[Pi]", " ", "i", " ", "3"}], "iSize"], "]"}], " ",
RowBox[{"Sin", "[",
FractionBox[
RowBox[{"\[Pi]", " ", "j", " ", "2"}], "iSize"], "]"}]}], ",",
RowBox[{"{",
RowBox[{"i", ",", "1", ",", "iSize"}], "}"}], ",",
RowBox[{"{",
RowBox[{"j", ",", "1", ",", "iSize"}], "}"}]}], "]"}]}], ";"}], "\n",
RowBox[{"ListDensityPlot", "[",
StyleBox["image1",
FontColor->RGBColor[1, 0, 1]], ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]}], "Input",
CellChangeTimes->{3.497*^9, 3.377*^9},
CellLabel->"In[87]:="],
Cell[BoxData[
RowBox[{"image1DCT", "=",
RowBox[{"dct2D", "[",
StyleBox["image1",
FontColor->RGBColor[1, 0, 1]], "]"}]}], ";"}]], "Input",
CellLabel->"In[90]:="],
Cell[BoxData[
RowBox[{"image1DCT", " ", "//", " ", "Dimensions"}]], "Input",
CellChangeTimes->{{3.91*^9, 3.954*^9}},
CellLabel->"In[91]:="],
Cell[BoxData[
RowBox[{"ListDensityPlot", "[",
StyleBox["image1",
FontColor->RGBColor[1, 0, 1]], "DCT"}]], ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellChangeTimes->{
3.2827`*^9, 3.63*^9, {3.428*^9,
3.1763`*^9}},
CellLabel->"In[92]:="],
Cell[BoxData[
RowBox[{"ListPlot3D", "[",
RowBox[{"image1DCT", ",",
RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}]], "Input",
CellLabel->"In[94]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["Blocked DCT 2D", "Section"],
Cell[TextData[{
" JPEG encoding is performed on blocks of 8 x 8 data. In this section, a \
general purpose algorithm is defined that partitions a graphic into 8 x 8 \
blocks and then performs a DCT on the partitions. ",
StyleBox["(This is based on the previously referenced article by Andrew \
Watson.)",
FontWeight->"Bold",
FontColor->RGBColor[0, 0, 1]]
}], "Text"],
Cell[CellGroupData[{
Cell["Partition", "Subsection"],
Cell[BoxData[
RowBox[{"Clear", "[", "a", "]"}], ";"}]], "Input",
CellLabel->"In[95]:="],
Cell[BoxData[
RowBox[{"alist", " ", "=", " ",
RowBox[{"Table", "[",
RowBox[{"a", "[", "i", "]"}], ",", " ",
RowBox[{"{",
RowBox[{"i", ",", " ", "1", ",", " ", "36"}], "}"}]}], "]"}]}]], "Input",\
CellLabel->"In[96]:="],
Cell[BoxData[
RowBox[{"Partition", "[",
RowBox[{"alist", ",", " ", "8"}], "]"}]], "Input",
CellLabel->"In[97]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["Blocked DCT Definitions", "Subsection"],
Cell[BoxData[{
RowBox[{"bDCTfactors", " ", "=", " ",
RowBox[{"N", "[",
RowBox[{"{", "1", "}"}], " ", "~", " ", "Join", "~", " ",
RowBox[{"Table", "[",
RowBox[{"Sqrt", "[", "2", "]"}], " ",
RowBox[{"Exp", "[",
RowBox[{"-", "I"}], " ", "\[Pi]", " ",
RowBox[{"i", "/",
RowBox[{"(",
RowBox[{"2", " ", "8"}], ")"}]}]}], "]"}]}], ",", " ",
RowBox[{"{",
RowBox[{"i", ",", " ", "1", ",", " ",
RowBox[{"8", "-", "1"}]}], "}"}]}], "]"}]}], "]"}]}],
";"}], "\[IndentingNewLine]",
RowBox[{"bIDCTfactors", " ", "=", " ",
RowBox[{"Conjugate", "[", "bDCTfactors", "]"}]}],
";"}], "\[IndentingNewLine]",
RowBox[{"bDCT", "[", "list_", "]"}], " ", ":=", " ",
RowBox[{"Re", "[", " ",
RowBox[{"bDCTfactors", " ",
RowBox[{"InverseFourier", "[", " ",
RowBox[{"N", "[",
RowBox[{"list", "\[LeftDoubleBracket]",
RowBox[{"{",
"1", ",", "3", ",", "5", ",", "7", ",", "8", ",", "6", ",", "4", ",",
"2"}], "}"}], "\[RightDoubleBracket]"}], "]"}], "]"}]}], "]"}]}],
";"}], "\[IndentingNewLine]",
RowBox[{"bIDCT", "[", "list_", "]"}], " ", ":=", " ",
RowBox[{"Re", "[",
RowBox[{"Fourier", "[",
RowBox[{"bIDCTfactors", " ", "list"}], "]"}], "]"}],
"\[LeftDoubleBracket]",
RowBox[{"{",
"1", ",", "8", ",", "2", ",", "7", ",", "3", ",", "6", ",", "4", ",",
"5"}], "}"}], "\[RightDoubleBracket]"}]}], ";"}], "\[IndentingNewLine]",
RowBox[{"bDCT", "[",
RowBox[{"array_", "?", "MatrixQ"}], "]"}], " ", ":=", " ",
RowBox[{"Transpose", "[",
RowBox[{"bDCT", " ", "/@", " ",
RowBox[{"Transpose", "[",
RowBox[{"bDCT", " ", "/@", " ", "array"}], "]"}]}], "]"}]}],
";"}], "\[IndentingNewLine]",
RowBox[{"bIDCT", "[",
RowBox[{"array_", "?", "MatrixQ"}], "]"}], " ", ":=", " ",
RowBox[{"Transpose", "[",
RowBox[{"bIDCT", " ", "/@", " ",
RowBox[{"Transpose", "[",
RowBox[{"bIDCT", " ", "/@", " ", "array"}], "]"}]}], "]"}]}],
";"}], "\[IndentingNewLine]",
RowBox[{"bDCT", "[",
RowBox[{"list_", "?",
RowBox[{"(",
RowBox[{"Length", "[", "#", "]"}], " ", ">", " ", "8"}], "&"}],
")"}]}], "]"}], " ", ":=", " ",
RowBox[{"Join", " ", "@@", " ",
RowBox[{"(",
RowBox[{"bDCT", " ", "/@", " ",
RowBox[{"Partition", "[",
RowBox[{"list", ",", "8"}], "]"}]}], ")"}]}]}],
";"}], "\[IndentingNewLine]",
RowBox[{"bIDCT", "[",
RowBox[{"list_", "?",
RowBox[{"(",
RowBox[{"Length", "[", "#", "]"}], " ", ">", " ", "8"}], "&"}],
")"}]}], "]"}], " ", ":=", " ",
RowBox[{"Join", " ", "@@", " ",
RowBox[{"(",
RowBox[{"bIDCT", " ", "/@", " ",
RowBox[{"Partition", "[",
RowBox[{"list", ",", "8"}], "]"}]}], ")"}]}]}], ";"}]}], "Input",
CellLabel->"In[98]:="],
Cell[BoxData[
RowBox[{"?", "bDCT"}]], "Input",
CellLabel->"In[106]:="],
Cell[BoxData[
RowBox[{"?", "bIDCT"}]], "Input",
CellLabel->"In[107]:="],
Cell[BoxData[
RowBox[{"b",
StyleBox["image1",
FontColor->RGBColor[1, 0, 1]]}]], " ", "=", " ",
RowBox[{"bDCT", "[",
StyleBox["image1",
FontColor->RGBColor[1, 0, 1]], "]"}]}], ";"}]], "Input",
CellLabel->"In[108]:="],
Cell[BoxData[
RowBox[{"ListDensityPlot", "[",
RowBox[{"b",
StyleBox["image1",
FontColor->RGBColor[1, 0, 1]]}]], ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellChangeTimes->{3.445*^9, 3.376*^9},
CellLabel->"In[109]:="],
Cell[BoxData[
RowBox[{"MatrixPlot", "[",
RowBox[{"b",
StyleBox["image1",
FontColor->RGBColor[1, 0, 1]]}]], ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
RowBox[{"ColorFunction", " ", "\[Rule]", " ", "GrayLevel"}], ",",
RowBox[{"ColorFunctionScaling", " ", "\[Rule]", " ", "False"}], ",",
"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellChangeTimes->{
3.445*^9, 3.376*^9, {3.9327`*^9,
3.426*^9}, {3.408*^9, 3.643*^9}},
CellLabel->"In[110]:="]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell["Dylan Block DCT", "Section"],
Cell[CellGroupData[{
Cell["Get Graphic Data", "Subsection"],
Cell[BoxData[
RowBox[{"SetDirectory", "[", "\"\\"", "]"}]], "Input",
CellLabel->"In[111]:="],
Cell[BoxData[
RowBox[{"FileNames", "[", "\"\\"", "]"}]], "Input",
CellChangeTimes->{{3.962*^9, 3.251*^9}},
CellLabel->"In[112]:="],
Cell[BoxData[
RowBox[{"g1", " ", "=", " ",
RowBox[{"Import", "[", "\"\\"", "]"}]}], ";"}]], "Input",
CellLabel->"In[113]:="],
Cell[BoxData[
RowBox[{"g1Data", " ", "=", " ",
RowBox[{"ImageData", "[",
RowBox[{"g1", ",", "\"\\""}], "]"}]}], ";"}]], "Input",
CellChangeTimes->{{3.3574`*^9, 3.645*^9}, {
3.7887`*^9, 3.297*^9}},
CellLabel->"In[114]:="],
Cell[BoxData[
RowBox[{"Dimensions", "[", "g1Data", "]"}]], "Input",
CellLabel->"In[115]:="],
Cell[BoxData[
RowBox[{"ListDensityPlot", "[",
RowBox[{"g1Data", ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"AspectRatio", "\[Rule]", "Automatic"}]}], "]"}]], "Input",
CellLabel->"In[116]:="],
Cell[BoxData[
RowBox[{"GraphicsRow", "[",
RowBox[{"{",
RowBox[{"MatrixPlot", "[",
RowBox[{"g1Data", ",", " ",
RowBox[{"ColorFunction", " ", "\[Rule]", " ", "GrayLevel"}]}], "]"}],
RowBox[{"g1Data", " ", "=", " ",
RowBox[{"Reverse", "[",
RowBox[{"g1Data", ",", "1"}], "]"}]}], ";", "\[IndentingNewLine]",
RowBox[{"MatrixPlot", "[",
RowBox[{"g1Data", ",", " ",
RowBox[{"ColorFunction", " ", "\[Rule]", " ", "GrayLevel"}]}],
"]"}]}]}], "}"}], "]"}]], "Input",
CellChangeTimes->{{3.432*^9, 3.2487`*^9}, {
3.291*^9, 3.64*^9}, {3.6837`*^9,
3.211*^9}, {3.339*^9, 3.593*^9}, {
3.403*^9, 3.536*^9}, 3.8523`*^9, {
3.8037`*^9, 3.04*^9}, 3.332*^9, {
3.316*^9, 3.854*^9}, 3.729*^9},
CellLabel->"In[117]:="],
Cell[BoxData[
RowBox[{"ListDensityPlot", "[",
RowBox[{"g1Data", ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"AspectRatio", "\[Rule]", "Automatic"}]}], "]"}]], "Input",
CellChangeTimes->{{3.232*^9, 3.7173`*^9},
3.689*^9},
CellLabel->"In[118]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["DCT", "Subsection"],
Cell[BoxData[{
RowBox[{"bg1", " ", "=", " ",
RowBox[{"bDCT", "[", "g1Data", "]"}]}], ";"}], "\[IndentingNewLine]",
RowBox[{"Dimensions", "[", "bg1", "]"}]}], "Input",
CellLabel->"In[119]:="],
Cell[BoxData[
RowBox[{"ListDensityPlot", "[",
RowBox[{"bg1", ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}]}], "]"}]], "Input",
CellChangeTimes->{3.525*^9, 3.33*^9},
CellLabel->"In[121]:="],
Cell[BoxData[
RowBox[{"ListDensityPlot", "[",
RowBox[{"bg1", ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"AspectRatio", "\[Rule]", "Automatic"}]}], "]"}]], "Input",
CellChangeTimes->{3.827*^9, 3.513*^9},
CellLabel->"In[122]:="],
Cell[BoxData[
RowBox[{"big1Data", " ", "=", " ",
RowBox[{"bIDCT", "[", "bg1", "]"}]}], ";"}]], "Input",
CellLabel->"In[123]:="],
Cell[BoxData[
RowBox[{"g1Data", " ", "-", " ", "big1Data"}], " ", "//", " ", "Chop"}],
" ", "//", " ", "Abs"}], " ", "//", " ", "Max"}]], "Input",
CellLabel->"In[124]:="]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell["JPEG Quantization", "Section"],
Cell["\", "Text"],
Cell[TextData[{
"In general,higher spatial frequencies are less visible to the human eye \
than low frequencies.Therefore,the quantization factors are usually chosen to \
be larger for the higher frequencies. (A mode is \"quantized\" by ",
StyleBox["dividing",
FontSlant->"Italic"],
" by the quantization factor. A large number ",
StyleBox["reduces",
FontSlant->"Italic"],
" the relative weight of the component.) ",
"The following quantization matrix is widely used for monochrome images and \
for the luminance component of a color image. According to Watson, the \"de \
facto\" quantization matrix for JPEG encoding is given by the following."
}], "Text"],
Cell[BoxData[
RowBox[{"qLum", " ", "=", "\n",
RowBox[{"{",
RowBox[{"{",
"16", ",", " ", "11", ",", " ", "10", ",", " ", "16", ",", " ", "24",
",", " ", "40", ",", " ", "51", ",", " ", "61"}], "}"}], ",", "\n",
RowBox[{"{",
"12", ",", " ", "12", ",", " ", "14", ",", " ", "19", ",", " ", "26",
",", " ", "58", ",", " ", "60", ",", " ", "55"}], "}"}], ",", "\n",
RowBox[{"{",
"14", ",", " ", "13", ",", " ", "16", ",", " ", "24", ",", " ", "40",
",", " ", "57", ",", " ", "69", ",", " ", "56"}], "}"}], ",", "\n",
RowBox[{"{",
"14", ",", " ", "17", ",", " ", "22", ",", " ", "29", ",", " ", "51",
",", " ", "87", ",", " ", "80", ",", " ", "62"}], "}"}], ",", "\n",
RowBox[{"{",
"18", ",", " ", "22", ",", " ", "37", ",", " ", "56", ",", " ", "68",
",", "109", ",", "103", ",", " ", "77"}], "}"}], ",", "\n",
RowBox[{"{",
"24", ",", " ", "35", ",", " ", "55", ",", " ", "64", ",", " ", "81",
",", "104", ",", "113", ",", " ", "92"}], "}"}], ",", "\n",
RowBox[{"{",
"49", ",", " ", "64", ",", " ", "78", ",", " ", "87", ",", "103", ",",
"121", ",", "120", ",", "101"}], "}"}], ",", "\n",
RowBox[{"{",
"72", ",", " ", "92", ",", " ", "95", ",", " ", "98", ",", "112", ",",
"100", ",", "103", ",", " ", "99"}], "}"}]}], "}"}]}], ";"}],
FontFamily->"Courier",
FontWeight->"Bold"]], "Input",
CellLabel->"In[125]:="],
Cell[BoxData[
RowBox[{"ListDensityPlot", "[",
RowBox[{"qLum", ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"PlotRange", "\[Rule]", "All"}], ",",
"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellChangeTimes->{3.177*^9, 3.449*^9},
CellLabel->"In[126]:="],
Cell[CellGroupData[{
Cell["Quantized Functions", "Subsection"],
Cell[BoxData[
RowBox[{"BlockImage", "[",
RowBox[{"image_", ",", " ",
RowBox[{"blocksize_:",
RowBox[{"{",
RowBox[{"8", ",", " ", "8"}], "}"}]}]}], "]"}], " ", ":=",
RowBox[{"Partition", "[",
RowBox[{"image", ",", " ", "blocksize"}], "]"}], " ", "/;",
RowBox[{"And", " ", "@@", " ",
RowBox[{"IntegerQ", " ", "/@", " ",
RowBox[{"(",
RowBox[{"Dimensions", "[", "image", "]"}], "/", "blocksize"}],
")"}]}]}]}]}],
FontFamily->"Courier",
FontWeight->"Bold"]], "Input",
CellLabel->"In[127]:="],
Cell[BoxData[
RowBox[{"UnBlockImage", "[", "blocks_", "]"}], " ", ":=", " ",
RowBox[{"Partition", "[",
RowBox[{"Flatten", "[",
RowBox[{"Transpose", "[",
RowBox[{"blocks", ",", " ",
RowBox[{"{",
RowBox[{"1", ",", " ", "3", ",", " ", "2"}], "}"}]}], "]"}], "]"}],
RowBox[{"{",
RowBox[{"Times", " ", "@@", " ",
RowBox[{"Dimensions", "[", "blocks", "]"}], "[",
RowBox[{"[",
RowBox[{"{",
RowBox[{"2", ",", " ", "4"}], "}"}], "]"}], "]"}]}], "}"}]}],
FontFamily->"Courier",
FontWeight->"Bold"]], "Input",
CellLabel->"In[128]:="],
Cell[BoxData[
RowBox[{"(",
RowBox[{"tImage", " ", "=", " ",
RowBox[{"Table", "[",
RowBox[{"i", " ", "+", " ",
RowBox[{"8",
RowBox[{"(",
RowBox[{"j", "-", "1"}], ")"}]}]}], ",", " ",
RowBox[{"{",
RowBox[{"j", ",", " ", "4"}], "}"}], ",", " ",
RowBox[{"{",
RowBox[{"i", ",", " ", "6"}], "}"}]}], "]"}],
FontFamily->"Courier",
FontWeight->"Bold"]}],
StyleBox[")",
FontFamily->"Courier",
FontWeight->"Bold"]}],
StyleBox[" ",
FontFamily->"Courier",
FontWeight->"Bold"],
StyleBox["//",
FontFamily->"Courier",
FontWeight->"Bold"],
StyleBox[" ",
FontFamily->"Courier",
FontWeight->"Bold"],
StyleBox["MatrixForm",
FontFamily->"Courier",
FontWeight->"Bold"]}]], "Input",
CellLabel->"In[129]:="],
Cell[BoxData[
RowBox[{"BlockImage", "[",
RowBox[{"tImage", ",", " ",
RowBox[{"{",
RowBox[{"2", ",", " ", "3"}], "}"}]}], "]"}], " ", "//", " ",
"MatrixForm"}],
FontFamily->"Courier",
FontWeight->"Bold"]], "Input",
CellLabel->"In[130]:="],
Cell[BoxData[
RowBox[{"UnBlockImage", "[",
RowBox[{"BlockImage", "[",
RowBox[{"tImage", ",", " ",
RowBox[{"{",
RowBox[{"2", ",", " ", "3"}], "}"}]}], "]"}], "]"}], " ", "//", " ",
"MatrixForm"}],
FontFamily->"Courier",
FontWeight->"Bold"]], "Input",
CellLabel->"In[131]:="],
Cell[BoxData[
RowBox[{"bQuantize",
StyleBox["[",
FontFamily->"Courier",
FontWeight->"Bold"],
RowBox[{"image_", ",", " ", "qMatrix_"}],
FontFamily->"Courier",
FontWeight->"Bold"],
StyleBox["]",
FontFamily->"Courier",
FontWeight->"Bold"]}],
StyleBox[" ",
FontFamily->"Courier",
FontWeight->"Bold"],
StyleBox[":=",
FontFamily->"Courier",
FontWeight->"Bold"],
StyleBox[" ",
FontFamily->"Courier",
FontWeight->"Bold"],
RowBox[{"Map", "[",
RowBox[{"(",
RowBox[{"#", "/",
StyleBox["qMatrix",
FontColor->RGBColor[1, 0, 1]]}], ")"}], "&"}], ",", " ",
RowBox[{"BlockImage", "[",
RowBox[{"image", ",", " ",
RowBox[{"Dimensions", "[", "qMatrix", "]"}]}], "]"}], ",",
RowBox[{"{", "2", "}"}]}], "]"}], " ", "//", "UnBlockImage"}], " ", "//",
StyleBox["Round",
FontColor->RGBColor[1, 0, 0]]}],
FontFamily->"Courier",
FontWeight->"Bold"]}],
StyleBox[";",
FontFamily->"Courier",
FontWeight->"Bold"]}]], "Input",
CellLabel->"In[132]:="],
Cell[BoxData[
RowBox[{"bUnQuantize", "[",
RowBox[{"image_", ",", " ", "qMatrix_"}], "]"}], " ", ":=", " ",
RowBox[{"Map", "[",
RowBox[{"(",
RowBox[{"#", " ",
StyleBox["qMatrix",
FontColor->RGBColor[1, 0, 1]]}], ")"}], "&"}], ",", " ",
RowBox[{"BlockImage", "[",
RowBox[{"image", ",", " ",
RowBox[{"Dimensions", "[", "qMatrix", "]"}]}], "]"}], ",",
RowBox[{"{", "2", "}"}]}], "]"}], " ", "//", "UnBlockImage"}]}],
FontFamily->"Courier",
FontWeight->"Bold"]], "Input",
CellLabel->"In[133]:="]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell["Examples", "Section"],
Cell[BoxData[
RowBox[{"{",
RowBox[{"Dimensions", "[", "g1Data", "]"}], ",", " ",
RowBox[{"Dimensions", "[", "g1Data", "]"}], "/", "8"}]}], "}"}]], "Input",\
CellLabel->"In[134]:="],
Cell[BoxData[{
RowBox[{"bg1", "=",
RowBox[{"bDCT", "[", "g1Data", "]"}]}], ";"}], "\n",
RowBox[{"ListDensityPlot", "[",
RowBox[{"bg1", ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",",
RowBox[{"Frame", "\[Rule]", "False"}]}], "]"}]}], "Input",
CellChangeTimes->{3.453*^9, 3.677*^9},
CellLabel->"In[135]:="],
Cell[BoxData[{
RowBox[{"bqg1", "=",
RowBox[{"bQuantize", "[",
RowBox[{"bg1", ",", "qLum"}], "]"}]}], ";"}], "\n",
RowBox[{"ListDensityPlot", "[",
RowBox[{"bqg1", ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",",
RowBox[{"Frame", "\[Rule]", "False"}]}], "]"}]}], "Input",
CellChangeTimes->{3.5877`*^9, 3.1367`*^9},
CellLabel->"In[137]:="],
Cell[BoxData[{
RowBox[{"buqg1", "=",
RowBox[{"bUnQuantize", "[",
RowBox[{"bqg1", ",", "qLum"}], "]"}]}], ";"}], "\n",
RowBox[{"ListDensityPlot", "[",
RowBox[{"buqg1", ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",",
RowBox[{"Frame", "\[Rule]", "False"}]}], "]"}]}], "Input",
CellChangeTimes->{3.901*^9, 3.7843`*^9},
CellLabel->"In[139]:="],
Cell[BoxData[{
RowBox[{"lp1", "=",
RowBox[{"ListPlot", "[",
RowBox[{"bg1", "\[LeftDoubleBracket]",
RowBox[{"Range", "[",
RowBox[{"1", ",", "80"}], "]"}], ",", "9"}],
"\[RightDoubleBracket]"}], ",",
RowBox[{"Joined", "\[Rule]", "True"}], ",",
RowBox[{"PlotRange", "\[Rule]",
RowBox[{"{",
RowBox[{"-", "10"}], ",", "256"}], "}"}]}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"{",
RowBox[{"Thickness", "[", "0.01`", "]"}], ",",
RowBox[{"RGBColor", "[",
RowBox[{"1", ",", "0", ",", "0"}], "]"}]}], "}"}]}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}]}], "]"}]}],
";"}], "\n",
RowBox[{"lp2", "=",
RowBox[{"ListPlot", "[",
RowBox[{"buqg1", "\[LeftDoubleBracket]",
RowBox[{"Range", "[",
RowBox[{"1", ",", "80"}], "]"}], ",", "9"}],
"\[RightDoubleBracket]"}], ",",
RowBox[{"Joined", "\[Rule]", "True"}], ",",
RowBox[{"PlotRange", "\[Rule]",
RowBox[{"{",
RowBox[{"-", "10"}], ",", "256"}], "}"}]}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"RGBColor", "[",
RowBox[{"0", ",", "0", ",", "1"}], "]"}]}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}]}], "]"}]}],
";"}], "\n",
RowBox[{"Show", "[",
RowBox[{"lp1", ",", "lp2", ",",
RowBox[{"DisplayFunction", "\[Rule]", "$DisplayFunction"}], ",",
"PlotLabel", "\[Rule]",
"\"\\""}]}], "]"}]}], "Input",
CellLabel->"In[141]:="],
Cell[BoxData[{
RowBox[{"lp1", "=",
RowBox[{"ListPlot", "[",
RowBox[{"bg1", "\[LeftDoubleBracket]",
RowBox[{"Range", "[",
RowBox[{"1", ",", "80"}], "]"}], ",", "9"}],
"\[RightDoubleBracket]"}], ",",
RowBox[{"Joined", "\[Rule]", "True"}], ",",
RowBox[{"PlotRange", "\[Rule]",
RowBox[{"{",
RowBox[{"-", "10"}], ",", "25"}], "}"}]}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"{",
RowBox[{"Thickness", "[", "0.01`", "]"}], ",",
RowBox[{"RGBColor", "[",
RowBox[{"1", ",", "0", ",", "0"}], "]"}]}], "}"}]}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}]}], "]"}]}],
";"}], "\n",
RowBox[{"lp2", "=",
RowBox[{"ListPlot", "[",
RowBox[{"buqg1", "\[LeftDoubleBracket]",
RowBox[{"Range", "[",
RowBox[{"1", ",", "80"}], "]"}], ",", "9"}],
"\[RightDoubleBracket]"}], ",",
RowBox[{"Joined", "\[Rule]", "True"}], ",",
RowBox[{"PlotRange", "\[Rule]",
RowBox[{"{",
RowBox[{"-", "10"}], ",", "25"}], "}"}]}], ",",
RowBox[{"PlotStyle", "\[Rule]",
RowBox[{"RGBColor", "[",
RowBox[{"0", ",", "0", ",", "1"}], "]"}]}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}]}], "]"}]}],
";"}], "\n",
RowBox[{"Show", "[",
RowBox[{"lp1", ",", "lp2", ",",
RowBox[{"DisplayFunction", "\[Rule]", "$DisplayFunction"}], ",",
"PlotLabel", "\[Rule]",
"\"\\""}]}], "]"}]}], "Input",
CellLabel->"In[144]:="],
Cell[CellGroupData[{
Cell["Data Compression", "Subsection"],
Cell[BoxData[
RowBox[{"Count", "[",
RowBox[{"Flatten", "[", "bg1", "]"}], ",", " ",
RowBox[{"_", "?",
RowBox[{"(",
RowBox[{"#", " ", "\[Equal]", " ", "0"}], " ", "&"}], ")"}]}]}],
"]"}]], "Input",
CellLabel->"In[147]:="],
Cell[BoxData[
RowBox[{"Count", "[",
RowBox[{"Flatten", "[", "buqg1", "]"}], ",", " ",
RowBox[{"_", "?",
RowBox[{"(",
RowBox[{"#", " ", "\[Equal]", " ", "0"}], " ", "&"}], ")"}]}]}],
"]"}]], "Input",
CellLabel->"In[148]:="],
Cell[BoxData[
RowBox[{"Histogram", "[",
RowBox[{"Flatten", "[", "bg1", "]"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellLabel->"In[149]:="],
Cell[BoxData[
RowBox[{"Histogram", "[",
RowBox[{"Flatten", "[", "buqg1", "]"}], ",",
RowBox[{"PlotLabel", "\[Rule]", "\"\\""}]}],
"]"}]], "Input",
CellLabel->"In[150]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["Default Compression", "Subsection"],
Cell[BoxData[
RowBox[{"q1Data", " ", "=", " ",
RowBox[{"g1Data", " ", "//", " ", "bDCT"}], " ", "//", " ",
RowBox[{"bQuantize", "[",
RowBox[{"#", ",", "qLum"}], "]"}], "&"}]}], " ", "//", " ",
RowBox[{"bUnQuantize", "[",
RowBox[{"#", ",", " ", "qLum"}], "]"}], "&"}]}], " ", "//", " ",
"bIDCT"}]}], ";"}]], "Input",
CellLabel->"In[151]:="],
Cell[BoxData[
RowBox[{"Show", "[",
RowBox[{"GraphicsRow", "[",
RowBox[{"(",
RowBox[{"ListDensityPlot", "[",
RowBox[{"#1", ",",
RowBox[{"PlotRange", "\[Rule]",
RowBox[{"{",
RowBox[{"0", ",", "255"}], "}"}]}], ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}], ",",
RowBox[{"Frame", "\[Rule]", "False"}]}], "]"}], "&"}], ")"}], "/@",
RowBox[{"{",
RowBox[{"g1Data", ",", "q1Data"}], "}"}]}], "]"}], "]"}]], "Input",
CellChangeTimes->{3.7847`*^9, 3.331*^9},
CellLabel->"In[152]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["Low Quality Compression", "Subsection"],
Cell[BoxData[
RowBox[{"q1Data8", " ", "=", " ",
RowBox[{"g1Data", " ", "//", " ", "bDCT"}], " ", "//", " ",
RowBox[{"bQuantize", "[",
RowBox[{"#", ",",
RowBox[{"8", "qLum"}]}], "]"}], "&"}]}], " ", "//", " ",
RowBox[{"bUnQuantize", "[",
RowBox[{"#", ",", " ",
RowBox[{"8", "qLum"}]}], "]"}], "&"}]}], " ", "//", " ", "bIDCT"}]}],
";"}]], "Input",
CellLabel->"In[153]:="],
Cell[BoxData[
RowBox[{"Show", "[",
RowBox[{"GraphicsRow", "[",
RowBox[{"(",
RowBox[{"ListDensityPlot", "[",
RowBox[{"#1", ",",
RowBox[{"PlotRange", "\[Rule]",
RowBox[{"{",
RowBox[{"0", ",", "255"}], "}"}]}], ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}], ",",
RowBox[{"Frame", "\[Rule]", "False"}]}], "]"}], "&"}], ")"}], "/@",
RowBox[{"{",
RowBox[{"g1Data", ",", "q1Data8"}], "}"}]}], "]"}], "]"}]], "Input",
CellChangeTimes->{3.775*^9, 3.2433`*^9},
CellLabel->"In[154]:="]
}, Closed]],
Cell[CellGroupData[{
Cell["High Quality Compression", "Subsection"],
Cell[BoxData[
RowBox[{"q1Data025", " ", "=", " ",
RowBox[{"g1Data", " ", "//", " ", "bDCT"}], " ", "//", " ",
RowBox[{"bQuantize", "[",
RowBox[{"#", ",",
RowBox[{"0.25", "qLum"}]}], "]"}], "&"}]}], " ", "//", " ",
RowBox[{"bUnQuantize", "[",
RowBox[{"#", ",", " ",
RowBox[{"0.25", "qLum"}]}], "]"}], "&"}]}], " ", "//", " ",
"bIDCT"}]}], ";"}]], "Input",
CellLabel->"In[155]:="],
Cell[BoxData[
RowBox[{"Show", "[",
RowBox[{"GraphicsRow", "[",
RowBox[{"(",
RowBox[{"ListDensityPlot", "[",
RowBox[{"#1", ",",
RowBox[{"PlotRange", "\[Rule]",
RowBox[{"{",
RowBox[{"0", ",", "255"}], "}"}]}], ",",
RowBox[{"Mesh", "\[Rule]", "False"}], ",",
RowBox[{"AspectRatio", "\[Rule]", "Automatic"}], ",",
RowBox[{"DisplayFunction", "\[Rule]", "Identity"}], ",",
RowBox[{"Frame", "\[Rule]", "False"}]}], "]"}], "&"}], ")"}], "/@",
RowBox[{"{",
RowBox[{"g1Data", ",", "q1Data025"}], "}"}]}], "]"}], "]"}]], "Input",
CellChangeTimes->{3.152*^9, 3.6337`*^9},
CellLabel->"In[156]:="]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell["Summary", "Section"],
Cell["\", "Text"],
Cell["\", "Text"]
}, Closed]]
WindowSize->{},
WindowMargins->{{56, Automatic}, {Automatic, 8}},
PrintingCopies->1,
PrintingPageRange->{1, Automatic},
ShowSelection->True,
Magnification:>FEPrivate`If[
FEPrivate`Equal[FEPrivate`$VersionNumber, 6.], 1.25, 1.25 Inherited],
FrontEndVersion->"8.0 for Mac OS X x86 (32-bit, 64-bit Kernel) (October 5, \
StyleDefinitions->"TutorialBook.nb"
(* End of Notebook Content *)
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
(*CellTagsIndex
CellTagsIndex->{}
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[567, 22, 74, 3, 129, "Title"],
Cell[644, 27, 62, 3, 53, "Subsubtitle"],
Cell[CellGroupData[{
Cell[731, 34, 31, 0, 108, "Section"],
Cell[765, 36, 830, 25, 69, "Text"],
Cell[8, 3, 27, "Text"],
Cell[0, 18, 90, "Text"],
Cell[CellGroupData[{
Cell[, 0, 40, "Subsubsection"],
Cell[9, 4, 48, "Text"],
Cell[, 563, "Graphics",
Evaluatable->False],
Cell[202, 292, 5, 69, "Text"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[213, 29, 0, 63, "Section"],
Cell[215, 173, 3, 48, "Text"],
Cell[220, 965, 28, 84, "Input"],
Cell[250, 192, 6, 33, "Input"],
Cell[258, 78, 2, 27, "Text"],
Cell[262, 215, 6, 33, "Input"],
Cell[270, 112, 5, 27, "Text"],
Cell[277, 372, 11, 33, "Input"],
Cell[290, 48, 0, 27, "Text"],
Cell[292, 595, 16, 109, "Input"],
Cell[310, 306, 9, 33, "Input"],
Cell[321, 218, 7, 33, "Input"],
Cell[330, 312, 9, 48, "Text"],
Cell[341, 639, 17, 109, "Input"],
Cell[360, 422, 12, 33, "Input"],
Cell[CellGroupData[{
Cell[376, 42, 0, 40, "Subsubsection"],
Cell[378, 703, 21, 134, "Input"],
Cell[401, 219, 7, 33, "Input"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[414, 28, 0, 63, "Section"],
Cell[416, 748, 22, 132, "Input"],
Cell[440, 439, 12, 84, "Input"],
Cell[454, 329, 9, 59, "Input"],
Cell[465, 9, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[538, 34, 0, 63, "Section"],
Cell[540, 159, 3, 27, "Text"],
Cell[545, 327, 10, 59, "Input"],
Cell[557, 246, 7, 33, "Input"],
Cell[566, 147, 3, 33, "Input"],
Cell[571, 526, 16, 84, "Input"],
Cell[589, 9, "Input"],
Cell[637, 4, "Input"],
Cell[696, 417, 11, 84, "Input"],
Cell[709, 415, 11, 84, "Input"],
Cell[722, 129, 4, 33, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[731, 25, 0, 63, "Section"],
Cell[733, 2, "Input"],
Cell[768, 4, "Input"],
Cell[801, 464, 12, 59, "Input"],
Cell[815, 496, 12, 59, "Input"],
Cell[829, 142, 4, 33, "Input"],
Cell[835, 298, 7, 59, "Input"],
Cell[844, 441, 11, 59, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[860, 41, 0, 63, "Section"],
Cell[862, 530, 11, 69, "Text"],
Cell[CellGroupData[{
Cell[877, 40, 0, 43, "Subsection"],
Cell[879, 124, 3, 27, "Text"],
Cell[884, 106, 2, 33, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[891, 39, 0, 43, "Subsection"],
Cell[893, 124, 3, 27, "Text"],
Cell[898, 166, 3, 33, "Input"],
Cell[903, 151, 4, 33, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[912, 42, 0, 43, "Subsection"],
Cell[914, 352, 10, 33, "Input"],
Cell[926, 208, 5, 33, "Input"],
Cell[933, 411, 12, 33, "Input"],
Cell[947, 511, 15, 33, "Input"],
Cell[964, 124, 3, 33, "Input"],
Cell[969, 366, 10, 33, "Input"],
Cell[981, 171, 5, 33, "Input"],
Cell[988, 353, 10, 59, "Input"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[004, 40, 0, 63, "Section"],
Cell[006, 332, 9, 59, "Input"],
Cell[017, 365, 10, 84, "Input"],
Cell[CellGroupData[{
Cell[031, 35, 0, 40, "Subsubsection"],
Cell[033, 133, 3, 33, "Input"],
Cell[038, 258, 7, 33, "Input"],
Cell[047, 261, 8, 33, "Input"],
Cell[057, 234, 6, 33, "Input"],
Cell[065, 414, 11, 59, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[081, 39, 0, 40, "Subsubsection"],
Cell[083, 127, 3, 33, "Input"],
Cell[088, 543, 15, 59, "Input"],
Cell[105, 268, 7, 59, "Input"],
Cell[114, 213, 6, 33, "Input"],
Cell[122, 215, 6, 33, "Input"],
Cell[130, 343, 10, 33, "Input"],
Cell[142, 225, 6, 33, "Input"],
Cell[150, 529, 16, 105, "Input"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[172, 49, 0, 63, "Section"],
Cell[174, 642, 18, 59, "Input"],
Cell[194, 182, 5, 33, "Input"],
Cell[201, 207, 5, 33, "Input"],
Cell[208, 206, 5, 33, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[218, 31, 0, 63, "Section"],
Cell[220, 150, 3, 27, "Text"],
Cell[225, 159, 5, 33, "Input"],
Cell[232, 410, 12, 59, "Input"],
Cell[246, 628, 17, 59, "Input"],
Cell[265, 95, 2, 33, "Input"],
Cell[269, 98, 2, 33, "Input"],
Cell[273, 419, 10, 33, "Input"],
Cell[285, 657, 17, 134, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[307, 37, 0, 63, "Section"],
Cell[309, 346, 10, 59, "Input"],
Cell[321, 349, 10, 59, "Input"],
Cell[333, 973, 29, 122, "Input"],
Cell[364, 187, 6, 33, "Input"],
Cell[372, 166, 3, 33, "Input"],
Cell[377, 497, 14, 59, "Input"],
Cell[393, 158, 4, 33, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[402, 33, 0, 63, "Section"],
Cell[404, 372, 8, 48, "Text"],
Cell[CellGroupData[{
Cell[416, 31, 0, 43, "Subsection"],
Cell[418, 100, 3, 33, "Input"],
Cell[423, 252, 8, 33, "Input"],
Cell[433, 118, 3, 33, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[441, 45, 0, 43, "Subsection"],
Cell[443, 4, "Input"],
Cell[541, 72, 2, 33, "Input"],
Cell[545, 73, 2, 33, "Input"],
Cell[549, 280, 10, 33, "Input"],
Cell[561, 450, 13, 59, "Input"],
Cell[576, 689, 17, 59, "Input"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[599, 34, 0, 63, "Section"],
Cell[CellGroupData[{
Cell[603, 38, 0, 43, "Subsection"],
Cell[605, 107, 2, 33, "Input"],
Cell[609, 165, 3, 33, "Input"],
Cell[614, 156, 4, 33, "Input"],
Cell[620, 300, 7, 33, "Input"],
Cell[629, 93, 2, 33, "Input"],
Cell[633, 216, 5, 33, "Input"],
Cell[640, , "Input"],
Cell[664, 310, 7, 33, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[676, 25, 0, 43, "Subsection"],
Cell[678, 209, 5, 59, "Input"],
Cell[685, 326, 7, 33, "Input"],
Cell[694, 277, 6, 33, "Input"],
Cell[702, 144, 4, 33, "Input"],
Cell[708, 212, 6, 33, "Input"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[720, 36, 0, 63, "Section"],
Cell[722, 326, 5, 69, "Text"],
Cell[729, 668, 13, 90, "Text"],
Cell[744, 4, "Input"],
Cell[786, 361, 9, 59, "Input"],
Cell[CellGroupData[{
Cell[799, 41, 0, 43, "Subsection"],
Cell[801, 615, 19, 84, "Input"],
Cell[822, 702, 22, 84, "Input"],
Cell[846, 866, 32, 33, "Input"],
Cell[880, 289, 10, 33, "Input"],
Cell[892, 333, 11, 33, "Input"],
Cell[905, , "Input"],
Cell[952, 639, 19, 84, "Input"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[977, 27, 0, 63, "Section"],
Cell[979, 215, 7, 33, "Input"],
Cell[988, 417, 10, 59, "Input"],
Cell[000, 453, 11, 84, "Input"],
Cell[013, 456, 11, 84, "Input"],
Cell[026, 4, "Input"],
Cell[076, 4, "Input"],
Cell[CellGroupData[{
Cell[128, 38, 0, 43, "Subsection"],
Cell[130, 270, 9, 33, "Input"],
Cell[141, 272, 9, 33, "Input"],
Cell[152, 210, 6, 33, "Input"],
Cell[160, 218, 6, 33, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[171, 41, 0, 43, "Subsection"],
Cell[173, 464, 14, 59, "Input"],
Cell[189, 733, 18, 134, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[212, 45, 0, 43, "Subsection"],
Cell[214, 512, 16, 84, "Input"],
Cell[232, 734, 18, 134, "Input"]
}, Closed]],
Cell[CellGroupData[{
Cell[255, 46, 0, 43, "Subsection"],
Cell[257, 522, 16, 84, "Input"],
Cell[275, 736, 18, 134, "Input"]
}, Closed]]
}, Closed]],
Cell[CellGroupData[{
Cell[299, 26, 0, 63, "Section"],
Cell[301, 375, 6, 69, "Text"],
Cell[309, 320, 5, 69, "Text"]
}, Closed]]
(* End of internal cache information *)

我要回帖

更多关于 海澜之家 hovd 的文章

 

随机推荐