Skip to content
This repository has been archived by the owner on Nov 19, 2020. It is now read-only.

Copy blob image with RW properties #1037

Merged
merged 3 commits into from
Nov 23, 2017
Merged

Copy blob image with RW properties #1037

merged 3 commits into from
Nov 23, 2017

Conversation

fdncred
Copy link
Collaborator

@fdncred fdncred commented Nov 13, 2017

@cesarsouza,
I'm not sure you'll allow the PR but I have the need to manipulate Accord.Imaging.Blob properties. Specifically, I'm creating and merging my own blobs. This is an example of how I need to use it.

private Blob MergeBlobsVertically(Blob blobOne, Blob blobTwo)
{
    var newRect = new Rectangle(
        Math.Min(blobOne.Rectangle.X, blobTwo.Rectangle.X),
        Math.Min(blobOne.Rectangle.Y, blobTwo.Rectangle.Y),
        Math.Max(blobOne.Rectangle.Width, blobTwo.Rectangle.Width),
        blobOne.Rectangle.Height + blobTwo.Rectangle.Height);
    var blobBmp = new Bitmap(newRect.Width, newRect.Height);
    using (var g = Graphics.FromImage(blobBmp))
    {
        g.Clear(Color.Black);
        if (blobOne.Rectangle.Y == newRect.Y)
        {
            // Merge BlobOne on Top
            g.DrawImage(blobOne.Image.ToManagedImage(), new Point(0, 0));
            g.DrawImage(blobTwo.Image.ToManagedImage(), new Point(0, blobOne.Image.Height));
        }
        else
        {
            // Merge BlobTwo on Top
            g.DrawImage(blobTwo.Image.ToManagedImage(), new Point(0, 0));
            g.DrawImage(blobOne.Image.ToManagedImage(), new Point(0, blobTwo.Image.Height));
        }
    }
    var newBlob = new Blob(blobOne.ID, newRect, UnmanagedImage.FromManagedImage(blobBmp));
    newBlob.Area = blobOne.Area + blobTwo.Area; // Area looks to be the count of white pixels
    newBlob.CenterOfGravity = new Accord.Point(newRect.X + (newRect.Width / 2), newRect.Y + (newRect.Height / 2));
    newBlob.ColorMean = blobOne.ColorMean;
    newBlob.ColorStdDev = blobOne.ColorStdDev;
    newBlob.Fullness = (double)newBlob.Area / (newRect.Width * newRect.Height);
    // From BlobCounterBase Class
    //Blob blob = new Blob(j, new Rectangle(x1[j], y1[j], x2[j] - x1[j] + 1, y2[j] - y1[j] + 1));
    //blob.Area = blobArea;
    //blob.Fullness = (double)blobArea / ((x2[j] - x1[j] + 1) * (y2[j] - y1[j] + 1));
    //blob.CenterOfGravity = new Accord.Point((float)xc[j] / blobArea, (float)yc[j] / blobArea);
    //blob.ColorMean = Color.FromArgb((byte)(meanR[j] / blobArea), (byte)(meanG[j] / blobArea), (byte)(meanB[j] / blobArea));
    //blob.ColorStdDev = Color.FromArgb(
    //    (byte)(Math.Sqrt(stdDevR[j] / blobArea - blob.ColorMean.R * blob.ColorMean.R)),
    //    (byte)(Math.Sqrt(stdDevG[j] / blobArea - blob.ColorMean.G * blob.ColorMean.G)),
    //    (byte)(Math.Sqrt(stdDevB[j] / blobArea - blob.ColorMean.B * blob.ColorMean.B)));
    return newBlob;
}

I'm not sure I'm calculating all the properties correctly.

Thanks,
Darren

@fdncred
Copy link
Collaborator Author

fdncred commented Nov 13, 2017

Doh! Please ignore the build-all-462.cmd. I created that just to make it easier to compile.

@cesarsouza
Copy link
Member

cesarsouza commented Nov 22, 2017

Hi @fdncred,

All PRs that help you achieve something you need are more than welcome. I will need some time to take a look at the PR yet, and also all the other issues that have popped up in the last week, but I will incorporate it as soon as I can.

Don't worry about the build-all462.cmd, I will remove it manually either before or after I accept the PR!

Thanks a lot for the submission,
Cesar

@cesarsouza
Copy link
Member

cesarsouza commented Nov 22, 2017

I guess the main issue here is related to #627. After so many years working with Python where everything is publicly accessible, I now recognize how much more useful it would be if the project allowed more properties to be easily directly adjusted by users. As I said, I will try to accept the PR as soon as I can.

Regards,
Cesar

@cesarsouza cesarsouza merged commit 5962eb3 into accord-net:development Nov 23, 2017
@fdncred
Copy link
Collaborator Author

fdncred commented Nov 27, 2017

Looks good. Thanks!

@fdncred fdncred deleted the CopyBlobImage branch November 27, 2017 16:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants