0
$\begingroup$

When I try to draw consecutive lines, I start to get aliasing artifacts in my image as my lines get thinner. Am I missing an option which may be causing this? I've tried Method->ShrinkWrap and setting all the padding etc. to zero but still no luck.

e.g, this looks ok,

x = 1;
rectangles = Table[{Black, Rectangle[{i x, 0}, {i x + x/2, 20}]}, {i, 0, 
    100}];
Graphics[rectangles, ImageSize -> {1000, 1000}, AspectRatio -> 1]

e.g, but when I double the number of lines,

x = 1;
rectangles = Table[{Black, Rectangle[{i x, 0}, {i x + x/2, 20}]}, {i, 0, 
    200}];
Graphics[rectangles, ImageSize -> {1000, 1000}, AspectRatio -> 1]

I begin to see artifacts.. (Is it my code?)

Thanks,

Edit: Method 2 using Raster[]+ImageResize (still artifacts)

rect = Table[((-1)^i + 1)/2, {i, 0, 500}];
gra = Graphics[Raster[{rect}], ImageSize -> {1000}];
ImageResize[gra, {1000, 400}]

Is it my eyes?

$\endgroup$
  • $\begingroup$ Menu -> Edit -> Appearance -> Graphics $\endgroup$ – Feyre Oct 25 '16 at 12:14
  • $\begingroup$ no it doesn't seem to be a display error. I can export the image (and even print it) and still see artifacts $\endgroup$ – Jeff Oct 25 '16 at 12:27
  • $\begingroup$ I see no artefacts, maybe it's your screen's resolution. $\endgroup$ – Feyre Oct 25 '16 at 12:31
  • $\begingroup$ In the new images I see two lines which are thinner than the others. $\endgroup$ – Feyre Oct 25 '16 at 12:43
  • $\begingroup$ Yes, this is the problem. My question is why? Is it something in my code? Is there a hidden border? $\endgroup$ – Jeff Oct 25 '16 at 14:08
3
$\begingroup$

Suppose your ImageSize is 1000, naturally in order to properly display the image with two pixels for black and white, you would have 250 white parts and 250 black parts, however

Length[rect]

501

Which means that two of the black lines will have only 1 pixel each.

Solution?

rect = Table[((-1)^i + 1)/2, {i, 0, 500}];
gra = Graphics[Raster[{rect}], ImageSize -> {1002}]
ImageResize[gra, {1002, 400}]

enter image description here

(Click to view properly)

$\endgroup$
  • $\begingroup$ thanks, so it was just my code, :) $\endgroup$ – Jeff Oct 26 '16 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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