Google Groups Home
Help | Sign in
Message from discussion Precise bitmaps
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Steve Luttrell  
View profile
 More options Feb 28 2005, 3:39 am
Newsgroups: comp.soft-sys.math.mathematica
From: "Steve Luttrell" <steve_usenet@_removemefirst_luttrell.org.uk>
Date: Mon, 28 Feb 2005 08:39:06 +0000 (UTC)
Local: Mon, Feb 28 2005 3:39 am
Subject: Re: Precise bitmaps
I have used precisely the same export/import trick as you in order to use
the Mathematica rendering engine to generate bitmaps for use in image
processing applications. My cure to the extra white space problem was to
simply discard those pixels after Importing the bitmap, and to anticipate
this loss of pixels by Exporting a slightly larger bitmap in the first
place.

I have just tried to reproduce what I did using Mathematica 5.1 (for
Windows) and find that the extra whitespace problem seems to have been cured
in that version. However, here is (roughly) what I did to cure the problem
in an earlier version of Mathematica:

Load a package for generating a pretty image.

<< "Graphics`Shapes`"

Generate an image (with a black background so you can see the extra white
space when it is added), export, then import it. Notice that I export 1
pixel more in each dimension than I eventually need.

g = Show[Graphics3D[Torus[], Background -> RGBColor[0, 0, 0]]]
Export["temp.bmp", g, "BMP", ImageSize -> {101, 101}]
g2 = Import["temp.bmp", "BMP"]
Show[g2]

Now have a look at the contents of g2. The first part is the image data, so
I have displayed only its dimensions. This shows which bits have to be
changed if you crop the image. There may be an "official" way of doing this,
but I haven't found it.

Dimensions[g2[[1,1]]]
g2[[1,2]]
g2[[1,3]]
g2[[1,4]]
g2[[2]]
g2[[3]]
g2[[4]]

{101, 101, 3}
{{0, 0}, {101, 101}}
{0, 255}
ColorFunction -> RGBColor
ImageSize -> {101, 101}
PlotRange -> {{0, 100}, {1, 101}}
AspectRatio -> Automatic

Make a copy of g2, and then hack it to crop the image. I am dropping the
last pixel in each row, and also the last row of the image. I am doing this
from memory, so if this prescription doesn't get rid of the white space then
modify it appropriately.

g3 = g2;
g3[[1,1]] = Drop[Map[Drop[#,-1]&,g2[[1,1]]],-1];
g3[[1,2,2]] = g3[[1,2,2]] - {1, 1};
g3[[2]] = g3[[2]] /. {x_, y_} -> {x - 1, y - 1};
g3[[3]] = g3[[3]] /. {{x1_, y1_}, {x2_, y2_}} -> {{x1, y1 - 1}, {x2, y2 -
1}};
Show[g3]

Have a look at the contents of g3.

Dimensions[g3[[1,1]]]
g3[[1,2]]
g3[[1,3]]
g3[[1,4]]
g3[[2]]
g3[[3]]
g3[[4]]

{100, 100, 3}
{{0, 0}, {100, 100}}
{0, 255}
ColorFunction -> RGBColor
ImageSize -> {100, 100}
PlotRange -> {{0, 99}, {1, 100}}
AspectRatio -> Automatic

That should do what you want.

Steve Luttrell

"Jan G. Korvink" <korv...@t-online.de> wrote in message
news:cvrqg4$p55$1@smc.vnet.net...

> Dear All,

> I am battling to obtain a "precise" Raster[] of some Graphics[] objects.
> There seems to be no straightforward way to do the conversion, so I tried:

> Export[ /tmp/myfile, Graphics[myGraphics], ImageSize -> {xmax,ymax}
> myBitsPerUnit ]
> g = Import[ /tmp/myfile ]

> from which I can unpack the Raster[]. Unfortunately the Raster[]
> contains extra white space around the object, and no matter what I
> select for "myfile" (I have tried all bitmap formats) I get a
> consistently bad result. Furthermore, the Export/Import route is pretty
> bad, since it is slow for large pictures.

> What works is to use Adobe Illustrator as the rendering engine. But this
> is not nice!

> I do not want to implement a renderer, unless absolutely necessary, and
> it seems silly since Mathematica has such an animal.

> Can anyone suggest an alternative route?

> Thanks in advance, Jan


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google