How to write the same image format, compression and dpi of the image I read in [closed]
Hi,
I'm trying to read an uncompressed Tif, rotate it around a point that isn't the center of the image, crop it and write (ideally) to the same format, or at very least the same DPI. Rough code below.
I can get it to rotate and crop but on writing out the tif it results in a compressed format that messes with the next part of my script.
When I switched it to exporting a bmp or uncompressed png it seems ok, but the dpi is a 10th of the input and the dimensions are 10 times the size of the original image.
Initial image: 7.23inches, 9.15inches, 1200DPI
Output image: 76.38inches 97.3inches 111DPI
This creates a huge image that also screws up the next part of my script.
What do I do? I'm neither a python or OpenCv2 guru, so any help is appreciated with cv2 or if you have an alternative that also works. :) Happy Independence Day.
Cheers, Michael
image = cv2.imread(Path + str(inputline[0]) + ".tif")
#Use cv2.warpaffine to rotate
#Crop by taking image[y's, x's]
cv2.imwrite(Path + inputline[0] + ".tif", crop_img)
dpi information is irrelevant in computer-vision. what matters, is the number of pixels in the image.
(i guess, you were fooled by this, thinking your origiinal image was 10 times smaller than it is in reality)
opencv also won't read or write any metadata from images.
No not exactly. So the number of rows and columns does work out to be the same, but OpenCv drastically changes the pixel size... Maybe ultimately that's my question
So the original image has a pixel size of 0.0008, 0.0008, 8 bit, unsigned And the output pixel size is in one display 1,1
How do I enforce a specific output pixel size?
your "pixel size" is something entirely virtual, and again it does not matter in computer-vision, only in printing.
i'm quite sure, this is the wrong library for you.
sure, I understand rows and columns etc.
But I can't believe that someone hasn't wanted to write an image that would be a specific size, even if it was for printing.
For my own work training visual neural nets, managing DPI is essential--my training images come from different camera sources with varying resolution, so it's critical to resize (resample) images to a consistent DPI before training. It would be very convenient to read/write the PPI in image headers.
I understand if managing format-specific image metadata is outside the scope of OpenCV, but it's misleading to claim that DPI is irrelevant to computer vision.