# Warp images and coordinates

**URL:** <https://discourse.julialang.org/t/warp-images-and-coordinates/46256>\
**Category:** Visualization\
**Tags:** question\
**Created:** [September 8, 2020, 11:37am UTC](https://discourse.julialang.org/t/warp-images-and-coordinates/46256 "2020-09-08T11:37:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [September 8, 2020, 11:37am UTC](https://discourse.julialang.org/t/warp-images-and-coordinates/46256/1 "2020-09-08T11:37:56Z")

</div>

I’m transforming an image using `ImageTransformations.wrap`, but I also want to use the same transformation to transform some coordinates. The idea is that a coordinate in the original image should be transformed to a coordinate in the warped image.

MWE:

```julia
using Images, CoordinateTransformations, Rotations, ImageView, ImageDraw, TestImages
img = testimage("lighthouse")
i = [350, 57] # the top of the lightning rod
draw!(img, Cross(Point(i...), 10), RGB{N0f8}(1)) # mark it with an +
t = recenter(RotMatrix(π/4), center(img)) # rotate 45° around the center
invt = inv(t)
imgw = warp(img, t)
iw = round.(Int, t(i)) # transform the lightning-rod coordinate as well (convert to Int too)
iiw = round.(Int, invt(i)) # inverse transform the lightning-rod coordinate as well (convert to Int too)
draw!(imgw, Cross(Point(iw...), 10), RGB{N0f8}(1,0,0)) # draw that same location again?
draw!(imgw, Cross(Point(i...), 10), RGB{N0f8}(0,1,0)) # draw that same location again?
draw!(imgw, Cross(Point(iiw...), 10), RGB{N0f8}(0,0,1)) # draw that same location again?
imshow(imgw) # no...

```

 ![a](https://global.discourse-cdn.com/julialang/original/3X/8/4/84cfb12c6a713f2503d1d0fde56552e7293eb906.jpeg)

After rereading the excellent and clear blogpost by Tim Holy:

> **[Knowing where you are: custom array indices in Julia](https://julialang.org/blog/2017/04/offset-arrays/#why_should_we_care_which_indices_an_array_has_a_first_example)**
>
> Knowing where you are: custom array indices in Julia | Arrays are a crucial component of any programming language,...

I still can’t get this to work:

**How do I transform the original coordinates, `[350, 57]`, to where the top of the lightning-rod is in the transformed image (so where the white plus-sign is in the above image)?**

---

<div class="post-metadata">

**Author:** ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Post date:** [September 8, 2020, 12:12pm UTC](https://discourse.julialang.org/t/warp-images-and-coordinates/46256/2 "2020-09-08T12:12:48Z")

</div>

Ah… `ImageDraw.Point`’s notion of x and y is different from the coordinates ImageTransformations.warp accepts. So by flipping x and y I got it to work:

```julia
iiw = round.(Int, reverse(invt(reverse(i)))) # inverse transform the lightning-rod coordinate as well (convert to Int too)
draw!(imgw, Cross(Point(iiw...), 10), RGB{N0f8}(0,0,1)) # draw that same location again?

```

 ![a](https://global.discourse-cdn.com/julialang/original/3X/1/b/1bc88d8b6b4439be703912cc88b4f4ffe0d3e203.png)
