El Pinguino
El Pinguino

Reputation: 31

Assign smaller matrix to larger matrix (centered about an element in the larger matrix)?

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

Answers (1)

Rafael Monteiro
Rafael Monteiro

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

Related Questions