Ask Your Question
1

png compression

asked 2013-05-01 23:50:07 -0600

keltik gravatar image

updated 2013-05-02 01:45:36 -0600

Why does the png-file-size increase? Here is the code (in Java):

Mat m = Highgui.imread("C:/img1.png");
Highgui.imwrite("C:/img1out.png", m);

Initially the "img1.png"-file is 900kb, but "img1out.png" becomes 2200kb! I have read that the compression in openCV is not as good as in other image-processing API's, but recently some compression has been added.

I tried out to do this here:

Mat m = Highgui.imread("C:/img1.png");
MatOfInt mPngCompressionRate = new MatOfInt(9);
Highgui.imwrite("C:/img1out.png", m, mPngCompressionRate);

But the size still goes up to 2200kb of "img1out.png". What am i doing wrong here ?

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
1

answered 2013-05-02 02:01:04 -0600

As seen on the imwrite documentation you should assign a compression rate as parameter. In C++ this are basic integer values between 0-9, where 3 is standard compression rate.

edit flag offensive delete link more

Comments

totally forgot about those pages, i hope they will help, i am going to post the result here, thank you

keltik gravatar imagekeltik ( 2013-05-02 02:29:18 -0600 )edit
1

Actually i had to instantiate the "compression-vector" like this "MatOfInt mPngCompressionRate = new MatOfInt(Highgui.CV_IMWRITE_PNG_COMPRESSION,0);" gives 5000kb and "MatOfInt mPngCompressionRate = new MatOfInt(Highgui.CV_IMWRITE_PNG_COMPRESSION,9); gives 2000kb". (poor javadoc)

keltik gravatar imagekeltik ( 2013-05-02 02:35:37 -0600 )edit
2

answered 2013-05-02 02:35:53 -0600

berak gravatar image

bear with me for not knowing the java wrappers too well,

but your MatOfInt mPngCompressionRate should hold 2 elements, (not one only) :

CV_IMWRITE_PNG_COMPRESSION, 9

edit flag offensive delete link more

Comments

yep i found it out

keltik gravatar imagekeltik ( 2013-05-02 05:12:28 -0600 )edit
0

answered 2013-05-02 00:21:36 -0600

NightLife gravatar image

The problem should be compression rate. Try to change it and check the results.

edit flag offensive delete link more

Comments

I did the following: "MatOfInt mPngCompressionRate = new MatOfInt(0);", but still "img1out.png" has 2200kb size. The java API does not have much Documentation on "MatOfInt" and its usage with compression parameter of "imwrite(java.lang.String filename,Mat img,MatOfInt params))". Could someone help me?

keltik gravatar imagekeltik ( 2013-05-02 01:41:38 -0600 )edit

@keltik how did you resolve this issue

snsinha gravatar imagesnsinha ( 2020-06-30 04:08:31 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2013-05-01 23:50:07 -0600

Seen: 6,709 times

Last updated: May 02 '13