ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Saving as webp using ImageMagick is causing low quality/artifacting
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

EricNat

USA
37 Posts

Posted - Oct 19 2022 :  23:07:52  Show Profile  Reply
When I save an image using ImageMagick from ImageEnView, I am getting a very low quality image with lots of artifacting.

For example:

Image->IO->SaveToStream(s,iomscWEBP);

I am loading ImageMagick with the plugin:

IEGlobalSettings()->RegisterPlugIns();

The image seems to load into ImageEnView ok, but when saving it is using very low quality.

Any ideas?

Thanks,
Eric

xequte

38686 Posts

Posted - Oct 20 2022 :  04:20:34  Show Profile  Reply
Hi Eric

Try specifying the WebP properties

// Save a PNG file as a lossless WebP with maximum compression
ImageEnView1.IO.SaveToFile('D:\Image.png');
ImageEnView1.IO.Params.Dict.Insert( 'ImageMagick', TIEDictionary.Create() );
ImageEnView1.IO.Params.Dict.GetDictionary('ImageMagick').Insert( 'webp:lossless', True );
ImageEnView1.IO.Params.Dict.GetDictionary('ImageMagick').Insert( 'webp:method', 6 );
ImageEnView1.IO.SaveToFile('D:\Image_out.webp');


They are defined at:
- http://imagemagick.org/script/webp.php
- http://imagemagick.org/script/defines.php



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

EricNat

USA
37 Posts

Posted - Nov 01 2022 :  17:32:08  Show Profile  Reply
Unfortunately, I am still not having any progress with this after trying many different things.

One thing that is confusing is exactly how the dictionary entries are supposed to be defined. In a few places, they are defined like you have above. But in the Help files, it shows:

// Save a JPEG as WebP at 95% quality (using ImageMagick plug-in)
ImageEnView1.IO.LoadFromFile( 'D:\Image.jpg' );
ImageEnView1.IO.Params.Dict.Clear();
ImageEnView1.IO.Params.Dict.Insert( 'ImageMagick:Quality', 95 );
ImageEnView1.IO.SaveToFile( 'D:\Image_out.WebP' );


I have tried both ways, and neither seems to change the quality. Also, when I use the ImageMagick command line, the image looks good with the defaults (no parameters specified about quality, lossless, etc.). Shouldn't the plug in be using the same defaults?

Whenever I save from ImageEn as WEBP, it is degrading the quality substantially. Attached is an example. The first is the input and the second is what I'm getting on the save.

Any help would be greatly appreciated.

Thanks!
Eric

Go to Top of Page

EricNat

USA
37 Posts

Posted - Nov 01 2022 :  17:38:58  Show Profile  Reply
Here is the original webp file, if that is helpful at all.

attach/EricNat/2022111173848_wepbtest.zip
5.48 KB
Go to Top of Page

xequte

38686 Posts

Posted - Nov 01 2022 :  21:16:43  Show Profile  Reply
Hi Eric

We are only passing the specified params to ImageMagick, so we cannot be sure what effect they have other than by testing it.

From my testing setting 'ImageMagick:Quality' does not have any discernible effect with WebP (I will update the documentation)

You are better to use the WebP parameters:

    ImageEnView1.IO.LoadFromFile('D:\Alpha_2.png');
    ImageEnView1.IO.Params.SetDefaultParams();
    ImageEnView1.IO.Params.Dict.Insert( 'ImageMagick', TIEDictionary.Create() );
    ImageEnView1.IO.Params.Dict.GetDictionary('ImageMagick').Insert( 'webp:lossless', Lossless );
    ImageEnView1.IO.Params.Dict.GetDictionary('ImageMagick').Insert( 'webp:method', Method );
    ImageEnView1.IO.SaveToFile('D:\'+outFN+'.webp');


Lossless=False, Method=6:



Lossless=False, Method=1:



Lossless=True:




It seems that Lossless gives worse quality than lossy here because the source contains anti-aliased (partially transparent) pixels.

I'm not seeing the low quality result that you are. Ensure that you do not have an old version of the ImageEn ImageMagick plug-in and/or ImageEn library.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

xequte

38686 Posts

Posted - Nov 02 2022 :  20:18:00  Show Profile  Reply
Sorry, working with your original image (the source WebP) it looks like when loading the alpha channel is not supported for gray-scale WebP images like this. We will investigate.



Nigel
Xequte Software
www.imageen.com

Go to Top of Page

EricNat

USA
37 Posts

Posted - Nov 11 2022 :  13:06:49  Show Profile  Reply
Thanks Nigel. Yes, I realized that I thought it was happening when it was being saved but it turns out the issue is happening when the webp file is being opened in ImageEnView. Sorry I didn't realize that earlier. Please let me know what you find out. Thank you!
Go to Top of Page

EricNat

USA
37 Posts

Posted - Nov 21 2022 :  16:53:59  Show Profile  Reply
Hi, any update on this issue? Thanks!
Go to Top of Page

xequte

38686 Posts

Posted - Nov 21 2022 :  22:31:40  Show Profile  Reply
Hi Eric

Yes, this will be fixed in our upcoming v11.4.5 (released in the next week or so).

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

EricNat

USA
37 Posts

Posted - Nov 21 2022 :  22:34:19  Show Profile  Reply
Wonderful. Thank you!
Go to Top of Page

EricNat

USA
37 Posts

Posted - Dec 07 2022 :  01:26:33  Show Profile  Reply
Hi Nigel,

I've updated to the latest 11.4.5.

Now, when opening the above webp test image, it opens fine.

However, when I go to save it, it is not saving properly. I've attached what I'm getting as the output. I am doing:

Image->IO->LoadFromFile("webptest.webp");
Image->IO->SaveToFile("test.webp",iomscWEBP);


attach/EricNat/202212712157_test.zip
30.56 KB

I am registering ImageMagick at startup with RegisterPlugIns();

Any idea what is causing that?

Thanks.
Go to Top of Page

xequte

38686 Posts

Posted - Dec 07 2022 :  22:23:18  Show Profile  Reply
Hi Eric

I've added support for ie1g and alpha channel in the current beta. Please email me for it.



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

EricNat

USA
37 Posts

Posted - Sep 08 2023 :  18:26:27  Show Profile  Reply
Hi,

The latest versions are working properly when saving as WEBP format. However, we are still seeing artifacting when we open the WEBP image and then try to save it as a PNG. Is there some way around this or is this a bug?

Here is our code:

gImageMagickPath="\\webp test\\Win32\\Debug";
IEGlobalSettings()->RegisterPlugIns();
Image->IO->LoadFromFile("webptest.webp");
Image->IO->SaveToFile("test.webp",iomscWEBP);
Image->IO->SaveToFile("test.png",ioPNG);

Using the same image provided previously - the sheet icon with the letters PNG on it.

The test.webp looks great now. But when saved as PNG, it has the same artifacting that it had before.

Thank you,
Eric
Go to Top of Page

xequte

38686 Posts

Posted - Sep 10 2023 :  19:13:46  Show Profile  Reply
Hi Eric

PNG only supports alpha when 32bit (24bit+Alpha), so you need to increase the color depth:

  IEGlobalSettings().AutoSetBitDepth := True;

  ImageEnView1.IO.LoadFromFile( 'D:\wepbtest.webp' );
  ImageEnView1.IEBitmap.PixelFormat := ie24RGB;
  ImageEnView1.IO.SaveToFile( 'D:\wepbtest.png' );


Nigel
Xequte Software
www.imageen.com
Go to Top of Page

EricNat

USA
37 Posts

Posted - Sep 10 2023 :  22:51:58  Show Profile  Reply
That did it! Thanks so much.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: