Round Image(s) overlap issue

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Post Reply
stealthrt
Posts: 32
Joined: 2018-03-08T18:09:21-07:00
Authentication code: 1152

Round Image(s) overlap issue

Post by stealthrt »

Hey all I have the following C# code:

Code: Select all

List<string> lFiles = new List<string>();

lFiles.Add(@"C:\Users\David\Pictures\1.jpg");
lFiles.Add(@"C:\Users\David\Pictures\2.jpg");
lFiles.Add(@"C:\Users\David\Pictures\3.jpg");
IFiles.Add(@"C:\Users\David\Pictures\4.jpg");
IFiles.Add(@"C:\Users\David\Pictures\5.jpg");

using (MagickImageCollection images = new MagickImageCollection())
{
    MagickImage magickinput = null;

    foreach (string tempFile in lFiles)
    {
       magickinput = new MagickImage(tempFile);

       magickinput.Alpha(AlphaOption.Set);
       magickinput.Quality = 100;
       magickinput.Resize(0, 100);
       magickinput.Distort(DistortMethod.DePolar, 0);
       magickinput.VirtualPixelMethod = VirtualPixelMethod.HorizontalTile;
       magickinput.BackgroundColor = MagickColors.None;
       magickinput.Distort(DistortMethod.Polar, 0);                        
       images.Add(magickinput);
   }

   var montageSettings = new MontageSettings()
   {
       BackgroundColor = MagickColors.None,
       TileGeometry = new MagickGeometry(lFiles.Count, 1),
       Shadow = true,
       Geometry = new MagickGeometry(-10, 5, 0, 0)
   };

   using (IMagickImage result = images.Montage(montageSettings))
   {
       result.Composite(magickinput, CompositeOperator.DstIn);
       result.Trim();
       result.RePage();

       result.Write(@"C:\Users\David\Pictures\combinedImgs.png");
   }
}
This produces an image like this:

Image

Notice that the area around Maggie (the first image) has Lisa (the second image) within it and cuts out some of image 2???. It also cuts off Marge (last image). If I just set Geometry = new MagickGeometry(-10, 5, 0, 0) to Geometry = new MagickGeometry(5, 5, 0, 0) it then looks like this:

Image

Which fixes Marge (last image) but Maggie (first image) still looks odd...

I've also noticed that all the images seem to be "fuzzy" with their outlines:

ImageImage

First image is the original and the second is the Magick version.

Images used:

ImageImageImageImageImage

Maggie (first image) by herself looks like this:
Image

What am I doing incorrectly? I'm using version ImageMagick-7.0.7-Q16.
Last edited by stealthrt on 2018-03-18T00:37:50-07:00, edited 2 times in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Round Image(s) overlap issue

Post by fmw42 »

It might help if you post your input images. Also what version of Imagemagick? Does the same think happen with -smush that than montage?

What happens is you just process maggie by itself? Does it show the same issue?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Round Image(s) overlap issue

Post by snibgo »

You resize down, then distort depolar and polar. I expect the quality will be better (but processing slower) if you resize after the distortions.

But why distort at all? This is certain to remove sharpness from the image. A better method is to draw a white circle on a black background, and "CopyOpacity" that to the image.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Round Image(s) overlap issue

Post by fmw42 »

snibgo is correct. Here is somewhat like what he is suggesting. Unix command line syntax.

Code: Select all

convert maggie.jpg lisa.jpg bart.jpg homer.jpg marge.jpg -resize 100x100 \
null: \( -size 100x100 xc:black -fill white -draw "circle 50,50 50,100" \) \
-alpha off -compose copy_opacity -layers composite \
-background none -gravity center +smush -20+0 \
simpsons_circles.png
Image
stealthrt
Posts: 32
Joined: 2018-03-08T18:09:21-07:00
Authentication code: 1152

Re: Round Image(s) overlap issue

Post by stealthrt »

This is the overall look i am going for:

Image
stealthrt
Posts: 32
Joined: 2018-03-08T18:09:21-07:00
Authentication code: 1152

Re: Round Image(s) overlap issue

Post by stealthrt »

Also, If you look at yours, Marge (last image) seems to be cut off as well like mine was.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Round Image(s) overlap issue

Post by fmw42 »

How about this:

Code: Select all

convert maggie.jpg lisa.jpg bart.jpg homer.jpg marge.jpg -resize 100x100 \
null: \( -size 100x100 xc:black -fill white -draw "circle 50,50 50,88" \) \
-alpha off -compose copy_opacity -layers composite \
null: \( -size 100x100 xc:"graya(100%,0)" -fill black -draw "circle 50,50 50,90" -blur 0x5 \) \
-compose dstover -layers composite \
-background none -gravity center +smush -25+0 \
simpsons_circles2.png
Image
stealthrt
Posts: 32
Joined: 2018-03-08T18:09:21-07:00
Authentication code: 1152

Re: Round Image(s) overlap issue

Post by stealthrt »

This is as far as i have gotten with translating the command line:

Code: Select all

List<string> lFiles = new List<string>();

lFiles.Add(@"C:\Users\David\Pictures\1.jpg");
lFiles.Add(@"C:\Users\David\Pictures\2.jpg");
lFiles.Add(@"C:\Users\David\Pictures\3.jpg");
lFiles.Add(@"C:\Users\David\Pictures\4.jpg");
lFiles.Add(@"C:\Users\David\Pictures\5.jpg");

using (MagickImageCollection images = new MagickImageCollection())
{
       MagickImage magickinput = null;

       foreach (string tempFile in lFiles)
       {
            magickinput = new MagickImage(tempFile);
            IMagickImage _circle = new MagickImage();
                                                        
            magickinput.Resize(100, 100);
            _circle = new MagickImage(MagickColor.FromRgb(255, 255, 255), magickinput.Width + 20, magickinput.Height);
            _circle.Draw(new DrawableCircle(50, 50, 50, 100));
            _circle.Alpha(AlphaOption.Off);
            //_circle.Compose....????

      }
}
I'm not sure how to do these following commands in C#:

xc:black
copy_opacity -layers
dstover -layers
xc:"graya(100%,0)"
+smush
stealthrt
Posts: 32
Joined: 2018-03-08T18:09:21-07:00
Authentication code: 1152

Re: Round Image(s) overlap issue

Post by stealthrt »

Solution provided by dlemstra:

Code: Select all

List<string> lFiles = new List<string>();

lFiles.Add(@"C:\Users\David\Pictures\1.jpg");
lFiles.Add(@"C:\Users\David\Pictures\2.jpg");
lFiles.Add(@"C:\Users\David\Pictures\3.jpg");
lFiles.Add(@"C:\Users\David\Pictures\4.jpg");
lFiles.Add(@"C:\Users\David\Pictures\5.jpg");

using (MagickImageCollection images = new MagickImageCollection())
{
    foreach (string tempFile in lFiles)
    {
        images.Add(tempFile);
    }

    using (var mask = new MagickImage("xc:black", 100, 100))
    {
        mask.Settings.FillColor = MagickColors.White;
        mask.Draw(new DrawableCircle(50, 50, 50, 88));
        mask.HasAlpha = false;

        foreach (var image in images)
        {
            image.Resize(100, 100);

            image.Composite(mask, CompositeOperator.CopyAlpha);
        }
    }

    using (var shadow = new MagickImage("xc:none", 100, 100))
    {
        shadow.Settings.FillColor = MagickColors.Black;
        shadow.Draw(new DrawableCircle(50, 50, 50, 90));
        shadow.Blur(0, 5);

        foreach (var image in images)
        {
            image.Composite(shadow, CompositeOperator.DstOver);
        }
    }

    images.First().BackgroundColor = MagickColors.None;

    using (IMagickImage result = images.SmushHorizontal(-25))
    {
        result.Write(@"C:\Users\David\Pictures\combinedImgs.png");
    }
}
stealthrt
Posts: 32
Joined: 2018-03-08T18:09:21-07:00
Authentication code: 1152

Re: Round Image(s) overlap issue

Post by stealthrt »

Correction for the above code - There seems to be an error once it gets to image.Resize(100, 100);. It seems to freeze the program and just stays there
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Round Image(s) overlap issue

Post by dlemstra »

It will freeze only the first time you run the program because it will then run a benchmark to determine the performance of your CPU and GPU. Just let it continue and you will see that it will be pretty fast the next time you run the program again.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
stealthrt
Posts: 32
Joined: 2018-03-08T18:09:21-07:00
Authentication code: 1152

Re: Round Image(s) overlap issue

Post by stealthrt »

I've waited for 30+ minutes and it still has not progressed to the next step (image.Composite(mask, CompositeOperator.CopyAlpha);).

Image
Post Reply