Convolution on all dimensions of an image

조회 수: 10 (최근 30일)
armin nakhjiri
armin nakhjiri 2021년 1월 3일
답변: Image Analyst 2021년 1월 3일
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

답변 (2개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2021년 1월 3일
"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 2021년 1월 3일
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!

Translated by