# How can text-specific antialiasing be disabled in Rasterize?

While tinkering with the code in the Falling Matrix question, I was hoping to improve the rendering speed by making the rasterizations of the text grayscale. I changed the base color of the text to white and left the background black. However, this did not yield a grayscale raster. The problem seems to be that Mathematica tries to help with the readability of text by using special antialiasing schemes.

Consider the following test:

GraphicsRow[
Rasterize[#, Background -> Black, RasterSize -> 15,
ImageSize -> 150] & /@ {Style["\[FilledCircle]", White],
Graphics[{White, Disk[]}]}]


Interesting and (I think) undocumented, but the relevant question for me is: How can I control or eliminate this behavior? Adding a ColorConvert[#,"Grayscale"] or just taking the Norms of the ImageData gives an acceptable result but is pretty slow.

• I can confirm on mma 9.0.0 & 8.0.4 on win7 – Ajasja Mar 4 '13 at 18:45

One possible way would be to extract the text outline as in this answer (scroll to the end) and rasterize the resulting graphics. First, define a convenient function:

textGraphics[t_String | t_Style] := Graphics@First@First@
ImportString[ExportString[t, "PDF"], "PDF", "TextMode" -> "Outlines"];


We can see this in action:

textGraphics /@ {Style["A", FontSize -> 12, FontColor -> Red, FontFamily -> "Times"], "B"} // Row


If you now try your example above and apply this function on the styled text, you should get this:

• There seems to be a bit of a problem when using this for characters that do not fill much of the monospace-character box. You could use an explicit PlotRange to restore it, but is there some a priori way to know what the correct bounding box will be? – Xerxes Mar 4 '13 at 21:58
• @Xerxes Perhaps something like this: mathematica.stackexchange.com/a/4162/5 – rm -rf Mar 4 '13 at 22:01

First of all, the most practical solution is probably @rm's.

Mathematica simply uses your operating system's font renderer. If you disable subpixel antialiasing at the operating system level, it will be disabled in Mathematica too. It is possible to do this on all of Windows, OS X and Linux, but the procedures are different. However, you may not want to do this permanently as it's going to reduce the readability of text in every program.

This is closely related to my own question: Poor anti-aliasing in Rotated text with ClearType on.

EDIT: This apparently only works in Windows systems.

The same solution, Opacity of anything other than one, can be applied:

GraphicsRow[
Rasterize[#, Background -> Black, RasterSize -> 15, ImageSize -> 150] & /@ {Style[
"\[FilledCircle]", White, Opacity[0.9999]], Graphics[{White, Disk[]}]}]


Opacity[2] also works on my system.

• This does not seem to work for me (v9 Linux) using Opacity[2], Opacity[0.999] or FontOpacity->0.999. – Xerxes Mar 4 '13 at 21:24
• @Xerxes I'm sorry to hear that. It does work on Windows. I hope you find a solution; if you do please post an answer for my question too. – Mr.Wizard Mar 4 '13 at 21:26
• It doesn't work on OS X v9 either. Just include a note that this is a solution for Windows :) (and +1) – Szabolcs Mar 4 '13 at 21:31
• @Xerxes Out of curiosity what happens if you Rotate the text by 45° before rasterizing? – Mr.Wizard Mar 4 '13 at 22:13
• @Szabolcs Same question to you, please. – Mr.Wizard Mar 4 '13 at 22:13