画像を分割し各セグメントの平均値を出したい。
16 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
128×128の画像を縦横64分割し、各区画の平均値を出力した画像を作成したいです。
0 commentaires
Réponse acceptée
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);
Plus de réponses (1)
Voir également
Catégories
En savoir plus sur 近傍処理とブロック処理 dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!