Skip to content

Instantly share code, notes, and snippets.

@tomasaschan
Created March 19, 2015 15:21
Show Gist options
  • Save tomasaschan/e88f952f135797430324 to your computer and use it in GitHub Desktop.
Save tomasaschan/e88f952f135797430324 to your computer and use it in GitHub Desktop.
Toroidal image
# Define the following stuff somewhere
type ToroidalImage
img
end
import Base.getindex
getindex(timg::ToroidalImage, x, y) = timg.img[mod1(x, size(timg.img,1)), mod1(x, size(timg.img,2))]
# Then use like so
img = rand(100,50)
torimg = ToroidalImage(img)
mypixel = torimg[105, -10]
@Tyruiop
Copy link

Tyruiop commented Mar 19, 2015

Thank you for that (and sorry for leaving earlier) but I can't see how does that solve the issue of translating the whole image. For example, if I want to translate the whole image in the x direction by 5 pixels say, I still have to do something a kind of T_img = img[1:x + 5, :], which is not possible. And you can't do things like new_img = img[a:b, c:d] anymore to pick only part of the image.

Edit: well, it does work for [[1:x] + 5, :] if I change mod1 by mod though, good! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment