size of recoverd image gets increased [closed]

asked 2018-06-23 03:46:26 -0500

vishalsira gravatar image

updated 2018-06-23 03:58:16 -0500

berak gravatar image

I am reading image from this method

        Mat originalImage = Highgui.imread(path);
        byte[] imageInByte = new byte[(int) (originalImage.total() * originalImage.channels())];
        originalImage.get(0, 0, imageInByte);

        TYPE = originalImage.type();
        HEIGHT = originalImage.height();
        WIDTH = originalImage.width();

while recovering image i'm using

    Mat mat = new Mat(HEIGHT, WIDTH , TYPE);
    mat.put(0, 0, bytesArrayForImage);
    String filename = Path;
    Highgui.imwrite(filename, mat);

by using these 2 methods i'm getting image of large size and the difference in between these 2 images which i'm getting is only bit depth i'm not getting how to resolve it

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2018-06-23 05:40:25.998313

Comments

which opencv version is it ?

can you edit it a bit, so the code compiles / can be reproduced ?

(i also cannot reproduce it, using 3.4.1 / 4.0.0)

berak gravatar imageberak ( 2018-06-23 04:05:19 -0500 )edit

i'm using 3.4.0 version of opencv

vishalsira gravatar imagevishalsira ( 2018-06-23 04:12:44 -0500 )edit

oh, wait, did you mean the size on disk ? (not W/H ?)

this entirely depends on file type and compression params passed to imwrite()

berak gravatar imageberak ( 2018-06-23 04:16:43 -0500 )edit

yes size on disk gets double and in properties of my file byte depths also gets increased by 3 times

vishalsira gravatar imagevishalsira ( 2018-06-23 04:19:24 -0500 )edit

bit depth of original image is 8 and reconstructed image's bit depth is 24

vishalsira gravatar imagevishalsira ( 2018-06-23 04:20:41 -0500 )edit

Highgui.imread(path); <-- this is from opencv2.4, not 3.4 and it will force reading in a 24bit image.

to read a grayscale one use

Highgui.imread(path, CV_LOAD_IMAGE_GRAYSCALE);

(if you're using outdated 2.4), for 3.x it would be:

Imgcodecs.imread(path, IMREAD_GRAYSCALE);
berak gravatar imageberak ( 2018-06-23 04:26:24 -0500 )edit

i'm using 3.4.0 version of opencv

please check again. it would be Imgcodecs, not Highgui, then.

berak gravatar imageberak ( 2018-06-23 04:28:24 -0500 )edit

It is Highgui, because when i'm tried with Imgcodecs it gives error

vishalsira gravatar imagevishalsira ( 2018-06-23 04:33:52 -0500 )edit

so it's 2.4, not 3.4.0.

however it will behave the same. if you want to read in a grayscale image, use the CV_LOAD_IMAGE_GRAYSCALE flag ( IMREAD_GRAYSCALE for 3.x)

berak gravatar imageberak ( 2018-06-23 04:57:55 -0500 )edit

its woring thanks

vishalsira gravatar imagevishalsira ( 2018-06-23 05:00:44 -0500 )edit