This project has moved and is read-only. For the latest updates, please go here.

Issue with MagickImage.Negate()

Jul 25, 2014 at 9:20 AM
Can you please check if there's some memory allocation issue with .Negate() filter as I am having the following problem.

I load an image into MagickImage. I have 2 Picturebox - one always showing the original image, the 2nd showing altered image after filters. For speed concerns I simply clone the Original image to a Processed image, don't load the image again from the file.

After applying a .Negate() the Original image gets changed just like the Processed one. This happens only with Negate filter, many other filters I used work just fine. Also this doesn't happen if I don't clone the Original to the Processed image, but load the Processed image from the file again..

I don't know if this is issue with Negate filter, or I am doing something wrong...

Here's my code:
Class MyClass

Private OriginalImage As MagickImage
Private ProcessedImage As MagickImage

Private Sub Test()
        'load the original image
        OriginalImage = New MagickImage("image.jpg")

        ' display the original image
        PictureBox_Original_Image.Image = OriginalImage.ToBitmap
        
        ' clone the original image to the processed one
        ProcessedImage = OriginalImage.Clone
       
        ' do some filters
        ProcessedImage.Negate()

        ' show the processed image after the filters
        PictureBox_Trainer_Processed_Image.Image = ProcessedImage.ToBitmap

        ' redisplay the original again to show there's problem with the .Negate filter
        PictureBox_Trainer_Original_Image.Image = OriginalImage.ToBitmap
End Sub

End Class
Thanks in advance for your help!
Jul 25, 2014 at 9:37 AM
Edited Jul 25, 2014 at 10:08 AM
In addition wanted to say that the Negate filter actually works really slow.. I am trying it on 300x50 image and there's notable lag..

Just found that and for .Equalize() filter it happens the problem just like .Negate()
Jul 25, 2014 at 11:12 AM
Can you also try Composite?
Jul 25, 2014 at 11:27 AM
dlemstra wrote:
Can you also try Composite?
Composite seems to work fine
Jul 25, 2014 at 11:32 AM
Edited Jul 25, 2014 at 8:09 PM
Okay thanks, I will investigate this tonight / this weekend.

Edit: This seems to be related to OpenCL. Disabling it resolves the problem and also improves the performance. Not sure why this is happening yet but I will look into it.
Jul 28, 2014 at 9:20 PM
The OpenCL bug has been fixed. I am still investigating the performance issue.
Jul 29, 2014 at 8:24 AM
Great! Thank You for taking your time into fixing this!

Best of luck with the performance issue as well
Aug 1, 2014 at 9:28 PM
I have published the new release but I was unable to pin point the performance issue at this moment. We are still investigating it but I would suggest you disable OpenCL for now when you use the Negate method.
Aug 2, 2014 at 6:11 AM
Edited Aug 2, 2014 at 6:30 AM
dlemstra wrote:
I have published the new release but I was unable to pin point the performance issue at this moment. We are still investigating it but I would suggest you disable OpenCL for now when you use the Negate method.
Can you please let me know how to disable OpenCL? I am using the Magick.NET-6.8.9.601-Q8-AnyCPU-net40-client.zip package..

EDIT: ok, I found how to disable it. Like this:
ImageMagick.MagickNET.UseOpenCL = False


Meanwhile you were working on this, I found that this performance issue exists for more filters like .Blur , .Equalize , maybe more.. what is interesting is that when i first load my app and click the button to apply any of these problemable filters it does the lag, but when i re-apply the filter (do it several times) from the 2nd time there's no lag. Hope you understand what I mean.. Hope that helps you locate the source of the issue

EDIT: When I disabled the opencl there's no performance issue for any of the filters. Looks like the problem is in opencl as you say.

Thanks!
Aug 2, 2014 at 9:25 AM
Can you contact me through CodePlex? You disabled the 'contact' option in your profile. I would like to talk about your specific situation a bit more. And if we use the board it is going to be a bit spammy.
Aug 2, 2014 at 9:36 AM
dlemstra wrote:
Can you contact me through CodePlex? You disabled the 'contact' option in your profile. I would like to talk about your specific situation a bit more. And if we use the board it is going to be a bit spammy.
Sure, i just enabled contacts and contacted you..

Thanks!
Aug 28, 2014 at 9:15 PM
The performance issue will be fixed in the next release of Magick.NET (7.0.0.0003). I don't have an ETA for the next release.
Aug 28, 2014 at 9:18 PM
dlemstra wrote:
The performance issue will be fixed in the next release of Magick.NET (7.0.0.0003). I don't have an ETA for the next release.
With OpenCL enabled? That would be great, thanks man!
Aug 28, 2014 at 9:40 PM
Edited Aug 28, 2014 at 9:41 PM
Yup. The OpenCL negate method has been removed. The CPU could always perform this action faster. You can safely enable OpenCL in the next release.
Aug 28, 2014 at 9:44 PM
dlemstra wrote:
Yup. The OpenCL negate method has been removed. The CPU could always perform this action faster. You can safely enable OpenCL in the next release.
OK, great!

I will wait for the new version and then enable OpenCL and play with the filters and will keep you posted if i see something again..

btw I was doing more than fine without OpenCL so far :)

Thanks!