15,019 views
この記事は最終更新から 2084日 が経過しています。
imreadで任意の形式の画像ファイルを配列データとして読み込める。
※imreadに失敗する場合は「(25) imreadを使えるようにする」を参照のこと
octave:1> ls
gfish.png
octave:2> img=imread('gfish.png');
octave:3> size(img)
ans =
238 307 3
octave:4>
imfinfo で画像ファイルの情報を表示することができる。
この画像は、縦238ピクセル、横307ピクセル、RGB 3バンドのPNG画像ファイルだ。
octave:5> imfinfo('gfish.png')
ans =
scalar structure containing the fields:
Filename = /home/temp/work/gfish.png
FileModDate = 19-Sep-2013 00:03:27
FileSize = 125173
Height = 238
Width = 307
BitDepth = 8
Format = PNG
LongFormat = Portable Network Graphics
XResolution = 37.790
YResolution = 37.790
TotalColors = 40382
TileName =
AnimationDelay = 0
AnimationIterations = 0
ByteOrder = undefined
Gamma = 0.45455
Matte = 0
ModulusDepth = 8
Quality = 75
QuantizeColors = 256
ResolutionUnits = undefined
ColorType = truecolor
View =
octave:6>
imshowで変数に読み込んだ画像データを表示することができる。
octave:6> imshow(img)
octave:7>
変数に読み込んだ画像データは、配列データとして扱うことができる。
例えば、各ピクセルのRGBバンドの平均値(画像データ配列の3次元目の平均値)を算出し、グレースケール画像を作成してみる。
octave:7> gimg = uint8(mean(img,3)); octave:8> imshow(gimg) octave:9>
グレースケール画像ができた。
作成したグレースケール画像を imwriteでPNGファイル出力してみる。
octave:9> imwrite(gimg,'gray.png','png')
octave:10> ls
gfish.png gray.png
octave:11>
アクセス数(直近7日): ※試験運用中、BOT除外簡易実装済2025-07-11: 0回 2025-07-10: 0回 2025-07-09: 1回 2025-07-08: 0回 2025-07-07: 0回 2025-07-06: 0回 2025-07-05: 0回