ヘルプ:DjVuファイル

DjVuファイル
このページでは、DjVu形式のファイルを作成し、使用し、アップロードする方法を説明しています。DjVuファイルはスキャン画像を1つのコンテナ形式にグループ化しています。

画像の抽出 編集

ショートカット:
[{{Fullurl:%5B%5BH%3ADJVUIMG%5D%5D|redirect=no}} H:DJVUIMG]
 
インターネット・アーカイブからの、DjVu由来の画像(左上)と"Read online"の画像(右下)との比較。ぼやけ、ブロック化、細部の欠落など甚大な品質低下が明白です。しかし、この理由は明らかではありません。というのも、原作者がDjVu版を作成した方法を説明していないからです。
 
同じGoogle Bookスキャンからインターネット・アーカイブを経由した、DjVu由来の画像(左)とPDF由来の画像(右)の比較。DjVu版では圧縮によって非常にひどいダメージを受けています。しかし、この理由は明らかではありません。というのも、原作者がDjVu版を作成した方法を説明していないからです。

必要な画像を直接DjVuファイルから取り出せれば魅力的ですが、一部のDjVu文書は非可逆圧縮で作成されているため、常に正しい方法とは限りません。画像に不満がなくほかに情報源がないときは、DjVuファイルから抽出してコモンズ上のファイルに{{bad extraction}}タグをつけてください。そうでない場合は、JPG/PNG/TIFFによる文章のスキャンのような、よりよい情報源を使用してください。

DjVuがインターネット・アーカイブから入手したものであれば、オンライン上で閲覧可能な高画質JPGファイルが存在することが多いです(IA details pageにアクセスし、"read online" を選択し、and from there you can increase the size of the image、右クリックして画像を保存してください。

DjVuファイルがGoogle Booksスキャンから作成されている場合、たいていの場合DjVuファイルがPDFに由来していてさらなる圧縮ダメージを招いているため、Goole BooksのPDF文章を活用できます。多くのGoogle Booksスキャンは非常に低画質の2色画像で、他資料のスキャン(IAにおいて"uoft"や"ala"のような接尾辞でカラー・プレビュー画像を探してください)が画像抽出に適しています。さらに、Google Booksスキャンは画像が欠落していたり、ほとんど役に立たない、サムネイル品質の画像が埋め込まれていたり、ページが破れていたり、ページが折れていたりすることが多く、スキャナー操作者がページを押さえる手指が写っていたりする可能性があります。左図は良品質のGoogleスキャンで、つづくDjVu変換による甚大なダメージがみられます。

変換 編集

画像からDjVu 編集

Windows 編集

DjvuToyはさまざまな機能を提供するソフトウェアです:

  • Djvuの作成
  • Djvuファイルの結合
  • Djvuファイルの分割
  • Djvuファイルの編集
  • バンドルされたファイルの作成
  • DjVuから他ファイルへのエクスポート
  • DjVuからのテキストの抽出
  • DjVuファイルの構造情報のダウンロード(例:OCR座標)
画像 → バーチャル・プリンター → DjVu 編集

ページ・スキャンが、たとえばGoogle Bookスキャンのような、PDFファイルとして利用可能になっていれば、直接DjVuファイルに変換できます。以下のいずれかを利用してください。

  • The free Any2DjVu online service; this can also OCR the text and embed it in the .djvu file.
  • The freeware Pdf To Djvu GUI. Note that this requires the installation of the Cygwin environment as a prerequisite to its own installation.
  • The freeware command-line tool with GUI for Windows is the Djvu-Spec Pdf 2 Djvu Converter from the djvu-spec.narod.ru software page. This tool offers many settings to change the quality and size of the resulting djvu file.
  • The free software command-line pdf2djvu (available in repositories, also for Linux), which is usually as simple as pdf2djvu -o output.djvu input.pdf. There's also a GUI available.
  • If you need to crop the PDF document, you can use pdfcrop.pl (see below) for black margins or freeware Govert's PDF Cropper for white margins (it requires Ghostscript and .Net 2.0).

If the scanned images are made available as individual images, then the easiest option is to print them to a PDF document via one of the many "virtual printer" tools, such as the free PDFCreator; then convert the PDF document to DjVu as described above.

Note that there are many other options for converting pages to .djvu. One could convert using PostScript or multipage TIFF as the intermediate format, rather than PDF, but this would of course require different conversion tools. It is also possible to convert from .pdf or .ps to .djvu with the DjVuLibre software and its GSDjVu plug-in but due to licensing restrictions installing the plug-in is a fairly intricate process that involves compiling a patched version of Ghostscript.

Another free Windows tool that can come in handy for the images-to-pdf-to-djvu process is ConcatPDF, a GUI tool that permits easy splitting and merging of PDF files. This tool can also be used online. An example of how ConcatPDF might be used is: if a 100-page document has previously been scanned and converted to .djvu and the single page #42 needs to be re-scanned, ConcatPDF would allow that one page to be inserted into the intermediate .pdf file without tracking down the other page images and re-composing the entire document. Installing ConcatPDF version 1.1 requires as prerequisites that the free Microsoft program libraries Microsoft .NET Framework Version 1 and the corresponding Visual J# .NET Redistributable Package be installed beforehand.

画像から直接DjVu 編集

しかし、はるかに高画質な文章はDjVuLibreソフトウェアライブラリーを使用することで実現できます。c44エンコーダーを使用することでJPEGファイルを直接個々のDjVuページにエンコードできます。PNGのような可逆圧縮形式の画像はPPM(カラースキャン用)かPGM(グレイスケール用)に変換してからc44を使用すべきです。ほとんどのページ・テキスト画像のような2色(すなわち白黒)スキャンについては、ページ画像をモノクロPBMフォーマットに変換してからcjb2エンコーダーを使用してDjVuにエンコードすることで、より小さなDjVuファイルを得られます。これらの画像形式変換はすべてフリーウェアのImageMagickライブラリーによって実行できます(バッチ上で、mogrifyを使用して)。個々のDjVuファイルはdjvmプログラムを使うことで複数ページのDjVuに統合できます;このプログラムはDjVuファイルにページを挿入したり削除したりすることもできます。

この工程の警告として、高画質スキャンによってより大きなファイルになってしまう可能性があり、現時点でのコモンズへのアップロード制限は100MBです。大きさはdidjvuおよび/またはminidjvuを使って前景・背景分割を適用することで実質的に減少できます。

djVuLibreのスクリプト化 編集

このスクリプトを使えば、画像ファイル(JPG、PNG、GIF、TIFF、およびImagemagickがPPMに変換可能なあらゆるファイル)の全ディレクトリを選択し、自動的にDjVuファイルに変換してcollateします。現在はこのスクリプトはWindows用ですが、簡単にLinux用に変換できます。使用にはPython、Imagemagick、およびDjvuLibreが必要になるでしょう。

Linux 編集

See also: User:GrafZahl/How to digitalise works for Wikisource
Method 0 - converting graphic files with foreground/background separation 編集

Just use didjvu.

You may consider preprocessing the scans with Scan Tailor.

Method 1 - page at a time with DjVuLibre 編集

You need the djvu software, which includes a viewer, and some tools for creating and handling DJVU files. You will probably also need the Imagemagick software for converting scans from one format to another:

  • The tool cjb2 is used to create a DJVU file from (bitonal) PBM or TIFF file.
  • The tool c44 is used to create a DJVU file a PNM or JPEG files. This handles colour images, but the compression is lower.

Therefore you need to convert your scans if they are not already in one of these formats.

Conversion to intermediate format 編集
  • Conversion from PNG format to PBM format with the tool convert from Imagemagick
convert rig_veda-000.png rig_veda-000.pbm
  • Depending on the quality of the original scans, you may find it useful to process them with the unpaper utility, which deletes black borders around the pages and aligns the scanned text squarely on the page. Unpaper is also capable of extracting two separate page images where facing pages of a book have been scanned into a single image. Another utility is mkbitmap, another pdfcrop.pl (Perl-based and free software, it requires Ghostscript and texlive-extra-utils on Ubuntu; it uses BoundingBox; it can crop a whole multipage PDF document in just one passage). PDFCrop (another one!) deletes white margins.
Conversion to DJVU page file 編集
  • Creation of a DJVU file from a PBM file
cjb2 -clean rig_veda-000.pbm rig_veda-000.djvu
  • Creation of a DJVU file from a JPEG file at a given resolution:
c44 -dpi 300 p100.jpg p100.djvu
Creating final DJVU document 編集
  • Adding the DJVU file to the final document
djvm -i rig_veda.djvu rig_veda-000.djvu

You need to repeat these steps with a script for each page of the book. Example:

#!/bin/bash
for n in `seq 1 9`
do
        i="rig_veda-$n.png"
        j=`basename $i .png`
        convert $i $j.pbm
        cjb2 -clean $j.pbm $j.djvu
        djvm -i rig_veda.djvu $j.djvu
done

There is also another way to add all the *.djvu parts into one:

djvm -c rig_veda.djvu rig_veda-000.djvu rig_veda-001.djvu rig_veda-002.djvu

See the following section for an automated process for multiple pages.

Method 2 - PDF to DjVu bash script 編集

Use this script, which converts a PDF document (multiple or single page) into images, automatically crops them with ImageMagick, converts them in DjVu and bundles them. This is very slow (a large PDF document can require days) but a little more efficient than the following method.

The resulting DjVu document is quite big and low-quality, probably because of poor font recognition, which may be fixed by newer versions of poppler (the used library): the version available in repositories is usually several months old.[1]

You can also remove the pdftoppm part and use the script to convert multiple images directly in a multiple page PDF document. If images are not in pbm format, you can convert them with a single command using mogrify from ImageMagick.

Method 3 - pdf2djvu 編集

Simply download the pdf2djvu tool from your repository to directly convert PDF document (single or multiple pages) into DjVu.

If the document contains the results of OCR (as is the case e.g. with FineReader output) then they are preserved in the DjVu document as the hidden text layer. Some other properties of the source document, including metadata, are also preserved. The quality and the size of the output depends primarily on the features of the source document but can also be controlled with several program parameters, such the resolution of foreground and background. The program is capable to use several threads to speed up the conversion.

The original author of this page made the following recommendation which does not seem valid:

Moreover, you need to crop directly the pdf before the conversion. On Linux this is quite difficult. You could use ImageMagick convert -crop, but attention: with multiple page big PDF document, this can take several GB of memory (the limit is 16 TB!) and kill your computer if you don't use the -limit area 1 option directly after -crop. This make the convertion very long.

The resulting PDF document is increased in size and reduced in quality because of rastering.[2]

See other crop tools above.

Method 4 - DjVuDigital 編集

Use djvudigital,[3] which like pdf2djvu converts pdf directly in DjVu.[4] There are licensing problems, because the GSDjVu library has a different license, then you'll need to compile it by yourself; the included utils make this step quite easy, but still long (about 1 hour) and a bit annoying.[5]

But, then you can convert PDF document into DjVu with a single command (see the previous section for crop). The conversion is slow (I find it will complete a 300 page PDF document in about 30-40 minutes). The resulting DjVu is of higher quality and lower file size compared to both the previous two methods.[1] Additionally, DjVuDigital can handle JPEG2000 (aka JPX) files embedded in PDF documents, which is a feature of many Google books. pdf2djvu, Any2Djvu and Internet Archive conversions all fail to convert these files, leaving blank pages in the output.

DjVuDigital has many advanced options to improve results, but they can be difficult to master.[6] In general, altering the --dpi option can give you a quick reduction in file size without too much fiddling.

オンライン([ほとんど]すべてのシステム) 編集

Any2Djvu 編集

画像をDjVuで変換するもう1つの方法は、画像をZIP化してAny2Djvuのサイトを利用して、DjVuファイルを作成する方法です。Any2DjvuはZIP内から画像を抽出し、OCR化したDjVuを作成します。OCR機能は英語のみの対応です。

Any2Djvuでは巨大ファイルは扱えません。大きなファイルはURLでアップロードする(例:ftp://ftp.bnf.fr/005/N0051165_PDF_1_-1DM.pdf などのリンクを入力することで)のが最善です。変換には数時間かかる可能性があります。Any2DjVuはメモリ不足により失敗することがときどきあります。Google Booksスキャンで共通するPDF文書に埋め込まれた"JPX"画像も変換できません。

インターネット・アーカイブ 編集

もう1つの方法は、PDF文書(または画像ファイルのアーカイブ)をInternet Archiveにアップロードする方法です。

(注意:2019年3月現在、仕様の改訂によりDjVuファイルは生成されなくなっています。代わりにPDF WITH TEXTをダウンロードし、Wikimedia CommonsにPDFファイルとして直接アップロードすることにより、OCRテキストを利用することができます。)

ログインする必要があります(OpenIdは使わないでください、機能しません[7])。

アップロード 編集

右上角の"Upload"をクリックしてください。Flashのアップロード(標準の"Share"ボタン)はFirefoxでは機能しません(代わりにOperaやInternet Explorer[8]またはLinuxを使用してください)。標準の非Flash方式も使えます(ただしFirefoxではファイルの大きさ制限が2GBまでになります。Chromiumではありません。);FTPアップロードは、遅くクラッシュの傾向があるため推奨しませんが、but is the only easy to learn possibility if you have to upload many files (which shouldn't be the case here).

OCRのワナ 編集

アップロードが完了すると、インターネット・アーカイブが派生作業を始めます:アップロードしたPDFファイル上の検知された文章のXML文章を作成するOCR、およびテキストが埋め込まれたDjVuファイル、単なるテキストだけのダンプ・ファイルなどへの変換[9]

派生(派生すべきものがあればアップロード後自動的に作動します)を始める前にメタデータを正しい言語に設定することを忘れないでください、そうでなければOCR言語が英語に設定され、他言語の作品の結果がひどくなります。複数のOCR言語を設定するのも不可能ではありませんが、同じ本を2回アップロードして別々の言語を設定してOCRを2回行うことがすすめられます[10]。 処理時間の長さはファイルの大きさと複雑さ、さらに現在のインターネット・アーカイブの変換テストのバックログに依存します[11]キュー内の進行はこちらで、提出した作業に関するより詳細な情報はこちらで確認できます(ログインが必須)

インターネット・アーカイブはプロフェッショナル用で商用でプロプライエタリのソフトウェアABBYY[12]を使用しており、かなり高画質の画像と多くの言語およびフォントのOCRと強力な圧縮[13]とによって高品質の最終版DjVuファイルが維持されます[1]。しかし、インターネット・アーカイブはときどき低画質の過圧縮DjVuファイルを作成します。こうなってしまったら、PDF文書をダウンロードして手動で変換できることが多いです。派生が対象する解像度に減少させることができます。通常はいくらかの「推測」によって自動的に設定されます。設定にはfixed-ppi欄を使い、300dpi以下に設定すると、大きさ、処理時間、および(ときには)エラーが減少します。

画像フォーマット 編集

複数のTIFF、JPG、JP2形式の画像(他形式は受け付けません)に分割されたブック・スキャンも適切にTARまたはZIP形式のアーカイブを作成すれば、変換(「派生」)されます[14]。ふつうは未圧縮のスキャンかJPEGをアップロードするほうがいいです;派生工程で作成されるjp2ファイルは、多大の労力がないと操作できないような形で圧縮されます。

トラブルシューティング 編集

派生工程で深刻な問題があり、管理者の介入が必要な場合(あなたのタスク・リストで赤になっているもの)、info archive.orgで助けを求めてください。ふつうはすごく親切です。ただし、一般的なヘルプのリクエストはフォーラムに投稿してください。何でもないことで手を煩わせないでください!


DjVuからテキスト 編集

Any2DjVuによるOCR 編集

無料変換サービスAny2DjVuで利用可能なOCRオプションは、スキャン画像にOCRを実行しますが、その結果のテキストは.djvuファイル自体に埋め込まれるため、ウィキソースで利用できるように抽出しなければなりません。

これをする方法の1つはソフトウェアDjVuLibreを使用してテキストを抽出することで、以下のようなコマンドを実行します

djvused myfile.djvu -e 'print-pure-txt' > myfile.txt

または

 djvutxt myfile.djvu > myfile-ocr.txt 

JVbotはDjVuのテキスト・レイヤーをウィキソースのページに自動でアップロードすることができます。たとえば、Robert the Bruce and the struggle for Scottish independence - 1909

インターネット・アーカイブによるOCR 編集

上記参照:DjVuファイルをアップロードしたら派生工程がOCRを実行します。

TesseractによるOCR 編集

OCRは無料のOCRソフトでスクリプトのTesseractで実行できます:

Tesseract 3.xやその他無料OCRエンジンによるOCR 編集

ocrodjvuを使用してください。

DjVuから画像 編集

Linux 編集

DjVuファイルから画像を抽出するにはddjvuを使います

ddjvu -page=8 -format=tiff myfile.djvu myfile.tif

全ページが終わったら、(-page=**なしで)ページがまとまったTIFFを複数の単一ページのPNG(あるいは任意の他の形式)に分割できます

convert -limit area 1 myfile.tif myfile.png

全ページを80%品質のTIFFに変換できます

ddjvu -format=tiff -eachpage -quality=80 myfile.djvu myfile-%03d.tiff

操作 編集

DjVuを生成するために使うDjVuファイルや画像を操作する際のアドバイスです:

DjVuファイルの分割 編集

DjVu文書は2とおりの選択肢があります:バンドルと非バンドル(間接)です;後者のフォーマットでは各ページを別々のファイルに保存します。以下のコメントはバンドル版のみを対象にしています。

大きな作品はウィキメディアのサーバーにアップロードできません。制限は100MBになります。DjVuを分割するためにはDjVuLibreの"Save as"を使用しページ範囲を指定して、アップロードできるような小ささのファイルを作成してください。試行錯誤が必要になるかもしれません。

コマンドラインからDjVuファイルを分割するためのもっとも簡単な方法はdjvmcvtを使うことです。

 mkdir mydoc/ &&
 djvmcvt -i 'mydoc.djvu' 'mydoc/' 'new-mydoc-index.djvu'

また、djvusedがコマンドラインから使用できます:

 djvused myfile.djvu -e 'select 10; save-page-with p10.djvu'

これは各ページで使用できます。ページ番号を知るには:

 djvused myfile.djvu -e 'n'

著作権存続中のページの除去 編集

archive.orgやその他のサイトで利用可能な作成ずみのDjVuファイルの多くは、Googleの著作権ページが文章の表紙にあります。前提となる法令の分析に基づいたウィキメディアの方針では、たんにパブリック・ドメイン作品をスキャンもしくはコピーし、または主題を忠実に代表する平面写真を撮影したことをもって、著作権がパブリック・ドメインであるとは認められません。スキャン芸術作品、およびウィキメディア財団の見解に関するさらなる詳細は、ウィキメディア・コモンズでご確認ください。

かかる著作権存続中のページやその他無関係な素材はDjVuLibreで除去できます。DjVuLibreはオープン・ソース・プログラムで、DjVuの開発者により、GNUパブリック・ライセンスのもと保守されています。バイナリはWindows、Mac、Linux、Solaris、およびIRIXで利用可能です。djvm.exeが含まれており、コマンド・ライン・ユーティリティーとして実行できます。If you cannot figure out how to do this, you can message Mkoyle (talk), and he will do it for your file and email the file to you for upload. 1ページめ(1)を削除(-d)するためのコマンドラインは以下のとおりです:

djvm -d filename.djvu 1

ある特定のページの表示 編集

 

[[Image:...]]のリンク・タグは"page"引数を受け入れるため、たとえば以下のウィキ・コードはEmily Dickinson Poems (1890).djvuの右側164ページを、幅150ピクセルで表示します(文章なしのうら表紙):

[[Image:Emily Dickinson Poems (1890).djvu|right|150px|page=164]]



The page image can be displayed in the DjVu in place of text as in en:Page:Personal Recollections of Joan of Arc.djvu/9 using:

{{use page image|caption=JOAN'S VISION}}


en:Personal Recollections of Joan of Arc/Book I/Chapter 2のようにページ画像をウィキソースのMain名前空間内に表示するには以下のようにします:

[[Image:Personal_Recollections_of_Joan_of_Arc.djvu|page=27|right|thumbnail|200px|THE FAIRY TREE]]

脚注 編集

  1. 1.0 1.1 1.2 例: これは1691 book from GallicaのPDF文書で205MBあります。pdf2djvu.shスクリプトで変換するとほとんど読めない382.4MBのDjVu、djvudigitalでは少し読みやすくなった316.7MBのDjVu、そしてインターネット・アーカイブではより良い品質の51.3 MBのDjVuファイルになります。
  2. For instance, this 55 MB PDF document when cropped with ImageMagick gives a 100 MB PDF document which converted with pdf2djvu gives a 86.2 MB djvu, while the Internet Archive gives directly a 10.1 MB djvu of better quality.
  3. Man page.
  4. A comparison here.
  5. Complete instructions here.
  6. Moreover, they can require the proprietary msepdjvu libray instead of csepdjvu: see superhero pres: is it independently reproducible?.
  7. See forums: Authentication error; not a valid OpenID, Login problems when I click "Share" .
  8. See forum.
  9. もとのPDFにテキスト・レイヤーがないときは、派生工程が、同じく先ほど検知したOCR生成文章を適用することで、自動的に二次のテキスト付きPDFを作成します。

    ですが、PDFがGoogle Booksからのもので、1ページめに免責通知があるときは、派生プロセスが免責ページの隠れたテキスト・レイヤーを検知し、残りのページにも隠れたテキスト・レイヤーがあると想定して、決して作業せず二次PDFファイルの自動作成を完全にスキップすることを、留意してください。免責ページを残すが、すべての隠れたテキストを分離するというのが最適なアプローチです。その理由は、DjVuファイルの謝辞の同時作成と関係があります――分離して空白ページと交換するのも差しつかえありませんし、もちろん最終手段として免責ページを削除することもできます。

  10. See forum.
  11. 例:Vocabolario degli accademici della Crusca, 1691は派生に5.1日かかりました。
  12. 2013年からヴァージョン9.0
  13. たとえば、大きさがdjvudigital出力と比べて1/6になります。
  14. FAQ; documentation of the format to use. 留意点: 拡張子はかならず小文字, tiff は1つ, ppiの値をメタデータに入力. 画像のアーカイブがそのように認識されない場合は, メタデータを編集して形式を"Single Page Processed TIFF ZIP" (TARの場合も) にするなどしてください. おそらくthe _images.zipアーカイブ形式を最初にするべきでしょう.

関連項目 編集