1
$\begingroup$

I would like to produce a black image with superposed white disks.

  • The disk centers should start from the lower left and end at the upper right position.

  • The disk size should increase lineary from lower left to upper right position.

What I tried:

n = 400;
imageData = Array[0 &, {n, n}];
image = Image[imageData];


array = Table[{i, i}, {i, 1, n}]; 
objects = Table[Image@DiskMatrix[i/10 // N], {i, 1, n, 1}];

ImageCompose[image, objects, array]

Result:

enter image description here

As you see this the diagonal is not white.

My expected results should be:

enter image description here

How can this be done?

$\endgroup$
2
  • 2
    $\begingroup$ Wouldn't it be more convenient to use Disk / Table / Rasterize? $\endgroup$
    – Kuba
    Commented Feb 21, 2017 at 11:02
  • $\begingroup$ @Kuba: Could you please show a code snipplet? $\endgroup$
    – mrz
    Commented Feb 21, 2017 at 11:09

2 Answers 2

4
$\begingroup$

Like this?

Graphics[{White, Table[
   Disk[{i, i}, .2 i],
   {i, 10}]}, Background -> Black]

enter image description here

EDIT: If, for some reason, you want to do this with arrays and images instead of Graphics, you can use InverseDistanceTransform to turn a 2d array of radii into an image of overlapping discs:

dist = Image[
  SparseArray[Table[{5 i, 5 i} -> i, {i, 1, 20, 5}], {100, 100}]]

enter image description here

InverseDistanceTransform[dist]

enter image description here

$\endgroup$
1
  • $\begingroup$ Great solution ... thanks $\endgroup$
    – mrz
    Commented Feb 21, 2017 at 11:12
2
$\begingroup$

another approach, close to the original. ImageCompose one disk at a time then ImageMultiply the results. For this to work we need to work in negative images, so you start with a white "canvas" and multiply by black (0) disks. (then negate the final result)

imageData = Array[1 &, {n, n}];
image = Image[imageData];
array = Table[{i, i}, {i, 1, n, 20}];
objects = 
  Table[ColorNegate@Image@(DiskMatrix[i/10 // N]), {i, 1, n, 20}];
ColorNegate@
 ImageMultiply[image, 
  Sequence @@ (MapThread[
     ImageCompose[image, ##] &, {objects, array}])]

enter image description here

I expect you can see in the original form ImageCompose was covering prior white disks with the black border of the next disk image. To illustrate, colorize the black part of the individual disk images:

objects = Table[ColorReplace[Image@DiskMatrix[i/10 // N],
    0 -> Hue[RandomReal[{0, 2/3}]]], {i, 1, n, 20}];
ImageCompose[image, objects, array]

enter image description here

$\endgroup$
0

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.