Ask Your Question
-1

how to resize image without changing dpi ?

asked 2020-01-03 06:53:09 -0600

hi i resized the image and it change the dpi of the image from 300 dpi to 90 dpi . What is the correct way to resize image without changing its dpi in ocpencv . if we feed the 90 dpi image into OCR it barley recognizes any text in the image .

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2020-01-03 09:13:49 -0600

berak gravatar image

updated 2020-01-03 09:17:00 -0600

opencv does not deal at all with dpi, which is irrelevant in computer-vision and only needed for printing out things.

imread() will discard all meta information, and imwrite() won't write any dpi values.

the value of 90 you see (where ?) in your imageviewer is plain bogus / default (because there never was anything)

and again, neither ocr nor cnns care about dpi, only about pixels and image size.

edit flag offensive delete link more

Comments

The value 90 i see it in image properties by right clicking the image ->properties->Details->Horizontal resolution . how to maintain the pixel value consistent in the resized image ? the pixel value too decreases after resizing making the text in the images bit distorted how to avoid this ?

ajopencv gravatar imageajopencv ( 2020-01-08 00:38:10 -0600 )edit
0

answered 2020-01-03 07:38:22 -0600

mvuori gravatar image

Four things: 1 When you shoot an object, the photo will have a virtual DPI - or actually PPI - related to that object. When you resize the photo that value necessarily changes. 2 OCR doesn't care about DPI. It only cares about having sufficient number of pixels to represent the letter, "Pixels Per Letterform", that changes when you resize the photo. 3 DPI values that any application writes to values are arbitrary and symbolic. They have (almost always) no relevance in image processing. Only pixels count. 4 So, if you don't have enough pixels after resizing, you must not resize.

edit flag offensive delete link more

Comments

so how do we resize the image in opencv such that the Pixels Per Letterform is not affected ? where can we see this value of Pixels Per Letterform ? im not able to understand the 4th point , resizing the image is the most common task in text detection and OCR how can we work without resizing ?

ajopencv gravatar imageajopencv ( 2020-01-03 08:00:42 -0600 )edit

What size of image? Why do you wanted to do in OpenCV?

supra56 gravatar imagesupra56 ( 2020-01-03 08:15:51 -0600 )edit
1

im going to resize the image in opencv so that i can CNN on this resized image to detect text features .You cannot run it on the orginal image size as CNN used stride to check every region in image , so we need to resize it and it will give the text coordinates which i will pass to ocr to crop and get text . the problem is when i resize the image text is very hard to recognize when compared to the original image .

ajopencv gravatar imageajopencv ( 2020-01-03 08:39:34 -0600 )edit

@ajopencv. Ok. I do understand. So you're saving image from printer(depending size) Here is snippet:

img = cv2.imread('image.jpg')
img_resize(img, (90, 90)) <== Do whatever size you're wanted
supra56 gravatar imagesupra56 ( 2020-01-03 09:28:48 -0600 )edit

The value 90 i see it in image properties by right clicking the image ->properties->Details->Horizontal resolution . how to maintain the pixel value consistent in the resized image ? the pixel value too decreases after resizing making the text in the images bit distorted how to avoid this ?

ajopencv gravatar imageajopencv ( 2020-01-08 00:39:00 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2020-01-03 06:53:09 -0600

Seen: 3,992 times

Last updated: Jan 03 '20