How to Sum N elements of matrix
Show older comments
Hi,
I want to normalize image matrix using the following equation

is it possible to do it using convolution method function without involving traditional for loop method.
if not any other efficient function to achieve the above equation will be helpful.
Answers (1)
Guillaume
on 20 Jan 2019
An equation usually involve an assignment. I'm assuming the result is supposed to be assigned to I(x, y). You also haven't said what's supposed to happen at the edges.
Your equation is indeed a convolution;
N = 5; %or whatever value
kernel = [ones(1, N), 0, ones(1, N)] / (2*N);
newimage = conv2(I, kernel, 'same'); %zero padding at the edges
4 Comments
Guillaume
on 20 Jan 2019
Can you write the mathematical formula you want to implement?
In addition, if you take the difference between consecutive columns, you'll end up with one less column. What do you do for the last column?
Arun S
on 21 Jan 2019
Guillaume
on 21 Jan 2019
You've got a power of 2 in your new equation that wasn't present in the original.
If I understood correctly:
N = 5; %or whatever value
Dc = -diff(I, [], 2); %difference across column.
kernel = [ones(1, N), 0, ones(1, N)] / (2*N);
Dcn = Dc ./ sqrt(conv2(Dc.^2, kernel, 'same'));
The result will have one less column than the original matrix. You can append the original last column if you wish.
Categories
Find more on Red in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!