Quality for images in LaTeX documents - image

What are some of the points that I need to follow if I want to have good quality images in a LaTeX document. These images are mostly screenshots of a software application or flow charts.
Below are two such images.
Flow Chart
Screenshot
Thanx

For diagrams, the rule is to use vector formats as much as you can — PDF, EPS or native LaTeX packages. When using vector graphics, the picture does not loose resolution and can be scaled freely. For a flow chart, I would either export it from the drawing application as a PDF, or use PGF/Tikz to produce it from LaTeX (see also examples). If your drawing application does not have a PDF export, consider using one that does — e.g., UMLet.
If you can't use vector graphics (e.g., because it is a screenshot), make sure you use high-enough resolution to begin with. If it is an academic paper, the publisher usually has guidelines for this.

If you use PDFLatex you can use png images and in those cases you definately should use png over jpeg. PNG compression is not lossy, so you get the best quality at the expense of file size.
The second important point is to create the images with sufficient resolution, for printing it should be about 300-600 dpi, higher is better but the filesize of the images and the resulting document will increase. For documents that will only be looked at a screen you can use a lower resolution, about 72-100 dpi should be enough.
For diagrams you should create vector graphics (eps or pdf) if possible, that way you do not lose any quality.

For screenshots, there is not much to do, but for flow charts, I'd suggest to create them in PDF format (vectorized) and to compile your LaTeX source with pdflatex.

for the flowchart i'd suggest TikZ, then your chart is directly typeset in TeX. Here's an example: http://www.texample.net/tikz/examples/simple-flow-chart/

Screenshots are pretty much a lost cause. I've had a good experience saving them as PDF and then embedding them, but you want to make sure you're on a high-res capture to begin with.
Charts are very easy. Most graphics programs (e.g., Vizio, OmniGraffle) will let you save it as EPS or PDF, and scaling works fairly well.

Related

Microsoft Word -> PDF image quality

Our line of business application uses a Word document as a template, fills in the pertinent information and converts it to PDF, which it returns to the user.
That all works fine except for one thing. We use an image of our company's logo on the lead page and in the footer. In one resolution (e.g. 100%), it looks fine. But at higher resolutions (e.g. 250%), it has several noticeable jaggies; the diagonals have noticeable ragged edges. Tweaking the image, we're able to make it look good at the higher zoom value, but then it looks terrible at lower zoom values.
Currently, we're using a PNG, but we've tried JPG and it doesn't improve the jaggy problem. In fact, it looks worse at higher resolution because of JPG compression. I think a vector image would solve the problem (and we have the logo in vector format), but I haven't found any vector formats that Word supports.
I don't really have any code to show, since we don't do anything with the image in the code: we just take the document and plug in our values, none of which touch the logo (the template already contains the image).
We are using Word 2013 (32-bit) on Windows 8.1 (though some of our developers use Windows 7). We use the .NET PdfDocument class to generate the PDF.
Any ideas on how to get Word to be better at retaining image quality? Or is this a PDF issue?
The suggestion by David van Driessche might still work, provided the right EMF is used. EMF files can contain both raster and vector data. With a raster EMF file, the same problem will present itself as it did with PNG or JPEG. Vector EMF embedded in Word files can scale very nicely, at least when zoomed in display, so it could also work with printing or converting to PDF.
Word supports both raster and vector objects within EMFs, so the secret is to use EMFs that only contain scalable objects like lines, curves and text when quality & scaling are both concerns.
I have posted sample files here to illustrate this for anyone wishing to see the difference.
Amin Dodin

Using PDF files as images

In the past i have used PDF images of vector files in an NSImage, the advantage being that i can scale them without losing quality. I know that people usually use jpg and png files, why is this? Do PDF files significantly reduce performance or is there some other reason?
Thank you in advance,
Ben
It depends on what's in your PDF file. If there's enough going on in it, then yeah, a raster image may be faster. The trade-off is, of course, scalability—you end up needing to create 1x and 2x variants for every destination size, or create an icon family (if appropriate), instead of just using one image for everything.
But I think most people create raster resources because that's the sort of tool they're used to: Photoshop, Pixelmator, or Acorn. Not many people use vector editors or write their art in PostScript. (And the field of vector editors available on the Mac is pretty weak.)
My recommendation for a few years now has been an app called Opacity. It's vector-focused, but can export raster images in multiple sizes, PDFs, and even source code.
I use PDF files too, for precisely the same reason that they scale automatically. Apple do the same (look inside the Xcode.app bundle - you won't find much other than .pdf files).
There is no reason to use .jpg or .png files at all.

How to save images for web-pages? (format/size)

What is the best way to store images for web-sites?
What size I should not exceed?
Now, I save all interface-files in png (mostly in sprites) and usual images in jpg's. Some images are about 100-150Kb.
What quality and compression should I choose while saving images?
Preparing Images
To prepare images for presentation on
the Web, follow these steps:
Begin a new file. If it’s a photo or original artwork, use 300 dpi as
the resolution. If you are creating
something simple, set the resolution
to 72 dpi.
Use the drawing, text, shape and other tools provided in the graphics
program to create your image.
Save your file in the native file format (a file type meant for editing
that is specific to the image editing
program) of the program you are using.
For example, a Photoshop document
creates files with a ".psd" extension.
If you need to make a change or edit
later, do it in this file rather than
on the Web.
If necessary, lower the resolution of the image to 72 dpi.
If necessary, resize the image to the height and width in pixels
specifications desired.
Save the file in a Web-ready file format, usually a GIF (most programs
give you several choices for file
types), finding a balance between the
way the file looks and an appropriate
file size. Some image programs will
let you preview the final file output,
whie in others, you have to save it
and load it in the browser to see the
final effect.
Preparing Photographs
To prepare photographs for
presentation on the web, follow these
steps:
Download the photo from your digital
camera or scan in the photograph. The
process for this varies depending on
the software bundled with your scanner
or camera. The image will probably end
up in "Your Photos" on Windows, or the
"Photos" folder on a Mac, unless you
chose some other folder as the default
destination.
Use the color correction, drawing, text, shape, and other tools provided
in the graphics program to alter and
improve your image.
Save a copy of your file in the native file format of the program you
are using. Make later changes or edits
in this file rather than on the web.
With photographs, save an untouched
version of the photo in case you want
to use it again for another purpose.
If necessary, lower the resolution of the image to 72dpi.
If necessary, resize the image to the height and width in pixels
specifications desired.
Save the file in a web-ready format, usually a JPEG, finding a
balance between the way the file looks
and an appropriate file size.
Making images web-ready is all about
compromise. In general, the better
your image looks, the larger the file
size will be. The larger the file
size, the longer it will take to
download. Your job is to find a
compromise between quality and file
size. Some things to consider are:
Is this image conveying crucial information? If so, go for higher
quality.
Is the image on a page with a lot of other images? If so, make the file
size smaller.
Will your web visitor be able to detect that the quality of a photo or
image isn’t very good?
Make images of people fairly high quality because visual acuity is
strongest with people’s faces.
(Source)
For your images, here is a tip:
Do not scale images in HTML
Web page designers sometimes set image
dimensions by using the width and
height attributes of the HTML image
element. Avoid doing this since it can
result in images being larger than
needed. For example, if your page
requires image myimg.jpg which has
dimensions 240x720 but displays it
with dimensions 120x360 using the
width and height attributes, then the
browser will download an image that is
larger than necessary.
(Source, see another tip)
This all depends on what the image is for. If you're generally adhering to a web-safe palette, gifs will come out smaller and clearer than a jpeg. Jpeg's are for photos. For jpegs to handle websafe colors well, you need to save at 88%+ quality, which increases file size. Png's generally have the best quality, and in some cases (when you don't need transparency) can come out smaller than jpgs, and comparable to gif. So, for jpeg photos, 80 quality, (sometimes even 75 for smaller images) will get you decent results and small filesize. Use gifs / png for site imagery generally. As far as images on a page, I try not to exceed 30kb total, assuming the page isn't something that is focused on photos / imagery. Hope this helps.
It depends on what your image is of, and what the quality needs to be, whether you choose quality over page loading etc.
I personally save all mine in .png but IE has a problem rendering the colour correctly in .png so if you are using them for aestetical purposes I would save .jpg
As to the size of the image, like said it depends really on the quality you want your image and how it affects performance if it is a large file.
i usually use save for web mode that exists in photoshop. obviously the lower size is best. The sizes that you talking about (100-150) are good or not in relation to the dimension of the image. Anyway i advice you to use sprites and when possible in jpeg format.
something like 75-80% quality are good enought to a good quality of image
And please pay attention to the cmyk mode, that cause problems in some browsers

Self-describing file format for gigapixel images?

In medical imaging, there appears to be two ways of storing huge gigapixel images:
Use lots of JPEG images (either packed into files or individually) and cook up some bizarre index format to describe what goes where. Tack on some metadata in some other format.
Use TIFF's tile and multi-image support to cleanly store the images as a single file, and provide downsampled versions for zooming speed. Then abuse various TIFF tags to store metadata in non-standard ways. Also, store tiles with overlapping boundaries that must be individually translated later.
In both cases, the reader must understand the format well enough to understand how to draw things and read the metadata.
Is there a better way to store these images? Is TIFF (or BigTIFF) still the right format for this? Does XMP solve the problem of metadata?
The main issues are:
Storing images in a way that allows for rapid random access (tiling)
Storing downsampled images for rapid zooming (pyramid)
Handling cases where tiles are overlapping or sparse (scanners often work by moving a camera over a slide in 2D and capturing only where there is something to image)
Storing important metadata, including associated images like a slide's label and thumbnail
Support for lossy storage
What kind of (hopefully non-proprietary) formats do people use to store large aerial photographs or maps? These images have similar properties.
It seems like starting with TIFF or BigTIFF and defining a useful subset of tags + XMP metadata might be the way to go. FITS is no good since it is basically for lossless data and doesn't have a very appropriate metadata mechanism.
The problem with TIFF is that it just allows too much flexibility, but a subset of TIFF should be acceptable.
The solution may very well be http://ome-xml.org/ and http://ome-xml.org/wiki/OmeTiff.
It looks like DICOM now has support:
ftp://medical.nema.org/MEDICAL/Dicom/Final/sup145_ft.pdf
You probably want FITS.
Arbitrary size
1--3 dimensional data
Extensive header
Widely used in astronomy and endorsed by NASA and the IAU
I'm a pathologist (and hobbyist programmer) so virtual slides and digital pathology are a huge interest of mine. You may be interested in the OpenSlide project. They have characterized a number of the proprietary formats from the large vendors (Aperio, BioImagene, etc). Most seem to consist of a pyramidal zoomed (scanned at different microscopic objectives, of course), large tiff files containing multiple tiled tiffs or compressed (JPEG or JPEG2000) images.
The industry standard is DICOM Sup 145; getting vendors to adopt it though has been sluggish, but inventing yet another format would probably not be helpful.
PNG might work for you. It can handle large images, metadata, and the PNG format can have some interlacing, so you can get up to (down to?) an n/8 x n/8 downsampled image pretty easily.
I'm not sure if PNG can do rapid random access. It is chunked, but that might not be enough.
You could represent sparse data with the transparency channel.
JPEG2000 might be worth a look, some interesting efforts from National libraries in this space.

Ruthlessly compressing large images for the web

I have a very large background image (about 940x940 pixels) and I'm wondering if anyone has tips for compressing a file this large further than Photoshop can handle? The best compression without serious loss of quality from Photoshop is PNG 8 (250 KB); does anyone know of a way to compress an image down further than this (maybe compress a PNG after it's been saved)?
I don't normally deal with optimizing images this large, so I was hoping someone would have some pointers.
It will first depend on what kind of image you are trying to compress. The two basic categories are:
Picture
Illustration
For pictures (such as photographs), a lossy compression format like JPEG will be best, as it will remove details that aren't easily noticed by human visual perception. This will allow very high compression rates for the quality. The downside is that excessive compression will result in very noticeable compression artifacts.
For illustrations that contain large areas of the same color, using a lossless compression format like PNG or GIF will be the best approach. Although not technically correct, you can think of PNG and GIF will compress repetitions the same color very well, similar to run-length encoding (RLE).
Now, as you've mentioned PNG specifically, I'll go into that discussion from my experience of using PNGs.
First, compressing a PNG further is not a viable option, as it's not possible to compress data that has already been compressed. This is true with any data compression; removing the entropy from the source data (basically, repeating patterns which can be represented in more compact ways) leads to the decrease in the amount of space needed to store the information. PNG already employs methods to efficiently compress images in a lossless fashion.
That said, there is at least one possible way to drop the size of a PNG further: by reducing the number of colors stored in the image. By using "indexed colors" (basically embedding a custom palette in the image itself), you may be able to reduce the size of the file. However, if the image has many colors to begin with (such as having color gradients or a photographic image) then you may not be able to reduce the number of colors used in a image without perceptible loss of quality.
Basically it will come down to some trial-and-error to see if the changes to the image will cause any change in image quailty and file size.
The comment by Paul Fisher reminded me that I also probably wouldn't recommend using GIF either. Paul points out that PNG compresses static line art better than GIF for nearly every situation.
I'd also point out that GIF only supports 8-bit images, so if an image has more than 256 colors, you'll have to reduce the colors used.
Also, Kent Fredric's comment about reducing the color depth has, in some situtations, caused a increase in file size. Although this is speculation, it may be possible that dithering is causing the image to become less compressible (as dithering introduces pixels with different color to simulate a certain other color, kind of like mixing pigment of different color paint to end up with another color) by introducing more entropy into the image.
Have a look at http://www.irfanview.com/, is an oldy but a goody.
Have found this is able to do multipass png compression pretty well, and does batch processing way faster than PS.
There is also PNGOUT available here http://advsys.net/ken/utils.htm, which is apparently very good.
Heres a point the other posters may not have noticed that I found out experimentally:
On some installations, the default behaviour is to save a full copy of the images colour profile along with the image.
That is, the device calibration map, usually SRGB or something similar, that tells using agents how to best map the colour to real world-colours instead of device independant ones.
This image profile is however quite large, and can make some of the files you would expect to be very small to be very large, for instance, a 1px by 1px image consuming a massive 25kb. Even a pure BMP format ( uncompressed ) can represent 1 pixel in less.
This profile is generally not needed for the web, so, when saving your photoshop images, make sure to export them without this profile, and you'll notice a marked size improvement.
You can strip this data using another tool such as gimp, but it can be a little time consuming if there are many files.
pngcrush can further compress PNG files without any data loss, it applies different combinations of the encoding and compression options to see which one works best.
If the image is photographic in nature, JPEG will compress it far better than PNG8 for the same loss in quality.
Smush.It claims to go "beyond the limitations of Photoshop". And it's free and web-based.
It depends a lot on the type of image. If it has a lot of solid colors and patterns, then PNG or GIF are probably your best bet. But if it's a photo-realistic image then JPG will be better - and you can crank down the quality of JPG to the point where you get the compression / quality tradeoff you're looking for (Photoshop is very good at showing you a preview of the final image as you adjust the quality).
The "compress a PNG after it's been saved" part looks like a deep misunderstanding to me. You cannot magically compress beyond a certain point without information loss.
First point to consider is whether the resolution has to be this big. Reducing the resolution by 10% in both directions reduces the file size by 19%.
Next, try several different compression algorithms with different grades of compression versus information/quality loss. If the image is sketchy, you might get away with quite rigorous JPEG compression.
I would tile it, Unless you are absolutely sure that you audience has bandwidth.
next is jpeg2k.
To get more out of a JPEG file you can use the 'Modified Quality Setting' of the "Save as Web" dialog.
Create a mask/selection that contains white where you want to keep the most detail, eq around Text. You can use Quick-Mask to draw the mask with a brush. It helps to Feather the selection, this results in a nice white to black transition in the next step.
save this mask/selection as a channel and give the channel a name
Use File->Save as Web
Select JPEG as file format
Next to the Quality box there is a small button with a circle on it. Click that. Select the saved channel in step 2 and play with the quality setting for the white and black part of the channel content.
http://www.jpegmini.com is a new service that creates standard jpgs with an impressively small filesize. I've had good success with it.
For best quality single images, I highly recommend RIOT. You can see the original image, aside from the changed one.
The tool is free and really worth trying out.
JPEG2000 gives compression ratios on photographic quality images that are significantly higher than JPEG (or PNG). Also, JPEG2000 has both "lossy" and "lossless" compression options that can be tuned quite nicely to your individual needs.
I've always had great luck with jpeg. Make sure to configure photoshop to not automatically save thumbnails in jpegs. In my experience I get the greatest bang/buck ratio by using 3 pass progressive compression, though baseline optimized works pretty well. Choose very low quality levels (e.g. 2 or 3) and experiment until you've found a good trade off.
PNG images are already compressed internally, in a manner that doesn't benefit from more compression much (and may actually expand if you try to compress it).
You can:
Reduce the resolution from 940x940 to something smaller like 470x470.
Reduce the color depth
Compress using a lossy compression tool like JPEG
edit: Of course 250KB is large for a web background. You might also want to rethink the graphic design that requires this.
Caesium is the best tool i have ever seen.

Resources