def testNewAndWriteCrop(): imagePath = datastore.fetch('sample_image.ptif') source = large_image.open(imagePath) out = large_image_source_vips.new() assert out.crop is None out.crop = 10, 10, 2000, 2000 assert out.crop is not None out.crop = None assert out.crop is None with pytest.raises(TileSourceError): out.crop = -1, -1, -1, -1 out.crop = 10, 10, 2000, 2000 for tile in source.tileIterator( format=large_image.constants.TILE_FORMAT_NUMPY, region=dict(right=4000, bottom=2000), ): out.addTile(tile['tile'], x=tile['x'], y=tile['y']) tmpdir = tempfile.mkdtemp() outputPath = os.path.join(tmpdir, 'temp.tiff') try: out.write(outputPath) result = large_image.open(outputPath) resultMetadata = result.getMetadata() assert resultMetadata['sizeX'] == 2000 assert resultMetadata['sizeY'] == 1990 finally: shutil.rmtree(tmpdir)
def testNewAndWrite(): imagePath = datastore.fetch('sample_image.ptif') source = large_image.open(imagePath) out = large_image_source_vips.new() for tile in source.tileIterator( format=large_image.constants.TILE_FORMAT_NUMPY, region=dict(right=4000, bottom=2000), ): out.addTile(tile['tile'], x=tile['x'], y=tile['y']) assert out.bandFormat == pyvips.enums.BandFormat.UCHAR assert out.bandRanges['min'][0] > 10 assert out.mm_x is None assert out.mm_y is None out.mm_x = source.getNativeMagnification()['mm_x'] out.mm_y = source.getNativeMagnification()['mm_y'] assert out.mm_x == 0.00025 assert out.mm_y == 0.00025 tmpdir = tempfile.mkdtemp() outputPath = os.path.join(tmpdir, 'temp.tiff') try: out.write(outputPath) assert os.path.getsize(outputPath) > 50000 result = large_image.open(outputPath) resultMetadata = result.getMetadata() assert resultMetadata['sizeX'] == 4000 finally: shutil.rmtree(tmpdir)
def testNewAndWriteLossless(): imagePath = datastore.fetch('sample_image.ptif') source = large_image.open(imagePath) out = large_image_source_vips.new() for tile in source.tileIterator( format=large_image.constants.TILE_FORMAT_NUMPY, region=dict(right=4000, bottom=2000), ): out.addTile(tile['tile'], x=tile['x'], y=tile['y']) tmpdir = tempfile.mkdtemp() outputPath = os.path.join(tmpdir, 'temp.tiff') try: out.write(outputPath, lossy=False) assert os.path.getsize(outputPath) > 50000 result = large_image.open(outputPath) resultMetadata = result.getMetadata() assert resultMetadata['sizeX'] == 4000 finally: shutil.rmtree(tmpdir)