Graphics, Figures & Tables\includegraphics makes image unsharp

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Rc3g
Posts: 6
Joined: Mon Dec 01, 2008 6:34 pm

\includegraphics makes image unsharp

Post by Rc3g »

Hi. I'm trying to include a png image in my LaTeX document but for some reason it shows up blurred, like it's been slightly upscaled. Surely the standard behavior of \includegraphics is to use the image's natural size? I don't really understand what's going on here. There are no errors when compiling the document (using pdflatex). I've obviously checked that there's nothing wrong with the image itself ;)

This is the exact code I'm using:

Code: Select all

\begin{figure}[h]
\includegraphics{ferrers.png}
\caption{Examples of Ferrers diagrams. Note that $\mu/\lambda$ is not a border strip.}
\label{fig:ferrers}
\end{figure}
I've even tried specifying the exact width and height of the image (\includegraphics[width=330px,height=90px]{ferrers.png}), but it just makes it worse!
Attachments
f.PNG
f.PNG (26.64 KiB) Viewed 22669 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

\includegraphics makes image unsharp

Post by localghost »

Try a certain scaling factor.

Code: Select all

\includegraphics[scale=0.75]{ferrers.png}
Th reason is the relation between the two units pixel and postscript point.


Best regards and welcome to the board
Thorsten¹
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Rc3g
Posts: 6
Joined: Mon Dec 01, 2008 6:34 pm

Re: \includegraphics makes image unsharp

Post by Rc3g »

Thanks for your reply. I suppose that will work.

I've tried converting the image to a pdf, and then including the pdf. This makes everything nice and sharp, but once I start cropping (obviously I can't have a single page with just that figure on it), I get the same result as when I included the png. I don't suppose there is anything to do about this either (except scaling)?
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

\includegraphics makes image unsharp

Post by localghost »

Rc3g wrote:[...] I've tried converting the image to a pdf, and then including the pdf. This makes everything nice and sharp, but once I start cropping (obviously I can't have a single page with just that figure on it), I get the same result as when I included the png. I don't suppose there is anything to do about this either (except scaling)?
Converting a pixel based format (PNG) to a vector based format (PDF) makes no sense because you can't benefit from advantages of the vector format. The best quality would be achieved by drawing these diagrams by hand with pgf/tikZ. But there will be a learning curve until you get familiar with that.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
Rc3g
Posts: 6
Joined: Mon Dec 01, 2008 6:34 pm

Re: \includegraphics makes image unsharp

Post by Rc3g »

I see. Thanks.
Rc3g
Posts: 6
Joined: Mon Dec 01, 2008 6:34 pm

Re: \includegraphics makes image unsharp

Post by Rc3g »

My figure could be drawn very easily (and with acceptable quality) with MetaPost.
User avatar
localghost
Site Moderator
Posts: 9201
Joined: Fri Feb 02, 2007 12:06 pm

\includegraphics makes image unsharp

Post by localghost »

Rc3g wrote:My figure could be drawn very easily (and with acceptable quality) with MetaPost.
I did two examples with pgf/tikZ. The first one with subfigures ...

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{font=small,labelfont=sc]{caption}
\usepackage[font=footnotesize][subcaption}
\usepackage{nicefrac}
\usepackage{tikz}

\begin{document}
  \begin{figure}[!ht]
    \centering
    \begin{subfigure}{0.2\linewidth}
      \centering
      \begin{tikzpicture}[thick]
%        \draw[style=help lines] (0,0) grid (3,2);
        \foreach \position in {(0,0),(0,0.6),(0,1.2),(0.6,0.6),(0.6,1.2),(1.2,1.2),(1.8,1.2)}
        \draw \position rectangle +(0.5,0.5);
      \end{tikzpicture}
      \caption{$\mu=(421)$}\label{subfig-1:ferrers}
    \end{subfigure}
    \begin{subfigure}{0.2\linewidth}
      \centering
      \begin{tikzpicture}[thick]
%        \draw[style=help lines] (0,0) grid (3,2);
        \foreach \position in {(0,0.6),(0,1.2),(0.6,0.6),(0.6,1.2)}
        \draw \position rectangle +(0.5,0.5);
        \foreach \position in {(0,0),(1.2,1.2),(1.8,1.2)}
        \path \position rectangle +(0.5,0.5);
      \end{tikzpicture}
      \caption{$\lambda=(22)$}\label{subfig-2:ferrers}
    \end{subfigure}
    \begin{subfigure}{0.2\linewidth}
      \centering
      \begin{tikzpicture}[thick]
%        \draw[style=help lines] (0,0) grid (3,2);
        \foreach \position in {(0,0),(1.2,1.2),(1.8,1.2)}
        \draw \position rectangle +(0.5,0.5);
        \foreach \position in {(0,0.6),(0,1.2),(0.6,0.6),(0.6,1.2)}
        \path \position rectangle +(0.5,0.5);
      \end{tikzpicture}
      \caption{$\nicefrac{\mu}{\lambda}$}\label{subfig-3:ferrers}
    \end{subfigure}
    \caption[Examples of \textsc{Ferrers} diagrams]{Examples of \textsc{Ferrers} diagrams. Note that $\nicefrac{\mu}{\lambda}$ is not a border strip.}\label{fig:ferrers}
\end{figure}
\end{document}
... and the other one as single figure to make it look more like your screenshot.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage[english]{babel}
\usepackage{font=small,labelfont=sc]{caption}
\usepackage{nicefrac}
\usepackage{tikz}

\begin{document}
  \begin{figure}[!ht]
    \centering
    \begin{tikzpicture}[thick]
%      \draw[style=help lines] (0,0) grid (9,3);
      \foreach \position in {(0,0),(0,0.6),(0,1.2),(0.6,0.6),(0.6,1.2),(1.2,1.2),(1.8,1.2)}
        \draw \position rectangle +(0.5,0.5);
      \draw (1.5,2) node[above] {\small $\mu=(421)$};
      \begin{scope}[xshift=3cm]
        \foreach \position in {(0,0.6),(0,1.2),(0.6,0.6),(0.6,1.2)}
        \draw \position rectangle +(0.5,0.5);
        \draw (1.5,2) node[above] {\small $\lambda=(22)$};
      \end{scope}
      \begin{scope}[xshift=6cm]
        \foreach \position in {(0,0),(1.2,1.2),(1.8,1.2)}
          \draw \position rectangle +(0.5,0.5);
        \draw (1.5,2) node[above] {\small $\nicefrac{\mu}{\lambda}$};
      \end{scope}
    \end{tikzpicture}
    \caption[Examples of \textsc{Ferrers} diagrams]{Examples of \textsc{Ferrers} diagrams. Note that $\nicefrac{\mu}{\lambda}$ is not a border strip.}\label{fig:ferrers}
  \end{figure}
\end{document}
Nevertheless I'm also interested in a solution with MetaPost.
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes[/size]

¹ System: openSUSE 42.2 (Linux 4.4.52), TeX Live 2016 (vanilla), TeXworks 0.6.1
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

\includegraphics makes image unsharp

Post by phi »

Here is an example using Asymptote, which can be used to draw arbitrary diagrams of this kind. Compile with your platform equivalent of (pdf)latex AAA && asy AAA && (pdf)latex AAA:

Code: Select all

\documentclass{article}
\usepackage{asymptote}

\begin{document}

\begin{figure}
\centering
\begin{asy}
unitsize(6mm);
struct Ferrer {
	static path Box = box((0, 0), (0.8, -0.8));
	static int offset = 0;
	bool[][] values;
	bool get(int i, int j) {
		return values.initialized(i) && values[i].initialized(j) && values[i][j];
	}
	void set(int i, int j) {
		if(!values.initialized(i)) values[i] = new bool[];
		values[i][j] = true;
	}
	void operator init(...int[] r) {
		for(int i = 0; i < r.length; ++i) {
			for(int j = 0; j < r[i]; ++j) set(i,j);
		}
	}
	void Draw(string L) {
		int n = 0;
		for(int i = 0; i < values.length; ++i) {
			n = max(n, values[i].length);
			for(int j = 0; j < values[i].length; ++j) {
				currentpen = get(i,j) ? defaultpen : nullpen;
				draw(shift(offset+j, -i) * Box);
			}
		}
		label(L, (offset+n/2, 0), N, defaultpen);
		offset += n+2;
	}
}
Ferrer operator/(Ferrer L, Ferrer R) {
	Ferrer result;
	for(int i = 0; i < L.values.length; ++i) {
		for(int j = 0; j < L.values[i].length; ++j) {
			if(L.get(i,j) && !R.get(i,j)) result.set(i,j);
		}
	}
	return result;
}
Ferrer mu = Ferrer(4, 2, 1);
Ferrer lambda = Ferrer(2, 2);
mu.Draw("$\mu = (421)$");
lambda.Draw("$\lambda = (22)$");
(mu/lambda).Draw("$\mu/\lambda$");
\end{asy}
\caption{Examples of \textsc{Ferrers} diagrams. Note that $\mu/\lambda$ is not a border strip.}
\end{figure}

\end{document}
Post Reply