0

I want to plot a PNG image in PGFplots. While this basically works with the graphics keyword, my problem is that Apples Preview PDF viewer applies kind of anti-aliasing to the image. But in my case it is important to see the pixelwise elements (128x128 pixel) (see figures). I thought that the solution could be to plot not the PNG image directly but plotting it from the image data. Thus the image is not recognized as an image by Preview and thus is not anti-aliased.

Is there a way to plot an image directly from a 128x128x3 data array? Other solutions for my problem not using PGFplots are also okay.

\begin{tikzpicture}
    \begin{axis}[
    axis on top,
    width=5cm,
    height=5cm,
    scale only axis,
    enlargelimits=false,
    axis equal=true,
    tick align=outside,
    tick pos=left,
    tick style={black},
    xmin=0,
    xmax=128,
    ymin=0,
    ymax=128,
    xtick={0, 64, 128},
    ytick={0, 64, 128},
    ]
         \addplot graphics[xmin=0,ymin=0,xmax=128,ymax=128] {fig/scaled.png};
    \end{groupplot}
\end{tikzpicture}

enter image description here

Yannic
  • 205
  • If I am not mistaken then pdftex/pdflatex offers an option that controls this behavior. I tried to google it but no luck so far. – Dr. Manuel Kuehner Mar 15 '21 at 22:16
  • 1
    Maybe related: https://tex.stackexchange.com/questions/10975 – Dr. Manuel Kuehner Mar 15 '21 at 22:16
  • Maybe related: https://latex.org/forum/viewtopic.php?t=11608. There is a text code like `\documentclass[a4paper,12pt]{article} \usepackage{graphicx} \begin{document}

    \pdfliteral direct {/Interpolate true} \special {pdf:direct: /Interpolate true } \includegraphics[width=0.5\linewidth]{mytest.png} \pdfliteral{/Interpolate true}

    \end{document}`

    – Dr. Manuel Kuehner Mar 15 '21 at 22:18
  • This solution works perfectly and is so easy: Just upscale the small image from 128x128 pixels to 1024x1024 pixels with no interpolation (such that each pixel is repeated four times in each direction). The resulting image size is also only slightly higher (about 10kb). Thanks! – Yannic Mar 15 '21 at 22:28
  • Glad to hear that. Should we close the question? – Dr. Manuel Kuehner Mar 15 '21 at 22:34
  • 1
    Yes question can be closed. I already flagged it as duplicate. – Yannic Mar 15 '21 at 22:47

0 Answers0