0

I tried to crop 16bits(float)/band TIFF image, but the resulting image is 8bits(byte)/band. Are there anything I should have done?

from vipsCC import *

input_file_path = 'input.tiff'
output_file_path = 'output.tiff'

bands = 4
bg = VImage.VImage.black(width,height,bands)
im = VImage.VImage(input_file_path) # Giving 16bits(float)/band TIFF image...

im_frag = im.extract_area(dx,dy,width,height)
bg.insertplace(im_frag,0,0)
bg.write(output_file_path) # Results 8bits(byte)/band ...
Izumi Kawashima
  • 1,197
  • 11
  • 25

1 Answers1

1

a.insertplace(b) does an in-place insert operation. It directly modifies a, pasting b into it. If b isn't the correct type, it's cast to match a.

You probably want plain insert. Try:

import sys
from vipsCC import *

im = VImage.VImage(sys.argv[1]) 
im_frag = im.extract_area(10, 10, 200, 200)

bg = VImage.VImage.black(1000, 1000, 1)
bg = bg.insert(im_frag, 100, 100)
bg.write(sys.argv[2])

a.insert(b) makes a new image which is big enough to hold all of a and b, so bands are added as required, the format is cast up, and so on. It's also a lot faster than insertplace and can handle images of any size.

You're also using the old vips7 Python interface. There's a new vips8 one now which is a bit nicer:

http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/using-from-python.html

There was a blog post a year or so ago introducing the new interface:

http://libvips.blogspot.co.uk/2014/10/image-annotation-with-pyvips8.html

jcupitt
  • 10,213
  • 2
  • 23
  • 39