matrix operation

17 Ansichten (letzte 30 Tage)
Vinh
Vinh am 6 Feb. 2012
Hi,
I am trying to avoid using loop for this operation. Basically, my job is to replace original image individual pixel by average value of a grid size i (any odd number bigger or equal to 3).
My code is somewhat like this:
for n=1:L1(1)
for m=1:L1(2)
h = 1:i;
window = double(InputImage(h+n-1,h+m-1));
output(n,m)= (sum(window(:,j+1)) + sum(window(j+1,:)) - window(j+1,j+1))/(i*2 - 1);
end
end
which was reasonably ok, in which I use arrar/matrix operation at the smallest scoop instead of another loop.
However, I want to improve its speed. I am trying to do something like
n=1:L1(1);
m=1:L1(2);
%create an array to move from one location to the other
h = 1:i;
output(n,m)= sum(InputImage(h+n-1,h+m-1))/(i*2 - 1);
Of course, it couldn't work since h and n do not match the dimensions. Is there some how I can "tell" Matlab that at keep m-vector and n-vector fixed while moving cursor along h-vector to do the average-operator for every single point of the image along n-m-vectors?

Antworten (1)

Andrei Bobrov
Andrei Bobrov am 6 Feb. 2012
out = conv2(InputImage,ones(i1)/i1^2,'same')

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by