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

Commit

Permalink
GH-587: UnmanagedImage does not supported in ExtractBiggestBlob filter
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarsouza committed Aug 12, 2017
1 parent 1cb3ead commit 5bbb4f1
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions Sources/Accord.Imaging/Filters/Other/ExtractBiggestBlob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,31 @@ public Bitmap Apply(Bitmap image)
/// <exception cref="ArgumentException">The source image does not contain any blobs.</exception>
///
public Bitmap Apply(BitmapData imageData)
{
using (UnmanagedImage biggestBlob = Apply(new UnmanagedImage(imageData)))
{
// dispose unmanaged image of the biggest blob
return biggestBlob.ToManagedImage();
}
}

/// <summary>
/// Apply filter to an image (not implemented).
/// </summary>
///
/// <param name="image">Image in unmanaged memory.</param>
///
/// <returns>Returns filter's result obtained by applying the filter to
/// the source image.</returns>
///
public UnmanagedImage Apply(UnmanagedImage image)
{
// check pixel format of the source image
if (!FormatTranslations.ContainsKey(imageData.PixelFormat))
if (!FormatTranslations.ContainsKey(image.PixelFormat))
throw new UnsupportedImageFormatException("Source pixel format is not supported by the filter.");

// locate blobs in the source image
BlobCounter blobCounter = new BlobCounter(imageData);
BlobCounter blobCounter = new BlobCounter(image);

// get information about blobs
Blob[] blobs = blobCounter.GetObjectsInformation();
Expand Down Expand Up @@ -216,7 +234,7 @@ public Bitmap Apply(BitmapData imageData)
// extract biggest blob's image
if (originalImage == null)
{
blobCounter.ExtractBlobsImage(new UnmanagedImage(imageData), biggestBlob, false);
blobCounter.ExtractBlobsImage(image, biggestBlob, false);
}
else
{
Expand All @@ -233,34 +251,13 @@ public Bitmap Apply(BitmapData imageData)
}

// check its size
if ((originalImage.Width != imageData.Width) || (originalImage.Height != imageData.Height))
if ((originalImage.Width != image.Width) || (originalImage.Height != image.Height))
throw new InvalidImagePropertiesException("Original image must have the same size as passed source image.");

blobCounter.ExtractBlobsImage(originalImage, biggestBlob, false);
}

Bitmap managedImage = biggestBlob.Image.ToManagedImage();

// dispose unmanaged image of the biggest blob
biggestBlob.Image.Dispose();

return managedImage;
}

/// <summary>
/// Apply filter to an image (not implemented).
/// </summary>
///
/// <param name="image">Image in unmanaged memory.</param>
///
/// <returns>Returns filter's result obtained by applying the filter to
/// the source image.</returns>
///
/// <exception cref="NotImplementedException">The method is not implemented.</exception>
///
public UnmanagedImage Apply(UnmanagedImage image)
{
throw new NotImplementedException("The method is not implemented for the filter.");
return biggestBlob.Image;
}

/// <summary>
Expand All @@ -270,11 +267,9 @@ public UnmanagedImage Apply(UnmanagedImage image)
/// <param name="sourceImage">Source image to be processed.</param>
/// <param name="destinationImage">Destination image to store filter's result.</param>
///
/// <exception cref="NotImplementedException">The method is not implemented.</exception>
///
public void Apply(UnmanagedImage sourceImage, UnmanagedImage destinationImage)
{
throw new NotImplementedException("The method is not implemented filter.");
Apply(sourceImage).Copy(destinationImage);
}
}
}

0 comments on commit 5bbb4f1

Please sign in to comment.