Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to write the same image format, compression and dpi of the image I read in

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)

click to hide/show revision 2
No.2 Revision

updated 2017-07-04 23:58:49 -0600

berak gravatar image

How to write the same image format, compression and dpi of the image I read in

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

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 ".tif") #Use cv2.warpaffine to rotate

Crop rotate #Crop by taking image[y's, x's]

x's] cv2.imwrite(Path + inputline[0] + ".tif", crop_img)

crop_img)