如何将dzi文件转换为多块金字塔tiff格式 [英] how to convert dzi files to multi-tile pyramidal tiff format

查看:343
本文介绍了如何将dzi文件转换为多块金字塔tiff格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

参考答案(如何转换dzi(深度缩放)文件转换为完整图像)

我是这个主题的菜鸟,如果我错了,请更正.

我正在尝试从.dzi(深度缩放图像)格式创建多平铺tiff,我的做法是:

(i)选择最高级别文件夹.

(ii)将m行的所有n列(m_n.jpeg,我指的是以这种格式保存的图像)垂直缝制为png图像.因此它们占据了相当大的空间.

(iii)最后,我使用pyvips.Image.write_to_file()将所有这些垂直png图像水平合并为一个完整的图像png.

(iv)最后使用vis im_save将完整的图像png转换为tiff.

我现在担心的是,此过程要花费将近2个小时才能制作出30,000 base_tiles的完整图像png,而且它的大小也超过了10 GB(完整图像png).

是否有更好,更快的方法将.dzi转换为tiff?

解决方案

libvips 具有<可以加入集合的href ="https://libvips.github.io/libvips/API/current/libvips-conversion.html#vips-arrayjoin" rel ="nofollow noreferrer"> arrayjoin 运算符瓷砖一起变成一个大图像.

您可以这样使用它(在linux命令行上):

vips arrayjoin "$(ls *.jpeg | sort -t_ -k2g -k1g)" x.tif[tile,pyramid,compression=jpeg] --across 20

这会将所有JPG图像加载到当前目录中,将它们组装成一个巨大的网格(跨20个图像),并作为TIFF金字塔写入.显然,您需要检查网格的大小,然后调整across参数.

$()部分按数字顺序先按y,然后按x对x_y.jpg格式的文件名进行排序.没有这些,瓷砖将被烦人地换位.

假定重叠为0.如果图块重叠,则需要设置hspacingvspacing选项以控制图块的放置方式.例如:

vips arrayjoin "$(ls *.jpg | sort -t_ -k2g -k1g)" x.tif --across 20 --hspacing 254 --vspacing 254

将水平和垂直每254个像素放置磁贴.

arrayjoin必须能够打开所有输入图像,因此它需要很多文件描述符.大多数Linux默认每个进程一次最多打开1024个文件,因此您可能需要提高该数目.通常,您只需要编辑几个配置文件,然后再次注销即可.我将系统设置为65536,但是您可以使用任何数字.

Windows的每个进程都严格限制有2000个文件,您不能更改.您需要在该平台上的各个部分中进行组装.

这是一个可行的示例.首先,创建一个没有重叠的Deepzoom金字塔:

john@kiwi:~/pics/x$ vips dzsave ~/pics/k2.jpg x --overlap 0
john@kiwi:~/pics/x$ cd x_files/11
john@kiwi:~/pics/x/x_files/11$ ls
0_0.jpeg  0_7.jpeg  1_5.jpeg  2_3.jpeg  3_1.jpeg  3_8.jpeg  4_6.jpeg  5_4.jpeg
0_1.jpeg  0_8.jpeg  1_6.jpeg  2_4.jpeg  3_2.jpeg  4_0.jpeg  4_7.jpeg  5_5.jpeg
0_2.jpeg  1_0.jpeg  1_7.jpeg  2_5.jpeg  3_3.jpeg  4_1.jpeg  4_8.jpeg  5_6.jpeg
0_3.jpeg  1_1.jpeg  1_8.jpeg  2_6.jpeg  3_4.jpeg  4_2.jpeg  5_0.jpeg  5_7.jpeg
0_4.jpeg  1_2.jpeg  2_0.jpeg  2_7.jpeg  3_5.jpeg  4_3.jpeg  5_1.jpeg  5_8.jpeg
0_5.jpeg  1_3.jpeg  2_1.jpeg  2_8.jpeg  3_6.jpeg  4_4.jpeg  5_2.jpeg
0_6.jpeg  1_4.jpeg  2_2.jpeg  3_0.jpeg  3_7.jpeg  4_5.jpeg  5_3.jpeg

您可以看到它是由6格和9格向下的瓦片组成的网格.

现在重新组装磁贴并写成TIFF金字塔:

john@kiwi:~/pics/x/x_files/11$ vips arrayjoin "$(ls *.jpeg | sort -t_ -k2g -k1g)" x.tif[tile,pyramid,compression=jpeg] --across 6
john@kiwi:~/pics/x/x_files/11$ vipsheader x.tif 
x.tif: 1524x2286 uchar, 3 bands, srgb, tiffload_stream

使用pyvips就像:

#!/usr/bin/env python3

import pyvips

tiles_across = 142
tiles_down = 150

tiles = [pyvips.Image.new_from_file(f"{x}_{y}.jpeg", access="sequential")
         for y in range(tiles_down) for x in range(tiles_across)]
im = pyvips.Image.arrayjoin(tiles, across=tiles_across)

im.write_to_file("x.jpg")

这花了大约10分钟和6gb的内存来连接这台笔记本电脑上的21,000张瓷砖.

In reference to the answer (how to convert dzi (deep zoom) files to full image)

I am a noob on this topic, please correct if I am wrong.

I am trying to create a multi-tiled tiff from .dzi (deep zoom image) format, how I am doing is:

(i) Pick the max level folder.

(ii) Vertically Stitch all the n columns of m rows (m_n.jpeg, I am referring to the images saved in this format) as png images. So they are occupying quite a considerable amount of space.

(iii) Finally, I horizontally merge all these vertical png images into a single full image png using pyvips.Image.write_to_file().

(iv) Finally using vips im_save, I convert the full image png to tiff.

My concern now is this process is taking almost 2 hours for it to make full image png for 30,000 base_tiles, and also it accounts to 10+ GB of size (Full Image png).

Is there any better and faster way to do the .dzi to tiff conversion?

解决方案

libvips has an arrayjoin operator that can join a set of tiles together into a large image.

You can use it like this (on the linux command-line):

vips arrayjoin "$(ls *.jpeg | sort -t_ -k2g -k1g)" x.tif[tile,pyramid,compression=jpeg] --across 20

That will load all the JPG image in the current directory, assemble them into a huge grid, 20 images across, and write as a TIFF pyramid. You'd need to check the size of your grid, obviously, and adjust the across parameter.

The $() part sorts the filenames of the form x_y.jpg by y first, then x, in numeric order. Without that, the tiles will be transposed, annoyingly.

That's assuming overlap 0. If your tiles have an overlap, you'll need to set the hspacing and vspacing options to control how tiles are positioned. For example:

vips arrayjoin "$(ls *.jpg | sort -t_ -k2g -k1g)" x.tif --across 20 --hspacing 254 --vspacing 254

Will position the tiles every 254 pixels horizontally and vertically.

arrayjoin has to be able to open all of the input images, so it needs a lot of file descriptors. Most linuxes default to a maximum of 1024 files open at once per process, so you'll probably need to raise that number. Usually you just edit a couple of config files and log out and in again. I set my system to 65536, but you can use any number.

Windows has a hard limit of 2000 files per process which you cannot change. You'll need to assemble in sections on that platform.

Here's a worked example. First, create a deepzoom pyramid with no overlaps:

john@kiwi:~/pics/x$ vips dzsave ~/pics/k2.jpg x --overlap 0
john@kiwi:~/pics/x$ cd x_files/11
john@kiwi:~/pics/x/x_files/11$ ls
0_0.jpeg  0_7.jpeg  1_5.jpeg  2_3.jpeg  3_1.jpeg  3_8.jpeg  4_6.jpeg  5_4.jpeg
0_1.jpeg  0_8.jpeg  1_6.jpeg  2_4.jpeg  3_2.jpeg  4_0.jpeg  4_7.jpeg  5_5.jpeg
0_2.jpeg  1_0.jpeg  1_7.jpeg  2_5.jpeg  3_3.jpeg  4_1.jpeg  4_8.jpeg  5_6.jpeg
0_3.jpeg  1_1.jpeg  1_8.jpeg  2_6.jpeg  3_4.jpeg  4_2.jpeg  5_0.jpeg  5_7.jpeg
0_4.jpeg  1_2.jpeg  2_0.jpeg  2_7.jpeg  3_5.jpeg  4_3.jpeg  5_1.jpeg  5_8.jpeg
0_5.jpeg  1_3.jpeg  2_1.jpeg  2_8.jpeg  3_6.jpeg  4_4.jpeg  5_2.jpeg
0_6.jpeg  1_4.jpeg  2_2.jpeg  3_0.jpeg  3_7.jpeg  4_5.jpeg  5_3.jpeg

You can see it's made a grid of tiles 6 across and 9 down.

Now reassemble the tiles and write as a TIFF pyramid:

john@kiwi:~/pics/x/x_files/11$ vips arrayjoin "$(ls *.jpeg | sort -t_ -k2g -k1g)" x.tif[tile,pyramid,compression=jpeg] --across 6
john@kiwi:~/pics/x/x_files/11$ vipsheader x.tif 
x.tif: 1524x2286 uchar, 3 bands, srgb, tiffload_stream

With pyvips it would be something like:

#!/usr/bin/env python3

import pyvips

tiles_across = 142
tiles_down = 150

tiles = [pyvips.Image.new_from_file(f"{x}_{y}.jpeg", access="sequential")
         for y in range(tiles_down) for x in range(tiles_across)]
im = pyvips.Image.arrayjoin(tiles, across=tiles_across)

im.write_to_file("x.jpg")

That took about 10 minutes and 6gb of ram to join 21,000 tiles on this laptop.

这篇关于如何将dzi文件转换为多块金字塔tiff格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆