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

16 vues (au cours des 30 derniers jours)
夏樹 坂本
夏樹 坂本 le 17 Sep 2020
Commenté : 夏樹 坂本 le 17 Sep 2020
128×128の画像を縦横64分割し、各区画の平均値を出力した画像を作成したいです。

Réponse acceptée

Atsushi Ohashi
Atsushi Ohashi le 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 commentaire
夏樹 坂本
夏樹 坂本 le 17 Sep 2020
回答ありがとうございます。
アドバイスのおかげで解決しました。ありがとうございます。

Connectez-vous pour commenter.

Plus de réponses (1)

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

Community Treasure Hunt

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

Start Hunting!