Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Exporting images without white borders

  • To: mathgroup at
  • Subject: [mg75338] Re: Exporting images without white borders
  • From: Szabolcs <szhorvat at>
  • Date: Wed, 25 Apr 2007 05:43:36 -0400 (EDT)
  • References: <f0hunk$a3b$>

On Apr 23, 11:36 am, "Steven T. Hatton" <hatt... at>
> If I import an image into a notebook and use the raster to create an image
> with the same number of pixels, when I export the image it always has a
> white frame around it.

This is very disappointing, but it seems that there is no simple way
of exporting a matrix as a pixel-perfect image from Mathematica (or at
least I couldn't find any in the documentation). When using Export
with a graphics format, the data is always converted to a vector image
first, so small distortions may be introduced during rasterization.
(And I wouldn't be surprised if it turned out that the end result is a
little bit different for different platforms. I wouldn't trust a
solution that works by tweaking PlotRange and ImageSize values.)

A workaround is to write Mathematica code to export the data to some
very simple image format, e.g. a portable graymap. You can find the
description of the format here:

img = Import["some grayscale image"]
dat = img[[1,1]]

    {{"P2"}, (* this specifies the image format *)
     Reverse@Dimensions@dat, (* the image dimensions *)
     {Max@dat} (* the value corresponding to white *)
    } ~Join~ Reverse@dat,

You may have to figure out the white value yourself: it may be
represented in Raster[] in different ways depending on the format of
the image you imported.

There are many free programs that can read pgm files and convert them
to other formats:

I hope this helps.


  • Prev by Date: Re: CrossProduct in Spherical Coordinates
  • Next by Date: Re: What's wrong?
  • Previous by thread: Re: Exporting images without white borders
  • Next by thread: short cut