Reputation: 31
Say I have a 1920x1080 image matrix. I also have a 3x3 matrix kernel. I want to assign the kernel to values of the image centered at any valid pixel location (ii, jj).
kernel(1, 1) = image(ii-1, jj-1);
kernel(1, 2) = image(ii-1, jj );
kernel(1, 3) = image(ii-1, jj+1);
kernel(2, 1) = image(ii , jj-1);
kernel(2, 2) = image(ii , jj );
...
kernel(3, 3) = image(ii+1, jj+1);
Is there a shortcut to do this besides loops?
Upvotes: 0
Views: 88
Reputation: 4549
If you just want to do that assignment for a given (ii,jj)
, you could do it in a single statement:
kernel = image(ii-1:ii+1, jj-1:jj+1);
Upvotes: 1