I usually draw with Compose.jl and then overlay the draw to an Images.jl
image with a function I'd made:
using Images, TestImages, Compose, Color
import Compose.compose
function compose(img::Image, c::Context)
width, height = size(img)
surface = Cairo.CairoARGBSurface(zeros(Uint32, height, width))
draw(PNG(surface), c)
overlay = reinterpret(BGRA{FixedPointNumbers.Ufixed8}, surface.data)
outimg = similar(img)
for i=1:width, j=1:height
alpha = overlay[i,j].alpha
overlay_pixel = convert(eltype(img), overlay[i,j])
beta = one(alpha) - alpha
outimg[i,j] = beta*img[i,j] + alpha*overlay_pixel
end
outimg
end
For example,
testimg = testimage("lighthouse")
width,height = size(testimg)
c = compose(context(), line([(1,1), (width,height)]))
c = compose(c, line([(width,1), (width/2,height/2)]))
c = compose(c, stroke(color("yellow")))
c = compose(context(units=UnitBox(0, 0, width, height)), c)
compose(testimg, c)
Regards,
Cristóvão
On Sunday, January 11, 2015 at 11:32:17 PM UTC, Andrei Zh wrote:
>
> I'm trying to do the following in Julia:
>
> 1. read image
> 2. draw some basic graphics (like lines and circles) over it
> 3. display it
>
> Points (2) and (3) may go the other way, i.e. I don't really care if
> drawing is done on image array in memory or on canvas.
>
> However, I'm not sure what's the easiest way to implement this logic.
> Basically, I'm using Images.jl and ImageView.jl, but it seems like they
> don't support drawing at all (except for modifying underlying arrays, of
> course). On other hand, there's Cairo and Tk, which are powerful, but seem
> to be terrible overkill for such a simple task.
>
> So I'm wondering:
>
> 1. is there an easy way to do "just this"?
> 2. If not, what is the minimal set of packages/actions needed to implement
> this logic?
>