【问题标题】:Multi-file to Multi-page TIFF from large collection大型收藏中的多文件到多页 TIFF
【发布时间】:2014-04-10 20:52:06
【问题描述】:

努力使用 PyLiff、Libtiff 或任何可行的方法将多个文件合并为多页 TIFF。

我正在合并数千个带有任意八位 ID 和页码的文件:

目录命名为日期\images\1999\10\14

文件组 1 01234567_0001.tif、01234567_0002.tif、01234567_0003.tif

文件组 2 07654321_0001.tif, 07654321_0002.tif

转换后我想要两个文件:

  1. 01234567.tif(3 页多页 TIFF 文件)
  2. 07654321.tif(2 页多页 TIFF 文件)

等等。请提供有关脚本和合并的指导,这些脚本将按前 8 位数字分隔,合并具有该唯一八位数字的文件,并将新(合并)文件重命名为适当的 8-digit-number.tiff

我意识到这似乎不费吹灰之力。我有许多不同的脚本和方法会搅乱这个论坛的水。

【问题讨论】:

  • 当您说“...或任何可行的方法”时,您会考虑使用 Java 吗? :-) 如果是这样,您可以使用我在此答案中列出的方法:stackoverflow.com/questions/22856461/…(而不是阅读多页 TIFF,您将阅读多个单页 TIFF,但写作是等效的)。假设文件命名约定不是您的问题。
  • 一段不错的代码。我很欣赏这个建议。但整合是我在这里所做工作的关键部分。这些文件将直接从我们的数据库中导出,并且必须是多页 TIFF 格式。不过谢谢!我一直在寻找处理图像的工具。该代码将有助于其他项目:)

标签: image-processing tiff libtiff libtiff.net


【解决方案1】:

Ruby 能够提供的解决方案(Imagemagick 进行了实际转换)。希望这对其他人有帮助:

#!/usr/bin/env ruby

require 'find'
require 'set'

start_path = ARGV.shift || "~\Desktop\in"
output_path = ARGV.shift || "~\Desktop\out"

unless File.exist? start_path
  raise "cannot catalog contents; '#{start_path}' does not exist"
end

unless File.exist? output_path
  raise "cannot catalog contents; '#{output_path}' does not exist"
end

#make sure the output directory has a trailing slash
unless output_path =~ /\\$/
  output_path += "\\"
end

documents = Set.new

#look at each file
Find.find(start_path) do |file_path| 
  #look for the document pattern
  if file_path =~ /^(.*?(\d{8}))_\d{4}.tif/
    #track it so we can get the unique document list
    documents.add({:path => $1, :name => $2})
  end
end

documents.each do |doc|
  command = "convert #{doc[:path]}*.tif* #{output_path}#{doc[:name]}.tif"
  puts command
  `#{command}`
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多