compositing Venn diagrams

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
aschig

compositing Venn diagrams

Post by aschig »

I would like to use circles of different colors such that they are solid filled, but as I lay one circle to partially overlap another, the part where they overlap has a third color.

So
Draw circle points 20, 20 20, 30 fill red
Draw circle points 25, 20 25, 30 fill blue

except that the overlapping region is yellow.

Any help greatly appreciated.
No previous images need exist, everything can start from scratch.
aschig

Re: compositing Venn diagrams

Post by aschig »

Hi,

I have made some progress with ImageMagick in making these, but donot know how to convert the composite command (the way I have used it) in to perl's magick.

If I make im1.png and im2.png in this way:
$im1->Draw(primitive=>'circle',points=>'270,220 270,250', fill=>'red');
$im2->Draw(primitive=>'circle',points=>'250,210 250,240', fill=>'blue');

Then I can get to overlap them with the overlapping portion seen in a separate color using
composite and then coloring it the way I want using convert. How do I do that in perl? Can the two be combined? Is there an overall shortcut?

composite im2.png im1.png im1.png out.png
convert out.png -fill yellow \
-draw 'color 266,209 floodfill' color_floodfill.png

Help will be appreciated.

-aschig
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: compositing Venn diagrams

Post by anthony »

If you draw the circles on separate canvases, then either 'screen' or 'add' them together, you can generate a 'purple color...

An example of this is with compose 'plus' in IM Examples....
http://www.imagemagick.org/Usage/compose/#plus

The other way is to generate the yellow area separately by compositing the two circles to produce a mask of the area that can then be 'colorized' completely yellow before this is overlaid on the main canvas.

Either method should produce a better anti-aliased result that trying to 'flood fill' the area which rarely produces a acceptable result... See IM Examples, Anti-aliasing for examples of trying to flood fill images with anti-aliased edges.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply