Convolution on all dimensions of an image

8 views (last 30 days)
Hello
I want this code to apply on RGB (and more dimentions) too.
what needs to be modified?
function output = mean_con(kernelSize) % get a kernel size from user (for a 3*3 they enter 3)
[path,~]=imgetfile(); % get an image
I=imread(path);
kernelSize = floor(kernelSize/2); % radius
for j=(kernelSize+1):(size(I,1)-kernelSize)
for i=(kernelSize+1):(size(I,2)-kernelSize)
clip = I((j-kernelSize):(j+kernelSize),(i-kernelSize):(i+kernelSize));
ave = imagemean(clip); % mean filter
ave = mean2(clip);
kernelMean=ave;
IOut(j,i) = kernelMean;
end
end
output=(uint8(IOut));
imshow(output);
end

Answers (2)

KALYAN ACHARJYA
KALYAN ACHARJYA on 3 Jan 2021
"I want this code to apply on RGB (and more dimentions) too."
One way: Try with different planes, and concatenation later, lets consider 3 D case
IOut=cat(3,ave{1},ave{2},ave{3})
If you are applying an average filter with a specific window (kernel) size, you can do this in a simpler way, have you looked at the vectorization approach to solve the same.

Image Analyst
Image Analyst on 3 Jan 2021
You can use convn() but I don't see the point of blurring across color channels (blending the color channels together). I think you'd be better off blurring each color channel independently. That's what happens in the real world when an image is blurred.

Community Treasure Hunt

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

Start Hunting!