I have two vectors: x
and y
where corresponding rows contain the coordinates of pixels in an image.
I also have a variable rad
that defines a square window with dimensions 2*rad+1 by 2*rad+1
If x
and y
are scalars,
patch = img(y - rad : y + rad, x - rad : x + rad);
produces the 2*rad+1 by 2*rad+1
square window around the point (y,x)
.
However, as I said above, my x
and y
are vectors. Is there a way to get the windows around each coordinate without just looping through the vector.
That is, I want to avoid this:
patch = zeros(2*rad+1, 2*rad+1, length(x));
for i = 1 : length(x)
patch(:,:,i) = img(y(i) - rad : y(i) + rad, x(i) - rad : x(i) + rad);
end
Is it possible to do this in a vectorized fashion?