How to Sum N elements of matrix

Hi,
I want to normalize image matrix using the following equation
equation.png
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)

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

Arun S
Arun S on 20 Jan 2019
Edited: Arun S on 20 Jan 2019
Hi Guillaume,
Thanks for quick reply,
I am actually trying to calculate the gradient of image d(x,y) and trying to normalize using 2N neighbouring elements with the square root of the equation mentioned
for X x Y image matrix
normalized image (x,y) = image pixel differene(x+1,y) / sqrt(equation mentioned)
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?
Hi
Yes for the last column i am assuming the original image last column values.
equation2.png
these are equations i am trying to implement with help of matlab functions
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.

Sign in to comment.

Asked:

on 20 Jan 2019

Commented:

on 21 Jan 2019

Community Treasure Hunt

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

Start Hunting!