画像を分割し各セグメントの平均値を出したい。

23 views (last 30 days)
夏樹 坂本
夏樹 坂本 on 17 Sep 2020
Commented: 夏樹 坂本 on 17 Sep 2020
128×128の画像を縦横64分割し、各区画の平均値を出力した画像を作成したいです。

Accepted Answer

Atsushi Ohashi
Atsushi Ohashi on 17 Sep 2020
1枚の画像を指定したサイズで分割し、それぞれの分割したブロックごとで処理を実行するには brockproc 関数がご利用になれます。
brockproc 関数ではユーザが指定した関数を指定したサイズで画像を分割したブロックに対して実行することができます。
% サンプルとして、peppers.pngを利用します
I = imread('peppers.png');
% 128x128にリサイズします
imageSize = [128, 128];
I = imresize(I, imageSize);
% ここではグレースケール画像を利用します
I = rgb2gray(I);
figure; imshow(I);
% 分割サイズを指定します
divSize = [64, 64];
% 1つのブロックサイズを求めます
blockSize = imageSize ./ divSize;
% 1つ1つのブロックごとに平均値を求める関数を定義します
fun = @(block_struct) uint8( round(mean2(block_struct.data)) );
% ブロックごとに平均値を求めた値を出力します
J = blockproc(I, [2, 2], fun);
figure; imshow(J);
  1 Comment
夏樹 坂本
夏樹 坂本 on 17 Sep 2020
回答ありがとうございます。
アドバイスのおかげで解決しました。ありがとうございます。

Sign in to comment.

More Answers (1)

Shunichi Kusano
Shunichi Kusano on 17 Sep 2020
blockproc関数を使えるかと思います。

Community Treasure Hunt

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

Start Hunting!