How can I make mean filter for color image?

10 vues (au cours des 30 derniers jours)
Gleb Bulatovskiy
Gleb Bulatovskiy le 19 Déc 2018
Commenté : Gleb Bulatovskiy le 21 Déc 2018
I am trying to do something like this for a color image:
SetPixelsIn32by32BlocksToStandardDeviationExample_01.png SetPixelsIn32by32BlocksToStandardDeviationExample_02.png
I was trying to use plockproc function but kept getting an error; it is my first time working with an image in matlab but i feel like it should not be hard to do. Can anyone help please?

Réponse acceptée

Image Analyst
Image Analyst le 20 Déc 2018
Gleb, you just had to make a minor modification to my code to call it 3 times, once for each color channel, and then recombine the results into an RGB image.
meanFilterFunction4 = @(theBlockStructure) mean2( * ones(1, 1, class(;
% Now,here we actually to the actual filtering.
blockyImageR = blockproc(redChannel, blockSize, meanFilterFunction4);
blockyImageG = blockproc(greenChannel, blockSize, meanFilterFunction4);
blockyImageB = blockproc(blueChannel, blockSize, meanFilterFunction4);
[blockRows, blockColumns] = size(blockyImageR)
% Recombine separate color channels into a single, true color RGB image.
rgbImage2 = cat(3, blockyImageR, blockyImageG, blockyImageB);
Attached is a full demo using the standard peppers demo image and using a variety of input and output block sizes.
0000 Screenshot.png
Let me know if you still don't know how to adapt it to what you want.

Plus de réponses (2)

Image Analyst
Image Analyst le 19 Déc 2018
See attached blockproc demo, which does this.
  1 commentaire
Gleb Bulatovskiy
Gleb Bulatovskiy le 20 Déc 2018
This code doesnt work on Mac for some reason, however it works on windows.
It works for a black and white image, and if I use color image, it makes it black and white first and then processes it and outputs black and white image. What I need to do is the same thing but I need the output to be colored image as well.

Connectez-vous pour commenter.

Jan le 20 Déc 2018
Modifié(e) : Jan le 20 Déc 2018
X = RGBimage; % 2D matrix, 3D RGB array or any other array
V = 100; % Block size for 1st dim
W = 100; % and for 2nd dim
S = size(X);
M = S(1) - mod(S(1), V);
N = S(2) - mod(S(2), W);
MV = M / V;
NW = N / W;
% Cut and reshape input such that the 1st and 3rd dimension have the lengths V
% and W:
XM = reshape(X(1:M, 1:N, :), V, MV, W, NW, []);
Y = sum(sum(XM, 1), 3) ./ (V * W);
% Remove singleton dimensions:
S(1) = MV;
S(2) = NW;
Y = reshape(Y, S);

Community Treasure Hunt

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

Start Hunting!

Translated by