Convert BPG from PNG
-
- Posts: 12
- Joined: 2018-11-07T18:19:39-07:00
- Authentication code: 1152
Convert BPG from PNG
I am a new user of ImageMagick. I download and install the newest version ImageMagick-7.0.8-14-Q16-x64-dll on Windows. I try to convert a png file to bpg file.
The png file is 199KB but the converted bpg file is 255KB. No matter what quality I set, the size is huge and PSNR is Inf(seems lossless).
The command I use is
convert mountain.png -quality 10 test.bpg
I do use imdisplay to show the test.bpg. It looks OK and I measure the PSNR which is Inf.
Where I do this wrong? I think BPG is lossy compression and should perform like JPEG right?
The png file is 199KB but the converted bpg file is 255KB. No matter what quality I set, the size is huge and PSNR is Inf(seems lossless).
The command I use is
convert mountain.png -quality 10 test.bpg
I do use imdisplay to show the test.bpg. It looks OK and I measure the PSNR which is Inf.
Where I do this wrong? I think BPG is lossy compression and should perform like JPEG right?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert BPG from PNG
I am on a Mac and tried your command with the lena.png image, but am getting error messages with both IM 6.9.10.14 and 7.0.8.14. I am not sure if BPG is limited to Windows or not. The page at https://imagemagick.org/script/formats.php says nothing about OS limitations nor delegates. See this page about quality for BPG
No matter what quality I assign (10 or 92), it comes back with:
magick: delegate failed `'bpgenc' -b 12 -o '%o' '%i'' @ error/delegate.c/InvokeDelegate/1860.
magick: delegate failed `'bpgenc' -b 12 -o '%o' '%i'' @ error/delegate.c/InvokeDelegate/1860.
Looks like I would need to install the libbpg delegate.
No matter what quality I assign (10 or 92), it comes back with:
Code: Select all
magick lena.png -quality 92 lena.bpg
Code: Select all
magick lena.png -quality 10 lena.bpg
Looks like I would need to install the libbpg delegate.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert BPG from PNG
OK, I installed libbpg. The lena.png image has file size of Filesize: 118327B
I ran the command
And the bpg file has file size 322131B. So the result is about 3 time the size of the original.
The verbose information shows the same bpg command no matter what -quality value
It does not seem to be using the -q qp argument as shown at https://bellard.org/bpg/lena.html
bpgenc
BPG Image Encoder version 0.9.8
usage: bpgenc [options] infile.[jpg|png]
Main options:
-h show the full help (including the advanced options)
-o outfile set output filename (default = out.bpg)
-q qp set quantizer parameter (smaller gives better quality,
range: 0-51, default = 29)
-f cfmt set the preferred chroma format (420, 422, 444,
default=420)
-c color_space set the preferred color space (ycbcr, rgb, ycgco,
ycbcr_bt709, ycbcr_bt2020, default=ycbcr)
-b bit_depth set the bit depth (8 to 12, default =8)
-lossless enable lossless mode
-e encoder select the HEVC encoder (jctvc, default = jctvc)
-m level select the compression level (1=fast, 9=slow, default =8)
Animation options:
-a generate animations from a sequence of images. Use %d or
%Nd (N = number of digits) in the filename to specify the
image index, starting from 0 or 1.
-fps N set the frame rate (default = 25)
-loop N set the number of times the animation is played. 0 means
infinite (default = 0)
-delayfile file text file containing one number per image giving the
display delay per image in centiseconds.
Since smaller -q gives better quality, then the largest value should give the most compression and least quality. So when I do
The file size is still 322131B
Sorry, I know little about bpg. But this looks like a bug in ImageMagick in not passing the -quality argument to libbpg.
I ran the command
Code: Select all
magick -verbose lena.png -quality 10 lena.bpg
The verbose information shows the same bpg command no matter what -quality value
Code: Select all
bpgenc' -b 12 -o '/tmp/magick-26410khRDz3mnZsMF' '/tmp/magick-26410rNEMHSIvxtDw
bpgenc
BPG Image Encoder version 0.9.8
usage: bpgenc [options] infile.[jpg|png]
Main options:
-h show the full help (including the advanced options)
-o outfile set output filename (default = out.bpg)
-q qp set quantizer parameter (smaller gives better quality,
range: 0-51, default = 29)
-f cfmt set the preferred chroma format (420, 422, 444,
default=420)
-c color_space set the preferred color space (ycbcr, rgb, ycgco,
ycbcr_bt709, ycbcr_bt2020, default=ycbcr)
-b bit_depth set the bit depth (8 to 12, default =8)
-lossless enable lossless mode
-e encoder select the HEVC encoder (jctvc, default = jctvc)
-m level select the compression level (1=fast, 9=slow, default =8)
Animation options:
-a generate animations from a sequence of images. Use %d or
%Nd (N = number of digits) in the filename to specify the
image index, starting from 0 or 1.
-fps N set the frame rate (default = 25)
-loop N set the number of times the animation is played. 0 means
infinite (default = 0)
-delayfile file text file containing one number per image giving the
display delay per image in centiseconds.
Since smaller -q gives better quality, then the largest value should give the most compression and least quality. So when I do
Code: Select all
magick lena.png -quality 51 lena.bmp
Sorry, I know little about bpg. But this looks like a bug in ImageMagick in not passing the -quality argument to libbpg.
-
- Posts: 12
- Joined: 2018-11-07T18:19:39-07:00
- Authentication code: 1152
Re: Convert BPG from PNG
So what I should do now? Report issue at GitHub and use native or other BPG converter?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert BPG from PNG
Yes, report the bug at GitHub or here on the Bug's forum.dem123456789 wrote: ↑2018-11-07T22:37:56-07:00 So what I should do now? Report issue at GitHub and use native or other BPG converter?
I looked into the delegates.xml file for the bpg entry, which follows. But it is only the decode entry.
Code: Select all
<delegate decode="bpg" command=""bpgdec" -b 16 -o "%o.png" "%i"; /bin/mv "%o.png" "%o""/>
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert BPG from PNG
I tried adding this line to the delegates.xml file, since there was only a decode and not an encode entry for bpg:
I tried both -q 50 and -q 10, but still get the same file size as when this entry was not included.
Code: Select all
<delegate encode="bpg" command=""bpgenc" -b 8 -q 50 -o "%o.png" "%i"; /bin/mv "%o.png" "%o""/>
-
- Posts: 12
- Joined: 2018-11-07T18:19:39-07:00
- Authentication code: 1152
Re: Convert BPG from PNG
I open an issue here https://github.com/ImageMagick/ImageMagick/issues/1378
I guess I need to use other implementations for now.
I guess I need to use other implementations for now.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert BPG from PNG
You can just use the bpgenc command itself directly without Imagemagick. I tried it and it does work. Use "bpgenc" at the terminal to get the help information.
-
- Posts: 12
- Joined: 2018-11-07T18:19:39-07:00
- Authentication code: 1152
Re: Convert BPG from PNG
Got it Thank you.