3
$\begingroup$

Bug introduced in 13.1 or earlier


I am using Rasterize on a Graphics object (because I want to count the number of black and white pixels). However, applying it introduces a new, blank area into the rasterized version of the Graphics object (see the image below). Why is this and how to avoid it?

enter image description here

EDIT: The code used to generate the Graphics object:

posList = Table[
   {RandomReal[{0, 1}], RandomReal[{0, 1/29}]}
   , {n, 1, 100}];
graphics = Graphics[{
    EdgeForm[None], Black,
    Table[Ellipsoid[posList[[n]], {0.5/29, 0.5/29}/2], {n,1,100}]
   }, PlotRange -> {{0, 1}, {0, 1/29}}];
$\endgroup$
5
  • $\begingroup$ When generating Graphics, use Graphics[..., PlotRangePadding -> 0]. $\endgroup$
    – Domen
    Commented Aug 30, 2022 at 18:35
  • $\begingroup$ Thanks for the suggestion but it didn't make any difference unfortunately. $\endgroup$ Commented Aug 30, 2022 at 19:02
  • $\begingroup$ It might help if you provide your code for generating graphics. There are also other options, like ImageMargins and ImagePaddings. $\endgroup$
    – Domen
    Commented Aug 30, 2022 at 19:12
  • $\begingroup$ I've included it. $\endgroup$ Commented Aug 30, 2022 at 19:19
  • $\begingroup$ I reproduce the issue with version 13.1.0 on Windows 10 x64, but not with version 12.3.1 on the same machine. Hence it is a regression bug. Please report it to the support. $\endgroup$ Commented Aug 31, 2022 at 1:37

1 Answer 1

1
$\begingroup$

I reproduce the issue with version 13.1.0 on Windows 10 x64, but not with version 12.3.1 on the same machine. Hence it is a regression bug. Please report it to the support.

As a workaround, you can specify explicit ImageSize for Graphics:

posList = Table[{RandomReal[{0, 1}], RandomReal[{0, 1/29}]}, {n, 1, 100}];
graphics = Graphics[{EdgeForm[None], Black, 
    Table[Ellipsoid[posList[[n]], {0.5/29, 0.5/29}/2], {n, 1, 100}]}, 
   PlotRange -> {{0, 1}, {0, 1/29}}, ImageSize -> {720, 25}];

Rasterize[graphics]

screenshot

Specifying ImageSize for Rasterize also works:

posList = Table[{RandomReal[{0, 1}], RandomReal[{0, 1/29}]}, {n, 1, 100}];
graphics = Graphics[{EdgeForm[None], Black, 
    Table[Ellipsoid[posList[[n]], {0.5/29, 0.5/29}/2], {n, 1, 100}]}, 
   PlotRange -> {{0, 1}, {0, 1/29}}];

Rasterize[graphics, ImageSize -> {720, 25}]

screenshot

It looks line the bug is caused by too small default image height of your Graphics:

is = Differences[Rasterize[Annotation[graphics, "Output", "Region"], "Regions"][[1, 2]]][[1]]
{360., 12.4138}

Specifying sufficiently large ImageSize fixes the problem even if the original small RasterSize is requested:

Rasterize[graphics, ImageSize -> 2 is, RasterSize -> Round@is]

screenshot

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.