Re: Trouble controlling Rasterize -- it introduces unwanted borders
- To: mathgroup at smc.vnet.net
- Subject: [mg103120] Re: Trouble controlling Rasterize -- it introduces unwanted borders
- From: Alexey <lehin.p at gmail.com>
- Date: Tue, 8 Sep 2009 06:00:27 -0400 (EDT)
- References: <h4rpch$l4j$1@smc.vnet.net>
Some my thoughts for you: 1) Graphics has a default width 360 pixels and in this way the quality will be only 360 pixels width even if Raster[] inside Graphics[] contains much more points. And resizing does not help. It also directly affects Export[]... :( But Image[] always has true dimensions and preserves quality. I discussed it in detail here: http://tinyurl.com/njmpro I have created a function Raster2Image that converts Graphics[Raster []] to Image with preserving quality (as opposed to Image[Graphics]): Raster2Image = Image[Part[#, Sequence @@ Position[#, _Raster] [[1]], 1], ColorSpace -> "RGB"] &; I also created function fix4Graphics that fixes the above-mentioned behavior (loosing quality): fix4Graphics = Append[#, ImageSize -> Reverse[Take[Dimensions [Part[#, Sequence @@ Position[#, _Raster][[1]], 1]], 2]]] &; 2) I have not found a perfect way how to change *default* width of Graphics[] (without using ImageSize). I discussed it here: http://tinyurl.com/l288ne On 30 Jul, 13:33, Damon <damonwisc... at gmail.com> wrote: > I can't work out how to eliminate spurious borders in Rasterize. In > the following code, I create a simple graphic (a line from {0,0} to > {1,1}) with the plot range {{0,1},{0,1}}. I want to rasterize it to be > 6 pixels high, and I want the rasterized version to occupy exactly the > same plot range as the original. But the Rasterize[] operation > introduces an unwanted border (shown in yellow in the code below), and > when I try to use Inset to specify the coordinate range of the > rasterized graphic then I end up with another unwanted border (show in > red in the code below). > > I would be grateful for help in understanding where these borders come > from and how to eliminate them. > > g = Graphics[{AbsoluteThickness[20], Line[{{0, 0}, {1, 1}}]}, > Background -> Cyan, PlotRange -> {{0, 1}, {0, 1}}, > ImageSize -> 150]; > gr = Rasterize[g, RasterSize -> {{Infinity}, {6}}, > Background -> Yellow]; > gri = Graphics[Inset[gr, {0, 0}, {0, 0}, {1, 1}, Background -> Red]]; > Show[gri, Frame -> True]