Page 1 of 1

Round Image(s) overlap issue

Posted: 2018-03-18T00:14:02-07:00
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.

Re: Round Image(s) overlap issue

Posted: 2018-03-18T00:26:50-07:00
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?

Re: Round Image(s) overlap issue

Posted: 2018-03-18T03:58:30-07:00
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.

Re: Round Image(s) overlap issue

Posted: 2018-03-18T10:58:29-07:00
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

Re: Round Image(s) overlap issue

Posted: 2018-03-18T11:36:48-07:00
by stealthrt
This is the overall look i am going for:

Image

Re: Round Image(s) overlap issue

Posted: 2018-03-18T11:37:30-07:00
by stealthrt
Also, If you look at yours, Marge (last image) seems to be cut off as well like mine was.

Re: Round Image(s) overlap issue

Posted: 2018-03-18T13:22:38-07:00
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

Re: Round Image(s) overlap issue

Posted: 2018-03-18T13:29:49-07:00
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

Re: Round Image(s) overlap issue

Posted: 2018-03-19T08:45:26-07:00
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");
    }
}

Re: Round Image(s) overlap issue

Posted: 2018-03-19T13:49:14-07:00
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

Re: Round Image(s) overlap issue

Posted: 2018-03-19T15:51:16-07:00
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.

Re: Round Image(s) overlap issue

Posted: 2018-03-20T07:42:10-07:00
by stealthrt
I've waited for 30+ minutes and it still has not progressed to the next step (image.Composite(mask, CompositeOperator.CopyAlpha);).

Image