Ask Your Question
2

COMPRESSION algo not helpful in PNG cases?

asked 2020-06-30 01:47:40 -0500

snsinha gravatar image

updated 2020-06-30 03:26:54 -0500

supra56 gravatar image

I m trying to compress the PNG images , and have tried to use different COMPRESSION algorithm , but the image file size remains the same. The image I m using is https://upload.wikimedia.org/wikipedi...

  • Before resize length 1966656
  • After resize length IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY - 6355730
  • After resize length IMWRITE_PNG_STRATEGY_FILTERED - 6355730
  • After resize length IMWRITE_PNG_STRATEGY_FIXED 6355730
  • After resize length IMWRITE_PNG_STRATEGY_RLE 6355730

The resizing(decreasing the dimension) is increasing the size of the image after the first log.

resizeByThird(sourceImage: Path, destinationImage: Path) {
        val sourceImageMat = imread(sourceImage.toString())
        val resizedImage = Mat()
        resize(sourceImageMat, resizedImage, Size(3840, 2208))
        println(sourceImage.toFile().length())
        val params: IntArray = intArrayOf(IMWRITE_PNG_STRATEGY_HUFFMAN_ONLY)
        imwrite(destinationImage.toString(), resizedImage, params)
        println(destinationImage.toFile().length())
    }
edit retag flag offensive close merge delete

Comments

please show the resizing code, so ppl can try to reproduce

berak gravatar imageberak ( 2020-06-30 02:23:07 -0500 )edit
2

yes . have added that now

snsinha gravatar imagesnsinha ( 2020-06-30 02:41:02 -0500 )edit

@berak if you can look at this and help me

snsinha gravatar imagesnsinha ( 2020-06-30 03:06:22 -0500 )edit
1

and which eso language would that be ?

and what does destinationImage.toFile().length() do ?

and what is the original image size(dimension) ?

berak gravatar imageberak ( 2020-06-30 03:14:30 -0500 )edit
1

its java and destinationImage.toFile().length() prints the size of the image file

snsinha gravatar imagesnsinha ( 2020-06-30 03:15:51 -0500 )edit

@berak what I have noticed is that -if I use resize to just one third of the original dimension , its size decreases ,but when I use 3840 * 2208 ,it increases. original size is 4000 * 2300

snsinha gravatar imagesnsinha ( 2020-06-30 03:17:51 -0500 )edit

Why are you using format toString?

supra56 gravatar imagesupra56 ( 2020-06-30 03:35:49 -0500 )edit
2

@supra56 that should not cause the issue.I checked it using the debugger ,its picking that correctly.

snsinha gravatar imagesnsinha ( 2020-06-30 03:49:09 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2020-06-30 09:24:33 -0500

updated 2020-06-30 10:21:51 -0500

seems you are right. you can create an issue about this problem

TEST CODE

#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <string>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{
    Mat mat = imread("Astro_4D_stars_proper_radial_g_b_8mag_big.png");

    vector<int> compression_params;
    compression_params.push_back(IMWRITE_PNG_COMPRESSION);
    compression_params.push_back(0);
    compression_params.push_back(IMWRITE_PNG_STRATEGY);
    compression_params.push_back(IMWRITE_PNG_STRATEGY_DEFAULT);
    for (int i = 0; i < 10; i++)
        for (int j = 0; j < 5; j++)
        {
            compression_params[1] = i;
            compression_params[3] = j;
            imwrite(format("PNG_STRATEGY_%d_PNG_COMPRESSION_%d.png", j, i), mat, compression_params);
        }
    imwrite("PNG_SAVED_DEFAULT.png", mat);
    return 0;
}

here is the result sizes

Astro_4D_stars_proper_radial_g_b_8mag_big.png   1.966.656
PNG_SAVED_DEFAULT.png   3.245.449
PNG_STRATEGY_0_PNG_COMPRESSION_0.png    27.647.001
PNG_STRATEGY_0_PNG_COMPRESSION_1.png    3.157.900
PNG_STRATEGY_0_PNG_COMPRESSION_2.png    3.039.178
PNG_STRATEGY_0_PNG_COMPRESSION_3.png    2.904.732
PNG_STRATEGY_0_PNG_COMPRESSION_4.png    2.637.388
PNG_STRATEGY_0_PNG_COMPRESSION_5.png    2.582.198
PNG_STRATEGY_0_PNG_COMPRESSION_6.png    2.529.017
PNG_STRATEGY_0_PNG_COMPRESSION_7.png    2.523.274
PNG_STRATEGY_0_PNG_COMPRESSION_8.png    2.503.723
PNG_STRATEGY_0_PNG_COMPRESSION_9.png    2.477.291
PNG_STRATEGY_1_PNG_COMPRESSION_0.png    27.647.001
PNG_STRATEGY_1_PNG_COMPRESSION_1.png    3.157.900
PNG_STRATEGY_1_PNG_COMPRESSION_2.png    3.039.178
PNG_STRATEGY_1_PNG_COMPRESSION_3.png    2.904.732
PNG_STRATEGY_1_PNG_COMPRESSION_4.png    2.603.165
PNG_STRATEGY_1_PNG_COMPRESSION_5.png    2.566.294
PNG_STRATEGY_1_PNG_COMPRESSION_6.png    2.519.976
PNG_STRATEGY_1_PNG_COMPRESSION_7.png    2.515.584
PNG_STRATEGY_1_PNG_COMPRESSION_8.png    2.498.000
PNG_STRATEGY_1_PNG_COMPRESSION_9.png    2.475.941
PNG_STRATEGY_2_PNG_COMPRESSION_0.png    27.647.001
PNG_STRATEGY_2_PNG_COMPRESSION_1.png    5.175.597
PNG_STRATEGY_2_PNG_COMPRESSION_2.png    5.175.597
PNG_STRATEGY_2_PNG_COMPRESSION_3.png    5.175.597
PNG_STRATEGY_2_PNG_COMPRESSION_4.png    5.175.597
PNG_STRATEGY_2_PNG_COMPRESSION_5.png    5.175.597
PNG_STRATEGY_2_PNG_COMPRESSION_6.png    5.175.597
PNG_STRATEGY_2_PNG_COMPRESSION_7.png    5.175.597
PNG_STRATEGY_2_PNG_COMPRESSION_8.png    5.175.597
PNG_STRATEGY_2_PNG_COMPRESSION_9.png    5.175.597
PNG_STRATEGY_3_PNG_COMPRESSION_0.png    27.647.001
PNG_STRATEGY_3_PNG_COMPRESSION_1.png    2.762.428
PNG_STRATEGY_3_PNG_COMPRESSION_2.png    2.762.428
PNG_STRATEGY_3_PNG_COMPRESSION_3.png    2.762.428
PNG_STRATEGY_3_PNG_COMPRESSION_4.png    2.762.428
PNG_STRATEGY_3_PNG_COMPRESSION_5.png    2.762.428
PNG_STRATEGY_3_PNG_COMPRESSION_6.png    2.762.428
PNG_STRATEGY_3_PNG_COMPRESSION_7.png    2.762.428
PNG_STRATEGY_3_PNG_COMPRESSION_8.png    2.762.428
PNG_STRATEGY_3_PNG_COMPRESSION_9.png    2.762.428
PNG_STRATEGY_4_PNG_COMPRESSION_0.png    27.647.001
PNG_STRATEGY_4_PNG_COMPRESSION_1.png    3.642.295
PNG_STRATEGY_4_PNG_COMPRESSION_2.png    3.492.898
PNG_STRATEGY_4_PNG_COMPRESSION_3.png    3.347.030
PNG_STRATEGY_4_PNG_COMPRESSION_4.png    3.058.305
PNG_STRATEGY_4_PNG_COMPRESSION_5.png    2.988.217
PNG_STRATEGY_4_PNG_COMPRESSION_6.png    2.915.866
PNG_STRATEGY_4_PNG_COMPRESSION_7.png    2.904.503
PNG_STRATEGY_4_PNG_COMPRESSION_8.png    2.876.399
PNG_STRATEGY_4_PNG_COMPRESSION_9.png    2.849.642

EDIT: i tested both images (original and saved by OpenCV) in https://compress-or-die.com/analyze

only difference : original image's ColorType is Palette and OpenCV's is RGB

i think the original image has only different tones of yellow and this is the reason for lesser size

image description

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2020-06-30 01:47:40 -0500

Seen: 50 times

Last updated: Jun 30