複数の画像の輝度値を抽出したいです

6 visualizaciones (últimos 30 días)
宗一郎(Soichiro) 髙橋(Takahasi)
宗一郎(Soichiro) 髙橋(Takahasi) el 10 de Nov. de 2021
高校生です
以下のコードを用いて、1枚の画像の輝度値を抽出したのですが、60枚ほどの画像に同じ作業をしたいです。
image = imread(filename);
I = rgb2gray(image);
A = mean2(I);

Respuestas (2)

Atsushi Ueno
Atsushi Ueno el 10 de Nov. de 2021
ついこの前の上記質問に良い事例が載っています。これを応用して下記に例を載せます。
60枚ほどの画像と下記スクリプトをカレントフォルダに置いて実行します。試しに画像3枚で実行してみました。
imgfiles = dir('*.jpg'); % 例:現在のフォルダにある拡張子jpgの画像を検索する
numfiles = length(imgfiles);
A = [];
for i = 1:numfiles
image = imread(imgfiles(i).name);
I = rgb2gray(image);
A = [A mean2(I)];
end
A
A = 1×3
136.0832 139.5826 114.1768
  1 comentario
宗一郎(Soichiro) 髙橋(Takahasi)
宗一郎(Soichiro) 髙橋(Takahasi) el 11 de Nov. de 2021
うまくできました。ご回答ありがとうございます。

Iniciar sesión para comentar.


Hernia Baby
Hernia Baby el 10 de Nov. de 2021
Editada: Hernia Baby el 10 de Nov. de 2021
任意の場所をuigetdir設定します。
そしてimageDatastoreからフォルダ内の画像ファイルの情報を抜き出します。
最後にcellfunでfunctionを各ファイルごとに処理します。
clc,clear;
s = uigetdir;
names = imageDatastore(s);
c=cellfun(@image_mean,names.Files,'UniformOutput',false);
function y = image_mean(name)
image = imread(name);
image_g = rgb2gray(image);
y = mean2(image_g);
end

Community Treasure Hunt

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

Start Hunting!