pythonのopencvで圧縮レベルがgroup 4のtifファイルを出力しても画像が出力されない

実現したいこと

初めて質問します。
pythonで画像をtifファイルで圧縮レベルがgroup 4のファイルを作成したい。

前提

pythonで画像を作成してtifファイルを出力しています。(圧縮がgroup 4)

発生している問題・エラーメッセージ

エラーは出ませんでした。
【出力結果】
2024/07/07 16:16 1,358 test_g4_image.tif
2024/07/07 16:16 42,722 test_lzw_image.tif

出力したファイル(test_g4_image.tif)をペイントで表示すると「壊れているまたはデータサイズが大きい」と表示される。
出力したファイル(test_lzw_image.tif)をペイントで表示すると正しく表示される。

該当のソースコード

python

1from PIL import Image, ImageFont, ImageDraw 2import magic 3import os 4import cv2 as cv 5import numpy as np 6 7width, height = 1200, 3008 9img_input = Image.new('L', (1200, 300), 'lightgrey')10 11# フォント設定12font_path = "ZenKakuGothicAntique-Black.ttf"13font = ImageFont.truetype(font_path, 80)14 15# テキストクラス作成16draw = ImageDraw.Draw(img_input)17# 入力するテキスト18text = "テスト画像です。"19# テキストの装飾20text_color = "white"21stroke_color = "black"22stroke_width = 523# テキストの位置24XX = width/225YY = height/226 27# テキスト挿入28draw.text((XX, YY), 29 text, 30 fill = text_color, 31 stroke_fill = stroke_color,32 stroke_width = stroke_width,33 font=font, 34 anchor='lm',35 )36 37img_output = img_input.convert('RGB')38img_array = np.array(img_output)39 40cv.imwrite("test_g4_image.tif", img_array, [cv.IMWRITE_TIFF_COMPRESSION, cv.IMWRITE_TIFF_COMPRESSION_CCITTFAX4])41cv.imwrite("test_lzw_image.tif", img_array, [cv.IMWRITE_TIFF_COMPRESSION, cv.IMWRITE_TIFF_COMPRESSION_LZW])42

補足情報(FW/ツールのバージョンなど)

numpy 2.0.0
opencv-contrib-python 4.10.0.84
opencv-python 4.10.0.84
pillow 10.4.0
pip 24.1.1

コメントを投稿

0 コメント