I'm in the process of moving some of my code off of openzoom.py and onto Libvips but am not sure how dictate the interpolation method, which is important. I at the very least need to be able to use bicubic/bilinear in one case and nearest neighbors in the other case.
My old code is as follows:
creator = deepzoom.ImageCreator(tile_size=128, tile_overlap=2, tile_format="png",
image_quality=0.8, resize_filter="nearest")
creator.create(sourceFile, destFile)
Currently, using pyvips I have the following
image = pyvips.Image.new_from_file(sourceFile)
image.dzsave(destFile, tile_size=128, overlap=2,
suffix='.png[Q=80]')
Any help would be greatly appreciated :)
By default, dzsave will average each 2x2 block of pixels, which is equivalent to bilinear.
Sometimes, for example with images where pixel values represent labels rather than intensity, you need a non-interpolatory downsize. For these cases, you can use the
region_shrinkparameter to selectmedianormode, which will both preserve label values.I would use:
Don't forget to set the
accesshint. It'll give you a huge improvement in speed and memory behaviour for large images that don't support random access.The PNG Q number sets quantization quality when outputting palettized images. Perhaps you mean
compression? libvips defaults to 6, the PNG standard.Are you sure you want
overlap=2? The deepzoom standard is overlap 1. Overlap 1 means there is one pixel extra around the edge of every tile, so tiles in the centre of the image will share two pixels on every edge with their neighbours. Settingoverlap=2means you'll have four pixel overlaps, confusingly.Likewise,
tile_size=128means most of your tiles will be 132x132 pixels. It doesn't matter for PNG, but JPG works best with multiples of 8 on an axis. I would settile_sizeto (128 - 2 * overlap), as deepzoom does by default.git master libvips adds
max,minandnearest(always pick the top-left pixel) as well. A branch haslanczos3, but it was never merged for various reasons.