This project has moved. For the latest updates, please go here.

first resize command slow

Oct 24, 2016 at 11:39 AM
Edited Oct 24, 2016 at 10:19 PM
Hi
I have a speed problem and I was following a post in which I found the exact problem that another user faced ( https://magick.codeplex.com/discussions/657120 ): I have to resize hundred of images and the first one (the first after the program starts each time) takes 6-8 seconds against the 1-2 second for any other one.

The solution given to the user is to set:
OpenCL.IsEnabled = false
I don't think this is a solution to my problem because the elaboration performance drops dramatically, taking 10 or more times.
Here is my ImagemagickOpenCLDeviceProfile.xml:
<devices>
<device name="CPU" score="28.35"/>
<device platform="Intel(R) OpenCL" vendor="Intel(R) Corporation" name="Intel(R) HD Graphics 4400" version="20.19.15.4444" maxClockFrequency="1000" maxComputeUnits="20" score="0.6067"/>
<device platform="Intel(R) OpenCL" vendor="Intel(R) Corporation" name="Intel(R) Core(TM) i3-4010U CPU @ 1.70GHz" version="5.2.0.10094" maxClockFrequency="1700" maxComputeUnits="4" score="2.261"/>
</devices>

Furthermore, I enabled trace logging on a file and I write you the lines where the time loss takes place:

24/10/2016 12.51.28 | 2016-10-24T12:51:28+02:00 0:02.926 2.328u 7.0.3 Trace MyApp.Win.vshost.exe[6056]: splay-tree.c/GetValueFromSplayTree/891/Trace
...
24/10/2016 12.51.28 | 2016-10-24T12:51:28+02:00 0:02.927 2.328u 7.0.3 Exception MyApp.Win.vshost.exe[6056]: blob.c/FileToBlob/992/Exception
unable to open file 'C:\Users\MyUser\AppData\Local\ImageMagick\magick_opencl_Intel(R)_HD_Graphics_4400_241a4c0f_32.bin': No such file or directory
24/10/2016 12.51.28 | 2016-10-24T12:51:28+02:00 0:02.928 2.328u 7.0.3 Trace MyApp.Win.vshost.exe[6056]: utility.c/GetPathComponent/1213/Trace
....\ImageMagick\MagickCore\blob.c
24/10/2016 12.51.32 | 2016-10-24T12:51:32+02:00 0:07.308 6.063u 7.0.3 Trace MyApp.Win.vshost.exe[6056]: image.c/CloneImage/812/Trace
C:\FOTO\BMW_40\EZ454YZ_1.JPG
24/10/2016 12.51.32 | 2016-10-24T12:51:32+02:00 0:07.334 6.063u 7.0.3 Trace MyApp.Win.vshost.exe[6056]: image.c/GetImageInfo/1343/Trace
...

I installed from nuGet the last version of MagicK.NET, the 8bit anycpu version

What could be the cause?
Thank you
Coordinator
Oct 24, 2016 at 8:26 PM
Which files do you have in the following folder: C:\Users\MyUser\AppData\Local\ImageMagick
Oct 24, 2016 at 10:28 PM
Hi
the only file in C:\Users\MyUser\AppData\Local\ImageMagick is "ImagemagickOpenCLDeviceProfile.xml" (whose content I copied in the post) and the file date has the installation date, some days ago.

If you notice, after the "No such file or directory" there is a gap of 4 seconds. Once the error is issued, the elaborations are fast until I restart the program.
Coordinator
Oct 26, 2016 at 9:07 AM
Your system is benchmarked in that gap. I will add some logging to ImageMagick to make this more visible. It looks like the compiled OpenCL kernel is not written to disk. If you are available to Skype sometime I can talk you through debugging this together with me to find why it fails. This will probably take us a few hours to set up your system and go through the debugger. Are you up for this and which timezone are you in?
Oct 26, 2016 at 11:03 AM
Ok I can spend some time for debugging. My timezone is GMT+1, so now it's 1PM
I can send you my skype by email
Coordinator
Oct 26, 2016 at 12:09 PM
I have contacted you through CodePlex so you can reply to me with you SkypeID.
Coordinator
Oct 27, 2016 at 9:05 PM
First of all thank you so much for letting me work on your machine to try and track down the issue. It appears that the compiled OpenCL kernel cannot be cached to disk. So the gap you are seeing is caused by the OpenCL kernel being compiled each time. I think I have a possible fix for this. I will contact you again when I have rewritten one of the functions so we can test it that works.
Coordinator
Oct 30, 2016 at 8:46 PM
Thanks for helping me fix this by giving me remote desktop access to your machine :) The bug has been resolved in Magick.NET 7.0.3.501
Oct 31, 2016 at 4:50 PM
You are welcome!
Oct 31, 2016 at 5:19 PM
hi I have a question about the transparency for watermarks: I have to place a watermark and since the user is asked to enter a value from 0% to 100% for transparency, where 0% is complete opaque and 100% is completely transparent, the user usually entered 75-85% values with a very old procedure. I checked the forum and so that the correct method is using "EvaluateOperator.Divide" in a ".Evaluate" method with "Channels.Alpha", so I did "watermark.Evaluate(Channels.Alpha, EvaluateOperator.Divide, dTransp)", but I had seriuos problema to calculare a linear range of values from 0 to 100 % using a divide operator... This causes the watermark to turn quickly from opaque to transparent for the first values entered, then slightly more and more transparent for the other dividers...

As seen on other posts, the "EvaluateOperator.Set" is not a valid solution because it fades all the image, regardless the alpha channel

Is there another way to put a linear transparency factor?
Coordinator
Nov 1, 2016 at 9:23 PM
Edited Nov 2, 2016 at 5:53 AM
I did some reading and testing with the stuff on this page: http://www.imagemagick.org/Usage/annotating/#watermarking. And it think this is what you want:
image.Composite(watermark, CompositeOperator.Dissolve, "15%");
Nov 2, 2016 at 9:52 AM
Great! exactly what I needed.

The last question: is there a method to add a string tag to the imagine? I'm asking that because when images are collected by web crowlers, the tags included in the image are used to index the image itself; an old graphic library offered this kind of possibility, so I'm wondering if I can find a similar feature in magick.net
Coordinator
Nov 2, 2016 at 5:02 PM
I am not sure what you are asking? You can store metadata in some image formats. Can you share an image that has this kind of metadata? You have my e-mail if you don't want to share it publicly.
Nov 2, 2016 at 6:00 PM
Ok I sent you an email with an example of tags correctly filled in
Coordinator
Nov 6, 2016 at 5:28 PM
Thanks for sending me the test files. The information is set through the exif profile and you can set it like this:
using (MagickImage image = new MagickImage("FA527JN_15_10520_GM.jpg"))
{
  ExifProfile profile = new ExifProfile();
  profile.SetValue(ExifTag.ImageDescription, "Magick.NET");

  image.AddProfile(profile);
  image.Write("\test.jpg");
}
This will only set the description of the image and not the ExifTag.XPKeywords. That one is not yet available in the Magick.NET library. I will try to add the missing tags next week. This means you will need to wait for the next release if the XPKeywords are important to you.
Nov 7, 2016 at 8:03 AM
Hi Dirk
the ImageDescription of ExifProfile is exactly what I need, infact just with that property set I can see in the resulting file image the same information I sent you by email as example, so I don't think that other tags would be necessary (to me)
Thank you for your help!
Maurizio