# My pixel perfect picture gets blurry when compiled in LaTeX

I have this picture: http://dl.dropbox.com/u/3394117/Temp/fig1.png (I have the original in Pixen and could export it to several different formats. I went with PNG though since it's lossless.)

When I open my picture in Preview (OS X) and zoom in, it looks fine. The characters have extremely sharp boarders between them and the background. However, when I put it into my LaTeX document, compile it to a PDF (using TeXShop) and then zoom in, it suddenly have gotten blurry (see screenshot: http://dl.dropbox.com/u/3394117/Temp/Screen%20shot%202011-02-13%20at%2012.46.30.png).

Minimal working example:

\documentclass[12pt]{article}
\usepackage{graphicx}
\begin{document}
\includegraphics[scale=1]{fig1.png}
\end{document}


In the end, I would like to be able to scale the picture freely without there being any blurring at all.

-

## migrated from stackoverflow.comFeb 13 '11 at 13:12

This question came from our site for professional and enthusiast programmers.

– Stefan Kottwitz Feb 13 '11 at 13:18
Dan: The screenshot works now. Thank you for pointing that out. – Speldosa Feb 13 '11 at 15:43
Stefan: Thank you for those links. I will check them out. – Speldosa Feb 13 '11 at 15:44

This is just an effect of the display settings of your PDF viewer. In Acrobat Reader 9, for example, there is an option "Edit | Preferences | Page Display | Smooth images". If you uncheck this box, the picture will not be anti-aliased. When printing, your image should look fine regardless of the smoothing effect you see on screen.

Here's your file in Acrobat Reader 9, zoomed to 800%, left half with the default "Smooth images", right half with the option unchecked. Note the tick mark and the red X:

-
OMG! :) Well that exaplains a lot. Still I'm using PDF to actually be able to control how everybody else sees my content. Nice to know that the print wouldn't be affected anyway. – Speldosa Feb 13 '11 at 15:41
I was now asking on comp.text.tex about a pdftex or PDF setting which can be used in the document to tell the PDF viewer not to use anti-aliasing. – Martin Scharrer May 17 '11 at 21:59
I don't see any difference between the left and right half of this picture. – Sverre Oct 26 '15 at 8:57
@Sverre: If you look at the green tick mark on the top, you should be able to see that the left half is a bit blurry, while the pixels on the right half have sharp corners. Make sure you're looking at the full resolution, unscaled image (it'll look different on a smartphone, for example) – Jake Oct 26 '15 at 11:24
@Jake Gotcha, I see it now. I just didn't expect the difference to be that small. – Sverre Oct 26 '15 at 11:50

Here is a comparison on my system of the PDF output side by side with your original PNG. The PDF is on the left and the PNG on the right. I can see some slight differences, but I would not describe the PDF as blurrier.

PNG may be lossless, but it's still a bitmap format, and hence will look bad when zoomed in on, especially for a very small image like yours. Does Pixen have the option for exporting to a vector format, like EPS or PDF (or SVG, which you could then convert using other tools)? That would be better than PNG.

-
+1 for vector formats. If you're feeling hardcore, redraw the whole thing in TikZ... – Seamus Feb 13 '11 at 13:45
Yes, it can export to for example ESP. However, when I do that, I get the same result. I have to admit that I don't really understand how different images are handled. For example, if I import the picture to Pages (iWork) and make it bigger, before I release the mouse it looks exactly like I want it (no blurryness at all, sharp boarders et cetera) but when I release the button, it gets blurry as if Pages wanted to "help" me somehow. Guess the same thing is happening in LaTex...or? Anyway. I solved it in an ugly way (see solution suggestion from myself). – Speldosa Feb 13 '11 at 13:55
@Speldosa: That behaviour in Pages is the "display smoothing" again: Pages assumes that you don't want to see the hard edges of your pixels and tries to make it look pretty by smoothing over it, which would be fine for photos, but not for pixel art. The underlying picture is fine, it really is just a display option of the picture viewer (or the PDF viewer if the image is included in a LaTeX document). – Jake Feb 13 '11 at 13:59
@Jake: Oh, I see. Then I guess it is preferable to do something along the lines with what I did (make the picture bigger) to get it to be shown properly for most people. – Speldosa Feb 13 '11 at 14:01
@Speldosa, I'd guess that Pixen is just putting a bitmap graphic in an EPS wrapper. Try importing into an actual vector graphics editor that has vectorize/trace capabilities like Inkscape -- I do think it's the viewer making the difference, but I still think vectorizing it would help. – frabjous Feb 13 '11 at 14:03

Ok. I got it to work now. It was ugly but it works.

What I did was the following. I zoomed in on the picture in Pixen so that it covered my entire screen. I then took a screenshot, imported it into Pixelmator and exported it as a png-file.

Now it looks great! It's not until you zoom in really, really far that you notice the blurring.

It would be neat to be able to zoom without getting any blurring at all. Maybe I should do vector pixel art next time (I'll see if InkScape can fulfill my needs).

-
Isn’t Jake’s answer more apt? I.e. disable the smoothing setting in your PDF viewer? – Konrad Rudolph Feb 13 '11 at 14:23
@Konrad: Well, if you send the pdf file to someone else, they might be rather annoyed if they're told to change viewer settings for best onscreen viewing. – Hendrik Vogt Feb 13 '11 at 14:34
@Speldosa Well the viewer screwed up your original picture, didn’t it? The current behaviour of the viewer is highly inconsistent: it smoothes the pixel values of the source image instead of the pixel values of the displayed (on-screen) pixel image. It would be much more consistent if Adobe would smoothe the displayed pixels and if this is ever implemented, your workaround won’t work any more. By the way, I’m not necessarily saying that you shouldn’t use your workaround, I’m just warning that it may not always work. – Konrad Rudolph Feb 13 '11 at 15:47
I have to strongly agree with @Konrad that Jake's answer should be accepted. It is the general solution/workaround of this issue. You should note that similar questions appeared and where marked as duplicates of this one. Jake's answer will help these people and others which have the same issue much more than your answer. – Martin Scharrer May 17 '11 at 21:50
I still don't see why my solution wouldn't always work. What I've done is to effectively heightened the resolution of my picture so that it, when it is presented as a smaller image, will be able to show the picture without blurring. If I however send my PDF to someone else and this person don't know how to goof around with the PDF reader, then I'm pretty much screwed. – Speldosa Aug 3 '11 at 15:13

One option for forcing a pixel-perfect image in pdf viewers with unreliable interpolation settings is simply to scale the image up by a few multiples without interpolation, so that each pixel simply becomes several pixels on the new image. Then in latex, set the image scale to the inverse of the multiplier.

So, in the example below, I took the original, pixel-perfect image and scaled it up by 4x so that the result was 4 pixels per pixel in the original image. I then set the include scale to 0.25:

\includegraphics[scale=0.25]{wulfenbach.png}


This isn't perfect, but it is an improvement.

The reason this works is because the pdfviewer still does image interpolation as usual, but it does it over a larger image. So most of the "pixels" are now several real pixels wide, and mainly get blurred with themselves, so the apparent amount of antialiasing is smaller.

-

A similar problem is being discussed in this thread.

I have found a solution on Inkscape forums. Open the PDF file in a text editor, and locate the following line:

/Interpolate true

Change it to the following:

/Interpolate false

This should stop the blurring.

-
This does not work with all PDF viewers, for example the PDF engine on OS X uses still interpolation, in print however it seems to be interpreted correctly. It probably has the same effect as adding the interpolate=false option to the includegraphics command (can you confirm that?). – mcb Nov 19 '14 at 0:45