How can I make mean filter for color image?
2 vues (au cours des 30 derniers jours)
Gleb Bulatovskiy le 19 Déc 2018
I am trying to do something like this for a color image:
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?
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(theBlockStructure.data(:)) * ones(1, 1, class(theBlockStructure.data));
% 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.
Let me know if you still don't know how to adapt it to what you want.
Plus de réponses (2)
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);