OpenCV java reducing resolution of image [closed]

asked 2018-10-21 13:41:24 -0600

Pras gravatar image

Hi,

I did lots of search around opencv forums around how to maintain priginal resolution in image, some people suggested to use "CV_LOAD_IMAGE_UNCHANGED" flag while imread operation before writing it, some forum answers says use PNG compression while writing it, none of those help really and I get output image with reduced resolution always.

Basically in java program I am just reading a jpg image using imread and then immediately writing it to disk using imwrite, and I get image same image on disk with reduced resolution. After trying lots of combinations I am about to give up and switch to some other library which can be used to read image, and process it and then store it at same resolution. But before switching to some other library I wanted to give final try by asking for any answer from experts here.

My current sample JAVA code is -

File imageFile= new File("jpgfilefromdisk.jpg);//read source file from disk
Mat original = Imgcodecs.imread(imageFile.getAbsolutePath(), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
MatOfInt par = new MatOfInt(Imgcodecs.CV_IMWRITE_PNG_COMPRESSION, 3);
Imgcodecs.imwrite(new File("./outputdir").getAbsolutePath() + "/cvimage.jpg", mat, par);

When I read original image in photoshop, windows photo viewer etc, the original image is 300 dpi. But when I read same image which was written to disk from openCV (cvimage.jpg), I can see the dip is reduced to 75dpi by just reading and writing same file from opencv.

Appreciate comments from experts here.

Regards, Pras

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2018-10-21 18:26:26.224664

Comments

cvimage.jpg -> cvimage.png

sturkmen gravatar imagesturkmen ( 2018-10-21 14:27:07 -0600 )edit

tried that as well. It just creates image with .png extension locally with bigger size, but resolution still 72 dpi. Whereas original one has 300 dpi

Pras gravatar imagePras ( 2018-10-21 14:33:46 -0600 )edit

@Pras -- dpi is entirely useless here (it's only used in printing). opencv, being a computer-vision library does neither read nor write such information, so what you see in your image viewer program is all bogus (like it's always 72 when it can't find anything else).

again, there is no such thing as "resolution", it's a pure fictional value, describing: "if you want to print this image to paper make it such and such large"

berak gravatar imageberak ( 2018-10-21 17:51:46 -0600 )edit