# Primitive drawing in array (Luxor & JuliaImages)

**URL:** https://discourse.julialang.org/t/primitive-drawing-in-array-luxor-juliaimages/39580
**Category:** Probabilistic Programming
**Tags:** question
**Created:** [May 16, 2020, 11:45am UTC](https://discourse.julialang.org/t/primitive-drawing-in-array-luxor-juliaimages/39580 "2020-05-16T11:45:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JuliaIncomplete](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliaincomplete/32/33997_2.png) [@JuliaIncomplete](https://discourse.julialang.org/u/JuliaIncomplete)
#### Post date: [May 16, 2020, 11:45am UTC](https://discourse.julialang.org/t/primitive-drawing-in-array-luxor-juliaimages/39580/1 "2020-05-16T11:45:10Z")

</div>

I’m trying to do some probabilistic programming and generate some ellipses to look like the target image. In theory this can work but it is quite slow as the way I’m drawing ellipses is using Luxor. As far as I can see, the only way to compare images (and compute a difference score) is to write Luxor’s drawing surface to file and then read it via the JuliaImages library. As I expect to do this comparison many times, writing to file and then reading is very slow.

Is there a way to rasterize the drawing by Luxor into a N-D image? If not, what other libraries can I use to directly draw onto an N-D array?

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [May 16, 2020, 12:07pm UTC](https://discourse.julialang.org/t/primitive-drawing-in-array-luxor-juliaimages/39580/2 "2020-05-16T12:07:27Z")

</div>

In Cairo.jl (which is btw the infrastructure to Luxor) you could draw to Image surfaces, to which you provide a data array.

This is part of runtests  
# fill 1/4 (upper quarter)

```julia
    z = zeros(UInt32,512,512);
    surf = CairoImageSurface(z, Cairo.FORMAT_ARGB32)
    # fills a 256x256 pixel area with blue,0.5 by using a hilbert curve of
    # dimension 32 (scaled by 8 -> 256) and a linewidth of 8
    hdraw(surf,32,8,8)

    d = simple_hist(surf.data)

```

---

<div class="post-metadata">

### Author: ![JuliaIncomplete](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliaincomplete/32/33997_2.png) [@JuliaIncomplete](https://discourse.julialang.org/u/JuliaIncomplete)
#### Post date: [May 16, 2020, 1:38pm UTC](https://discourse.julialang.org/t/primitive-drawing-in-array-luxor-juliaimages/39580/3 "2020-05-16T13:38:52Z")

</div>

Thank you. That was exactly what I was looking for!

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [May 17, 2020, 5:08pm UTC](https://discourse.julialang.org/t/primitive-drawing-in-array-luxor-juliaimages/39580/4 "2020-05-17T17:08:34Z")

</div>

I thought this might be a good thing to try to add, so I’m in the process of trying to add it:

 ![Screenshot 2020-05-17 at 18.06.29](https://global.discourse-cdn.com/julialang/original/3X/0/6/06308f2b98145e67586b8e78c955e73a98ad5246.png)

Currently not working too badly on master but time will tell…
