MATLAB 7.3 (R2006b) ではグレースケール画像は IMWRITE 関数を用いて正しく保存されないのはなぜですか?

1 view (last 30 days)
以下のグレースケール画像を作成しました。
A=repmat(-100:100,100,1);
figure(1)
imshow(A,[])
しかし、以下同様に IMWRITE 関数を用いてファイルに保存すると白黒となってしまいます。
imwrite(A,'myimage.png','BitDepth',16)
figure(2)
imshow('myimage.png')
グレースケール画像を正しく保存する方法を教えてください。

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 15 Apr 2013
これは関数 IMWRITE のデータの変換規則により発生します。
関数 IMWRITE の第 1 引数で指定する保存したい画像データの型が DOUBLE の場合、
範囲 0 ~ 1 のカラーマップが使用され、0 より小さい要素全ては 0 で、1 より大きい要素全ては 1 で置換されます。行列 A の要素の値は 0、1、負の数、または 1 より大きい正の数のみからなっているため、IMWRITE により 0 又は 1 のいづれかにマッピングされます。その結果、白黒の画像が出力されます。
正しく保存するため、以下同様に行列を範囲 0 ~ 1 の DOUBLE 型としてスケーリングしたデータに対して IMWRITE を行ってください。
A=A-min(A(:)); % shift data such that the smallest element of A is 0
A=A/max(A(:)); % normalize the shifted data to 1
imwrite(A,'myimage.png', 'BitDepth', 16);
figure(3)
imshow('myimage.png')
関数 IMWRITE の詳細は MATLAB コマンドプロンプトより
doc imwrite
を実行して表示されるドキュメントにてご参照頂けます。

More Answers (0)

Categories

Find more on イメージ in Help Center and File Exchange

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!