目次→http://1studying.blogspot.jp/2017/07/c-magicknetmokuzi.html#kuw04
「C# Magick.NETを使ってみる。その2」
http://1studying.blogspot.com/2017/05/c-magicknet_31.html
の補足情報です。
画像の主要情報取得
画像の主要情報取得の為のコードを記載します。
「Form1」クラスの「button1」クリックイベントコードを以下に置換
private void button1_Click(object sender, EventArgs e)
{
string fileStr = "./test_RGB.psd";
//string fileStr = "./test_CMYK.psd";
//string fileStr = "./test_グレー.psd";
//string fileStr = "./test_2値.psd";
using (var myMagick = new ImageMagick.MagickImage(fileStr))
{
chk_info(fileStr);//ファイルのインフォメーション表示
chk_Exif(myMagick);//「Magick.NET画像」のEXIF情報表示
chk_data(myMagick);//「Magick.NET画」の詳細情報書き出し
MessageBox.Show("処理終了");
}
}
「Form1」クラス内に以下のコードを追記 //ファイルのインフォメーション表示
private void chk_info(string filenameStr)
{
var myMagickInfo = new ImageMagick.MagickImageInfo();
myMagickInfo.Read("" + filenameStr);
//「画像情報」取得
string msg = "info\n";
msg += "ファイル名:" + myMagickInfo.FileName + "\n";
msg += "色空間:" + myMagickInfo.ColorSpace + "\n";
msg += "横pixel:" + myMagickInfo.Width + "\n";
msg += "縦pixel:" + myMagickInfo.Height + "\n";
msg += "画像形式:" + myMagickInfo.Format + "\n";
msg += "横解像度:" + myMagickInfo.Density.X + "\n";
msg += "縦解像度:" + myMagickInfo.Density.Y + "\n";
msg += "解像度の単位:" + myMagickInfo.Density.Units + "\n";
MessageBox.Show(msg);
}
//「Magick.NET画像」のEXIF情報表示
private void chk_Exif(ImageMagick.MagickImage myMagick)
{
//using (var myMagick = new ImageMagick.MagickImage("./Lenna.jpg"))
//{
//「Exif情報」取得
ImageMagick.ExifProfile myMagickExif = myMagick.GetExifProfile();
//「Exif情報」が存在すれば
if (myMagickExif != null)
{
string str = "exif\n";
foreach (var exifValue in myMagickExif.Values)
{
str += exifValue.Tag + "(";
str += exifValue.DataType + "):";
str += exifValue.ToString() + "\n";
}
MessageBox.Show(str);
}
else
{
MessageBox.Show("Exif情報はありません");
}
//}
}
//「Magick.NET画」の詳細情報書き出し
private void chk_data(ImageMagick.MagickImage myMagick)
{
string tmpStr = "";
//using (var myMagick = new ImageMagick.MagickImage("./test_RGB.psd"))
//using (var myMagick = new ImageMagick.MagickImage("./test_CMYK.psd"))
//using (var myMagick = new ImageMagick.MagickImage("./test_グレー.psd"))
//using (var myMagick = new ImageMagick.MagickImage("./test_2値.psd"))
//{
tmpStr += "取得開始\n";
tmpStr += myMagick.Density.ToString() + "\n";
tmpStr += myMagick.ColorType.ToString() + "\n";
tmpStr += myMagick.Depth.ToString() + "\n";
tmpStr += myMagick.ChannelCount.ToString() + "\n";//r
tmpStr += myMagick.ClassType.ToString() + "\n";
tmpStr += myMagick.ColorFuzz.ToString() + "\n";
tmpStr += myMagick.ColormapSize.ToString() + "\n";
tmpStr += myMagick.ColorSpace.ToString() + "\n";
tmpStr += myMagick.Compose.ToString() + "\n";
tmpStr += myMagick.Endian.ToString() + "\n";
tmpStr += myMagick.FilterType.ToString() + "\n";
tmpStr += myMagick.Format.ToString() + "\n";
tmpStr += myMagick.Gamma.ToString() + "\n";//r
tmpStr += myMagick.Height.ToString() + "\n";//r
tmpStr += myMagick.Interlace.ToString() + "\n";
tmpStr += myMagick.Interpolate.ToString() + "\n";
tmpStr += myMagick.IsOpaque.ToString() + "\n";//r
tmpStr += myMagick.MatteColor.ToString() + "\n";
tmpStr += myMagick.Orientation.ToString() + "\n";
tmpStr += myMagick.Page.ToString() + "\n";
tmpStr += myMagick.ProfileNames.ToString() + "\n";//r
tmpStr += myMagick.Quality.ToString() + "\n";
tmpStr += myMagick.ReadMask.ToString() + "\n";
tmpStr += myMagick.RenderingIntent.ToString() + "\n";
tmpStr += myMagick.Settings.ColorSpace.ToString() + "\n";
tmpStr += myMagick.Settings.ColorType.ToString() + "\n";
tmpStr += myMagick.Settings.Endian.ToString() + "\n";
tmpStr += myMagick.Settings.Format.ToString() + "\n";
tmpStr += myMagick.Signature.ToString() + "\n";//r
tmpStr += myMagick.TotalColors.ToString() + "\n";//r
tmpStr += myMagick.VirtualPixelMethod.ToString() + "\n";
tmpStr += myMagick.Width.ToString() + "\n";//r
tmpStr += myMagick.WriteMask.ToString() + "\n";
//}
Encoding utf8Enc = Encoding.GetEncoding("utf-8");
using (var writer = new System.IO.StreamWriter(@"./test_out.txt", false, utf8Enc))
{
writer.Write(tmpStr);
writer.WriteLine("取得終了。");
MessageBox.Show("「Magick.NET画像」詳細情報を\n「test_out.txt」へ書き出しました");
}
}
該当する画像を読み込み、必要な情報を取得します。「Magick画像」の主要プロパティ設定値
「Magick画像」主要プロパティ一覧
・テストに使用したデータ
DLL「Q8」使用
600Dpi
2362×2362Pixel、99.99×99.99mm
「Photoshop」で作成したpsd(画像統合済み、レイヤー無し)
の「RGB」「CMYK」「グレースケール」、「2階調」画像を、
それぞれ「Magick画像」として開き検証してみた。
| ↓(r)はGetのみ | 「RGB」 | 「CMYK」 | 「Gray」 | 「2値」 |
| 「Density」 | 600x600 inch | 600x600 inch | 600x600 inch | 600x600 inch |
| 「ColorType」 | TrueColor | ColorSeparation | Palette | Palette |
| 「Depth」 | 8 | 8 | 8 | 1 |
| (r) 「ChannelCount」 |
3 | 4 | 2 | 2 |
| 「ClassType」 | Direct | Direct | Pseudo | Pseudo |
| 「ColorFuzz」 | 0% | 0% | 0% | 0% |
| 「ColormapSize」 | -1 | -1 | 256 | 256 |
| 「ColorSpace」 | sRGB | CMYK | Gray | Gray |
| 「Compose」 | Over | Over | Over | Over |
| 「Endian」 | MSB | MSB | MSB | MSB |
| 「FilterType」 | Undefined | Undefined | Undefined | Undefined |
| 「Format」 | Psd | Psd | Psd | Psd |
| (r) 「Gamma」 |
0.4545454 38289642 |
0.4545454 54545455 |
0.4545454 54545455 |
0.4545454 54545455 |
| (r) 「Height」 |
2362 | 2362 | 2362 | 2362 |
| 「Interlace」 | NoInterlace | NoInterlace | NoInterlace | NoInterlace |
| 「Interpolate」 | Undefined | Undefined | Undefined | Undefined |
| (r) 「IsOpaque」 |
True | True | True | True |
| 「MatteColor」 | #BDBDBDFF | #BDBDBDFF | #BDBDBDFF | #BDBDBDFF |
| 「Orientation」 | TopLeft | TopLeft | TopLeft | TopLeft |
| 「Page」 | 2362x2362 | 2362x2362 | 2362x2362 | 2362x2362 |
| (r) 「ProfileNames」 |
(stringコンテナ) | (stringコンテナ) | (stringコンテナ) | (stringコンテナ) |
| 「Quality」 | 0 | 0 | 0 | 0 |
| 「ReadMask」 | Psd 2362x2362 8-bit Gray 0.00 |
Psd 2362x2362 8-bit Gray 0.00 |
Psd 2362x2362 8-bit Gray 0.00 |
Psd 2362x2362 1-bit Gray 0.00 |
| 「RenderingIntent」 | Perceptual | Perceptual | Undefined | Undefined |
| 「Settings. ColorSpace」 |
Undefined | Undefined | Undefined | Undefined |
| 「Settings. ColorType」 |
Undefined | Undefined | Undefined | Undefined |
| 「Settings. Endian」 |
Undefined | Undefined | Undefined | Undefined |
| 「Settings. Format」 |
Unknown | Unknown | Unknown | Unknown |
| (r) 「Signature」 |
(署名) ユニークな英数字 |
(署名) ユニークな英数字 |
(署名) ユニークな英数字 |
(署名) ユニークな英数字 |
| (r) 「TotalColors」 |
766 | 1281 | 256 | 2 |
| 「VirtualPixelMethod」 | Undefined | Undefined | Undefined | Undefined |
| (r) 「Width」 |
2362 | 2362 | 2362 | 2362 |
| 「WriteMask」 | Psd 2362x2362 8-bit Gray 0.00 |
Psd 2362x2362 8-bit Gray 0.00 |
Psd 2362x2362 8-bit Gray 0.00 |
Psd 2362x2362 1-bit Gray 0.00 |
考察
「RGB」と「CMYK」の違いは「ColorType」と「ColoreSpace」で判別している?
「グレースケール」と「2値」データの違いはDepthが1か8かの違いのみ。
「Gamma」は「0.454545…」となっているが、
実際は「1/0.454545…」なので、標準的につかわれる「Gamma2.2」となる。
「Magick画像」の主要プロパティ設定値2
色々な「Magick画像」のデータを比較してみる。
・Q8「RGB」
DLL「Q8」使用
600Dpi
2362×2362Pixel、99.99×99.99mm
「Photoshop」で作成したpsd(画像統合済み、レイヤー無し)の「RGB」画像
・Q16「自作RGB」
DLL「Q16」使用
背景緑、150×150Pxel
//「インスタンス時に開く」(背景緑、150*150)
using (var myMagick = new ImageMagick.MagickImage(new ImageMagick.MagickColor("#00ff00"), 150, 150))
{
}
で生成・Q8 Ps変換「2値Tiff」
DLL「Q8」使用
Q8「RGB」を「Photoshop」でグレースケール化→2値化した物です。
「画像圧縮をLZW」で保存しています。
・Q8 自前変換「2値Tiff」
DLL「Q8」使用
Q8「RGB」を「Magick.NET」でグレースケール化→2値化した物です。
の順で変換後保存。
(保存前にプロパティやExif調べて、
保存後、再度開いてのプロパティやExifを調べる。違いがでるか…確認。
PSDとtiffで保存した場合、開いた物との違いは出るのか?
↓
違いが出るっぽい。
ここでの表は後で取得し直す必要あり。)
| ↓(r)はGetのみ | Q8 「RGB」 |
Q16 「自作RGB」 |
Q8 Ps変換 「2値Tiff」 |
Q8 自前変換 「2値Tiff」 |
| 「Density」 | 600x600 inch | 0x0 | 600x600 inch | |
| 「ColorType」 | TrueColor | TrueColor | Bilevel | |
| 「Depth」 | 8 | 16 | 1 | |
| (r) 「ChannelCount」 |
3 | 3 | 1 | |
| 「ClassType」 | Direct | Direct | Direct | |
| 「ColorFuzz」 | 0% | 0% | 0% | 0% |
| 「ColormapSize」 | -1 | -1 | -1 | |
| 「ColorSpace」 | sRGB | sRGB | Gray | Gray |
| 「Compose」 | Over | Over | Over | Over |
| 「Endian」 | MSB | LSB | LSB | MSB |
| 「FilterType」 | Undefined | Undefined | Undefined | Undefined |
| 「Format」 | Psd | Xc | Tiff | Psd |
| (r) 「Gamma」 |
0.4545454 38289642 |
0.4545454 38289642 |
0.4545454 54545455 |
0.4545454 54545455 |
| (r) 「Height」 |
2362 | 150 | 2362 | 2362 |
| 「Interlace」 | NoInterlace | NoInterlace | NoInterlace | NoInterlace |
| 「Interpolate」 | Undefined | Undefined | Undefined | Undefined |
| (r) 「IsOpaque」 |
True | True | True | True |
| 「MatteColor」 | #BDBDBDFF | #BDBDBDBD BDBDFFFF |
#BDBDBDFF | #BDBDBDFF |
| 「Orientation」 | TopLeft | Undefined | TopLeft | TopLeft |
| 「Page」 | 2362x2362 | 150x150 | 2362x2362 | 2362x2362 |
| (r) 「ProfileNames」 |
(stringコンテナ) | (stringコンテナ) | (stringコンテナ) | (stringコンテナ) |
| 「Quality」 | 0 | 0 | 0 | 0 |
| 「ReadMask」 | Psd 2362x2362 8-bit Gray 0.00 |
Xc 150x150 16-bit Gray 0.00 |
Tiff 2362x2362 1-bit Gray 0.00 |
Psd 2362x2362 1-bit Gray 0.00 |
| 「RenderingIntent」 | Perceptual | Perceptual | Undefined | Undefined |
| 「Settings. ColorSpace」 |
Undefined | Undefined | Undefined | Undefined |
| 「Settings. ColorType」 |
Undefined | Undefined | Undefined | Undefined |
| 「Settings. Endian」 |
Undefined | Undefined | Undefined | Undefined |
| 「Settings. Format」 |
Unknown | Unknown | Unknown | Unknown |
| (r) 「Signature」 |
(署名) ユニークな英数字 |
(署名) ユニークな英数字 |
(署名) ユニークな英数字 |
(署名) ユニークな英数字 |
| (r) 「TotalColors」 |
766 | 1 | 2 | 2 |
| 「VirtualPixelMethod」 | Undefined | Undefined | Undefined | Undefined |
| (r) 「Width」 |
2362 | 150 | 2362 | 2362 |
| 「WriteMask」 | Psd 2362x2362 8-bit Gray 0.00 |
Xc 150x150 16-bit Gray 0.00 |
Tiff 2362x2362 1-bit Gray 0.00 |
Psd 2362x2362 1-bit Gray 0.00 |
考察
・「Q16」で新規キャンバスを作成した時のみ「Depth」は「16」となる。
16bitの色深度をサポートしていないビューアが多い為、
「Q16」で新規キャンバスを作成する場合注意が必要。
・これとは別に、
Q8「RGB」と同じファイルをQ16で開いてみても全ての値は同じだった。
「Depth」は「8」となる。
・「Endian」エンディアンの違い
「LSB」リトルエンディアン
「MSB」ビックエンディアン
保持される画像形式により違いが出る。
・注意!
保存形式を変更した場合、
そのままで、情報を取得したものと、
保存したファイルを開き直したものとで、結果に違いが出る!
他
表に関しては、
再度作り直しが必要。
値を信じ切らないようにして下さい。
中途半端な状態での公開です。
0 件のコメント:
コメントを投稿