Simple drawing over image?

510 views
Skip to first unread message

Andrei

unread,
Jan 11, 2015, 6:32:17 PM1/11/15
to julia...@googlegroups.com
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? 

Tim Holy

unread,
Jan 11, 2015, 6:57:50 PM1/11/15
to julia...@googlegroups.com
ImageView has an annotation framework; it's documented in the README.

--Tim

Andrei Zh

unread,
Jan 11, 2015, 7:31:35 PM1/11/15
to julia...@googlegroups.com
Ah, my fault. I should have checked it before googling more sophisticated things. Thanks! 

Max Suster

unread,
Jan 12, 2015, 2:49:02 AM1/12/15
to julia...@googlegroups.com

You can do this easily in OpenCV.jl.  An example of drawing is already in the README.md. 

Cristóvão Duarte Sousa

unread,
Jan 12, 2015, 6:22:18 AM1/12/15
to julia...@googlegroups.com
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

Max Suster

unread,
Jan 12, 2015, 2:43:01 PM1/12/15
to julia...@googlegroups.com

To be more precise, in OpenCV.jl, you can do the following:

1. read image

filename = "your image"
img = imread(filename)

2. draw some basic graphics (like lines and circles) over it

center = cvPoint(260,275)
radius = 30
color = cvScalar(0,0,255) #red 
thickness=4 lineType=LINE_AA shift = 0 
circle(img, center, radius, color, thickness,lineType, shift) 
rectangle(img, cvPoint(30,30), cvPoint(150,150), cvScalar(255,0,0), thickness, lineType, shift)

3. display it

imdisplay(img, "Drawing")
closeWindows(0,27,"")


Reply all
Reply to author
Forward
0 new messages