matrix operation
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!