Ask Your Question

Is it possible to resize images using resolution (dpi)?

asked 2018-06-18 03:23:31 -0500

Hichem gravatar image


I have some images which do not have the same width and height resolution (eg: width 200 dpi height 400 dpi). For some reasons I need to resize the image to have a square resolution by keeping one of the existing one that means the image should be either 200x200 dpi or 400x400 dpi in this case. I tried using the resize function the following way:

resize( inputImgMat, outImgMat, Size(0,0), 1, 0.5, INTER_LANCZOS4 )

but the resolution is reduced to be 96 dpi. Note that I tried all possible algorithms and each time the same result.

Is that possible using the resize function? is there any other function I can use?


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-06-18 03:27:27 -0500

berak gravatar image

updated 2018-06-18 03:31:15 -0500

dpi is only used in printing, not at all in computer-vision, where this is irrelevant.

imread() won't read this information, and imwrite() won't save it

( the 96 dpi you're seing in your image editor are a dummy value ).

so, in short - no it is not possible. you'll have to work with "pixels" as dimensions here, not dpi.

(maybe opencv is the wrong library for you ?)

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-06-18 03:23:31 -0500

Seen: 451 times

Last updated: Jun 18 '18