(************** Content-type: application/mathematica **************
CreatedBy='Mathematica 5.2'
Mathematica-Compatible Notebook
This notebook can be used with any Mathematica-compatible
application, such as Mathematica, MathReader or Publicon. The data
for the notebook starts with the line containing stars above.
To get the notebook into a Mathematica-compatible application, do
one of the following:
* Save the data starting with the line of stars above into a file
with a name ending in .nb, then open the file inside the
application;
* Copy the data starting with the line of stars above to the
clipboard, then use the Paste menu command inside the application.
Data for notebooks contains only printable 7-bit ASCII and can be
sent directly in email or through ftp in text mode. Newlines can be
CR, LF or CRLF (Unix, Macintosh or MS-DOS style).
NOTE: If you modify the data for this notebook not in a Mathematica-
compatible application, you must delete the line below containing
the word CacheID, otherwise Mathematica-compatible applications may
try to use invalid cache data.
For more information on notebooks and Mathematica-compatible
applications, contact Wolfram Research:
web: http://www.wolfram.com
email: info@wolfram.com
phone: +1-217-398-0700 (U.S.)
Notebook reader applications are available free of charge from
Wolfram Research.
*******************************************************************)
(*CacheID: 232*)
(*NotebookFileLineBreakTest
NotebookFileLineBreakTest*)
(*NotebookOptionsPosition[ 7548, 185]*)
(*NotebookOutlinePosition[ 8215, 208]*)
(* CellTagsIndexPosition[ 8171, 204]*)
(*WindowFrame->Normal*)
Notebook[{
Cell[CellGroupData[{
Cell["Antialiased Graphics", "Subtitle"],
Cell["\<\
A rasterized image may contain bit-mapped representations of lines and smooth \
surfaces. Because this is displayed as a bitmap, there is no notion of a \
line or surface as there is in a vectorized language. Bitmaps represent the \
image as an array of discrete pixels. This discrete nature can make lines \
and surface edges appear jagged. To overcome this limitation, bit-mapped \
images can be antialiased if the bitmap was created from vectorized sources. \
One method of antialiasing involves enlarging the original vectorized source \
graphic by some integer factor and then rasterizing the enlarged image. A \
set of pixels in the enlarged image are replaced by the average value. If \
the enlarged raster was enlarged 4 times in each direction, then the pixels \
are averaged over every sixteen pixels. The resulting image is 1/4 the \
enlarged size which is the size of the original image before enlargement. \
However, because of the averaging process, the elements now look smoother. \
This process is antialiasing.\
\>", "Text"],
Cell["\<\
The following code creates an antialised version of a given graphic.\
\>", "Text"],
Cell[CellGroupData[{
Cell["Anti-Aliasing Code", "Section"],
Cell["\<\
The following code uses a 4x4 smoothing kernel and ListConvolve. \
Essentially, the graphic object is exported 4x its normal size and is then \
re-imported. ListConvolve is then used on this larger bitmap to obtain a \
smoothed version of the original graphic in rasterized format.\
\>", "Text"],
Cell[BoxData[
\(aa[gr_] :=
Module[{siz, kersiz, ker, dat, as, ave, is,
ar}, \[IndentingNewLine]is =
ImageSize /. Options[gr, ImageSize]; \[IndentingNewLine]ar =
AspectRatio /.
Options[gr, AspectRatio]; \[IndentingNewLine]If[\(! NumberQ[
is]\), is = 288]; \[IndentingNewLine]kersiz =
4; \[IndentingNewLine]img =
ImportString[
ExportString[gr, "\",
ImageSize \[Rule] \((is\ kersiz)\)], "\"]; \
\[IndentingNewLine]siz =
Reverse@\(Dimensions[
img[\([1, 1]\)]]\)[\([{1, 2}]\)]; \[IndentingNewLine]ker =
Table[N[1/kersiz\^2], {kersiz}, {kersiz}]; \[IndentingNewLine]dat =
N[img[\([1, 1]\)]]; \[IndentingNewLine]as =
Dimensions[dat]; \[IndentingNewLine]ave =
Partition[
Transpose[\(Flatten[
ListConvolve[ker, dat[\([All, All, #]\)]]] &\) /@
Range[as[\([3]\)]]],
as[\([2]\)] - kersiz + 1]; \[IndentingNewLine]ave =
Take[ave,
Sequence @@ \((\({1, \(Dimensions[ave]\)[\([#]\)], kersiz} &\) /@
Range[Length[Dimensions[ave]] -
1])\)]; \[IndentingNewLine]Show[
Graphics[
Raster[ave, {{0, 0}, siz/kersiz}, {0, 255},
ColorFunction \[Rule] RGBColor]],
PlotRange \[Rule] {{0, siz[\([1]\)]/kersiz}, {0,
siz[\([2]\)]/kersiz}}, ImageSize \[Rule] is,
AspectRatio \[Rule] ar]\[IndentingNewLine]]\)], "Input"]
}, Open ]],
Cell[CellGroupData[{
Cell["Applying the Algorithm", "Section"],
Cell["\<\
Here is a ParemetricPlot3D that results in a typical rendered graphic. Close \
examination of the bounding box and the mesh on the surface reveals many \
jagged lines. We will attempt to smooth these features using this \
antialiasing technique.\
\>", "Text"],
Cell[BoxData[
\(original =
ParametricPlot3D[{\(2\ \((Cos[u] + u\ Sin[u])\)\ Sin[v]\)\/\(1 + u\ u\ \
Sin[v]\ Sin[v]\), \(2\ \((Sin[u] - u\ Cos[u])\)\ Sin[v]\)\/\(1 + u\ u\ Sin[v]\
\ Sin[v]\),
Log[Tan[v\/2]] + \(2\ Cos[v]\)\/\(1 + u\ u\ Sin[v]\ Sin[v]\)}, {u, \
\(-4\), 4}, {v, 0.05, \[Pi]}, PlotPoints \[Rule] 50,
ImageSize \[Rule] 600]\)], "Input"],
Cell["\<\
Since some aspects of the above graphic do not scale with image size, we must \
take extra steps to make sure they are handled correctly. The features \
requiring extra care are the narrow features such as lines and fonts. \
Without special care, narrow black lines will appear grey in the resulting \
image since they are averaged against the white background. To overcome \
this, we will increase the line widths by 4 times and also enlarge font sizes \
by 4 times. \
\>", "Text"],
Cell[BoxData[
\(\(gr =
ParametricPlot3D[{\(2\ \((Cos[u] + u\ Sin[u])\)\ Sin[v]\)\/\(1 + u\ u\
\ Sin[v]\ Sin[v]\), \(2\ \((Sin[u] - u\ Cos[u])\)\ Sin[v]\)\/\(1 + u\ u\ \
Sin[v]\ Sin[v]\),
Log[Tan[v\/2]] + \(2\ Cos[v]\)\/\(1 + u\ u\ Sin[v]\ Sin[v]\), \
{EdgeForm[AbsoluteThickness[4]]}}, {u, \(-4\), 4}, {v, 0.05, \[Pi]},
PlotPoints \[Rule] 50, ImageSize \[Rule] 600,
TextStyle \[Rule] {FontSize \[Rule] 40},
BoxStyle \[Rule] {AbsoluteThickness[4]},
DisplayFunction \[Rule] Identity];\)\)], "Input"],
Cell["\<\
Now, we are ready to antialias the graphic. Be patient as this might take a \
couple of minutes. The larger the original image size, the longer the \
algorithm will take.\
\>", "Text"],
Cell[BoxData[
\(finalgraphic = aa[gr]\)], "Input"],
Cell["\<\
The resulting image is much improved although does have some side-effects and \
shows some of the difficulties with implementing a robust antialiasing \
algorithm. Notice that the tick labels are lighter in color than the \
original. Fonts can be especially tricky to antialias correctly since the \
glyphs often have narrow strokes and therefore take on a lightened appearance \
when averaged against a lighter background color. However, the positive \
results often exceed the negatives.\
\>", "Text"]
}, Open ]]
}, Open ]]
},
FrontEndVersion->"5.2 for Microsoft Windows",
ScreenRectangle->{{0, 1280}, {0, 941}},
WindowSize->{1013, 740},
WindowMargins->{{36, Automatic}, {Automatic, 73}},
ShowSelection->True
]
(*******************************************************************
Cached data follows. If you edit this Notebook file directly, not
using Mathematica, you must remove the line containing CacheID at
the top of the file. The cache data will then be recreated when
you save this file from within Mathematica.
*******************************************************************)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[CellGroupData[{
Cell[1776, 53, 40, 0, 51, "Subtitle"],
Cell[1819, 55, 1061, 15, 128, "Text"],
Cell[2883, 72, 92, 2, 33, "Text"],
Cell[CellGroupData[{
Cell[3000, 78, 37, 0, 73, "Section"],
Cell[3040, 80, 307, 5, 52, "Text"],
Cell[3350, 87, 1593, 32, 313, "Input"]
}, Open ]],
Cell[CellGroupData[{
Cell[4980, 124, 41, 0, 73, "Section"],
Cell[5024, 126, 271, 5, 52, "Text"],
Cell[5298, 133, 379, 7, 66, "Input"],
Cell[5680, 142, 495, 8, 71, "Text"],
Cell[6178, 152, 567, 10, 87, "Input"],
Cell[6748, 164, 196, 4, 33, "Text"],
Cell[6947, 170, 54, 1, 30, "Input"],
Cell[7004, 173, 516, 8, 71, "Text"]
}, Open ]]
}, Open ]]
}
]
*)
(*******************************************************************
End of Mathematica Notebook file.
*******************************************************************)