複数の画像に対する処理の仕方がわかりません

7 views (last 30 days)
R
R on 17 Nov 2022
Commented: R on 17 Nov 2022
複数枚ある画像に対しての処理のやり方が分かりません。
下記の手順のことをやりたいと考えています。
複数画像を読み込む
読み込んだ画像を二値化
二値化画像の白色部分の面積を出す
面積を A1, A2,.... ,Anといったような変数に入れる
面積の平均を出す
ご教授いただけると幸いです。

Accepted Answer

Atsushi Ueno
Atsushi Ueno on 17 Nov 2022
imageDatastore関数で取り扱う画像を集約し、readall関数で全画像を読み込み、cellfun関数で各画像を処理しています。
  • 二値化は万能な方法が困難で色々検討が必要です(下記はimbinarize関数任せにしています)
  • メモリに入らない程大量の画像は読み込めません。read関数で1枚ずつ処理するのが無難です
  • 下記は2枚の画像をサンプルとしましたが「フォルダ下に含まれる画像」等の形で処理できます
fs = matlab.io.datastore.FileSet(["street1.jpg","coins.png"]); % サンプルは2枚だけ
imds = imageDatastore(fs);
Is = readall(imds) % 複数画像を読み込む
Is = 2×1 cell array
{480×640×3 uint8} {246×300 uint8}
BWs = cellfun(@(x) imbinarize(im2gray(x)),Is,'uni',false) % 読み込んだ画像を二値化
BWs = 2×1 cell array
{480×640 logical} {246×300 logical}
As = cellfun(@(x) sum(x,'all'),BWs) % 二値化画像の白色部分の面積を A1, A2,.... ,Anといったような変数に入れる
As = 2×1
40943 22290
AveArea = mean(As) % 面積の平均を出す
AveArea = 3.1617e+04
  1 Comment
R
R on 17 Nov 2022
ありがとうございます。
複数枚ある場合どうしたらよいのか分からなかったので解決しました。

Sign in to comment.

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!