diff --git a/Sources/Accord.Imaging/Filters/Other/ExtractBiggestBlob.cs b/Sources/Accord.Imaging/Filters/Other/ExtractBiggestBlob.cs index e5838aa4d..9ea1020cd 100644 --- a/Sources/Accord.Imaging/Filters/Other/ExtractBiggestBlob.cs +++ b/Sources/Accord.Imaging/Filters/Other/ExtractBiggestBlob.cs @@ -181,13 +181,31 @@ public Bitmap Apply(Bitmap image) /// The source image does not contain any blobs. /// public Bitmap Apply(BitmapData imageData) + { + using (UnmanagedImage biggestBlob = Apply(new UnmanagedImage(imageData))) + { + // dispose unmanaged image of the biggest blob + return biggestBlob.ToManagedImage(); + } + } + + /// + /// Apply filter to an image (not implemented). + /// + /// + /// Image in unmanaged memory. + /// + /// Returns filter's result obtained by applying the filter to + /// the source image. + /// + 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(); @@ -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 { @@ -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; - } - - /// - /// Apply filter to an image (not implemented). - /// - /// - /// Image in unmanaged memory. - /// - /// Returns filter's result obtained by applying the filter to - /// the source image. - /// - /// The method is not implemented. - /// - public UnmanagedImage Apply(UnmanagedImage image) - { - throw new NotImplementedException("The method is not implemented for the filter."); + return biggestBlob.Image; } /// @@ -270,11 +267,9 @@ public UnmanagedImage Apply(UnmanagedImage image) /// Source image to be processed. /// Destination image to store filter's result. /// - /// The method is not implemented. - /// public void Apply(UnmanagedImage sourceImage, UnmanagedImage destinationImage) { - throw new NotImplementedException("The method is not implemented filter."); + Apply(sourceImage).Copy(destinationImage); } } }