Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"ApplyMask" and "MaskedFilter" filters doesn't work correctlly #411

Open
GoogleCodeExporter opened this issue Mar 29, 2016 · 6 comments
Open

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1.First, thanks for create great AForge.net free library in image processing 
field.
2.I use the code "new ApplyMask(imageMask).ApplyInPlace(image);" in my project.
3.I use too the code "new MaskedFilter(new Sepia(), 
image).ApplyInPlace(image);" and "image" is an "AForge.Imaging.UnmanagedImage" 
that by "ref" pass to my mask filter.
4.static void ApplyBlobMaskingOnImage(ref AForge.Imaging.UnmanagedImage image, 
ref System.Drawing.Rectangle[] rects)
        {
            if (rects == null || rects.Length == 0)
                return;

            var imageMask = AForge.Imaging.UnmanagedImage.Create(
                image.Width, image.Height, image.PixelFormat);

            foreach (var rect in rects)
                if (rect != System.Drawing.Rectangle.Empty)
                    AForge.Imaging.Drawing.FillRectangle(imageMask, rect, System.Drawing.Color.White);

// I currently use this instead of:
            //new Invert().ApplyInPlace(imageMask);
            //new Subtract(imageMask).ApplyInPlace(image);

            // Bug
            new ApplyMask(imageMask).ApplyInPlace(image);
            //new MaskedFilter(new Sepia(), image).ApplyInPlace(image);
        }

What is the expected output? What do you see instead?
*When I pass an image in grayscale(8bpp) everything is ok, But pass a 
RGB(24bpp) image, unexpected region is show.

What version of the product are you using?
2.2.5

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 13 Aug 2015 at 7:32

@GoogleCodeExporter
Copy link
Author

One thing to note from your code:
//new MaskedFilter(new Sepia(), image).ApplyInPlace(image);
This looks very strange to me. You use same image as mask image, as input image 
for processing. I would not expect this.

The code around ApplyMask() seem to be valid. Did you try doing these steps 
first in IPLab application and see if it all works (just to exclude coding 
errors):
http://www.aforgenet.com/projects/iplab/

I believe you are telling about 24 bpp and 8 bpp input image, not mask. Since 
mask can be only 8 bpp (you would get exception otherwise).

Original comment by [email protected] on 13 Aug 2015 at 9:36

@GoogleCodeExporter
Copy link
Author

Very appreciate for your prompt response.

*Correct:* //new MaskedFilter(new Sepia(), *imageMask*).ApplyInPlace(*image*
);

Sorry about this issue, cause I use this function:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------
        static void ApplyBlobMaskingOnImage(ref
AForge.Imaging.UnmanagedImage image, ref System.Drawing.Rectangle[] rects)
        {
            if (rects == null || rects.Length == 0)
                return;

            var imageMask = AForge.Imaging.UnmanagedImage.Create(
                image.Width, image.Height, *image.PixelFormat*);

            foreach (var rect in rects)
                if (rect != System.Drawing.Rectangle.Empty)
                    AForge.Imaging.Drawing.FillRectangle(imageMask, rect,
System.Drawing.Color.White);

            new ApplyMask(imageMask).ApplyInPlace(image);
            //new MaskedFilter(new Sepia(), imageMask).ApplyInPlace(image);
        }
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------
But I don't care that I must use Gray image mask as overlay instead RGB
image mask even for RGB image! and "ApplyMask" or "MaskedFilter" don't
throw exception about this!

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------
.
.
.
            var imageMask = AForge.Imaging.UnmanagedImage.Create(
               image.Width, image.Height,
*System.Drawing.Imaging.PixelFormat.Format8bppIndexed*);
.
.
.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------
Be nice if the filters check for overlay that be Grayscale.

Very very good and thanks.
Good luck.
Hashem.

Original comment by [email protected] on 13 Aug 2015 at 12:27

@GoogleCodeExporter
Copy link
Author

The documentation clearly says about the fact that mask must be 8bpp:
http://www.aforgenet.com/framework/docs/html/fbcfe698-f9a2-a672-c334-30983103064
3.htm

The code tells an exception should be thrown if it is not 8bpp:
https://code.google.com/p/aforge/source/browse/trunk/Sources/Imaging/Filters/Oth
er/ApplyMask.cs

Original comment by [email protected] on 13 Aug 2015 at 1:05

  • Changed state: Rejected

@GoogleCodeExporter
Copy link
Author

You are right and this issue is discarded, I'm sorry.
But I couldn't find the try catch blocks in my code that prevent to appear
this exception. All of them content has this
command:"MessageBox.Show(ex.Message);".

Original comment by [email protected] on 13 Aug 2015 at 1:29

@GoogleCodeExporter
Copy link
Author

​________________________________________________________
​​
                if ( ( maskImage != null ) && ( maskImage.PixelFormat !=
PixelFormat.Format8bppIndexed ) )
                {
                    throw new ArgumentException( "The mask image must be 8
bpp grayscale image." );
                }

                *maskImage **= value;*
                unmanagedMaskImage = null;
                mask = null;
​ _________________________________________________________​
I found it!!!! ​Bug is exist!
​Check is before set value!​

​


​

On Thu, Aug 13, 2015 at 5:59 PM, Hashem Zavvari <[email protected]>
wrote:

Original comment by [email protected] on 13 Aug 2015 at 1:48

@GoogleCodeExporter
Copy link
Author

Yes, good spot. Somehow the silly bug has survived.

Original comment by [email protected] on 13 Aug 2015 at 1:51

  • Changed state: Accepted
  • Added labels: Project-Imaging

@github-staff github-staff deleted a comment from 1291945816 Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant