Ask Your Question
1

png compression

asked May 2 '13

keltik gravatar image

updated May 2 '13

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 ?

Preview: (hide)

3 answers

Sort by » oldest newest most voted
1

answered May 2 '13

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.

Preview: (hide)

Comments

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

keltik gravatar imagekeltik (May 2 '13)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 (May 2 '13)edit
2

answered May 2 '13

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

Preview: (hide)

Comments

yep i found it out

keltik gravatar imagekeltik (May 2 '13)edit
0

answered May 2 '13

NightLife gravatar image

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

Preview: (hide)

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 (May 2 '13)edit

@keltik how did you resolve this issue

snsinha gravatar imagesnsinha (Jun 30 '0)edit

Question Tools

2 followers

Stats

Asked: May 2 '13

Seen: 7,246 times

Last updated: May 02 '13