Add line thickness for draw module functions

866 views
Skip to first unread message

Maik Riechert

unread,
Sep 11, 2014, 7:59:04 AM9/11/14
to scikit...@googlegroups.com
Hi,

I'm a bit surprised that the coordinate functions in the draw module don't have a thickness parameter. Is there some other way of thickening the lines? Otherwise they are only of very limited use, aren't they?

Also, in addition to the polygon function there should be a function for polylines. In the meantime I hacked something together but it's not ideal:

def polyline(poly):
    """
    use skimage.draw.line repeatedly to build all pixels that belong to a polyline
        
    :param poly: (n,2) ndarray of (y,x) pairs
    :rtype: rr, cc : (m,) ndarray of int
            Indices of pixels that belong to the polyline. 
    """        
    rrs, ccs = [], []
    for i in range(poly.shape[0]-1):
        y = poly[i,0]
        x = poly[i,1]
        y2 = poly[i+1,0]
        x2 = poly[i+1,1]
        rr, cc = skimage.draw.line(y,x,y2,x2)
        rrs.append(rr)
        ccs.append(cc)
    # this will contain duplicates, but shouldn't be an issue
    rr = np.concatenate(rrs)
    cc = np.concatenate(ccs)
    return rr,cc

Cheers
Maik

Stefan van der Walt

unread,
Sep 11, 2014, 8:39:15 AM9/11/14
to scikit...@googlegroups.com, Phil Elson

On 2014-09-11 12:59:04, Maik Riechert <maik.r...@arcor.de> wrote:
> I'm a bit surprised that the coordinate functions in the draw module don't
> have a thickness parameter. Is there some other way of thickening the
> lines? Otherwise they are only of very limited use, aren't they?

Juan hacked something together as well for the skimage paper, which we
can look into adding here. Recently, I had a conversation with Phil
Elson, who showed me that it is possible to do the actual drawing and
matplotlib and then transfer the relevant parts of the canvas over.
This may be a more productive approach in the long run.

Phil, any advice, especially on doing alpha values?

Stéfan

Phil Elson

unread,
Sep 11, 2014, 2:59:45 PM9/11/14
to Stefan van der Walt, scikit...@googlegroups.com

I'm currently out in the sticks in rural New York state with only my phone for connectivity, so can't help too much right now, but I was going to spin off a thread here about a possible interface for overlaying mpl figues (including axes) on an image (the result would always be RGBA). Of course this would include anything that mpl can draw, such as anti-aliased lines and text (through freetype) of arbitrary thickness.

I actually managed to pull all the components together on my 4hr train ride to the airport the other day, so I  really just need to package it up into a nice interface.

I should be able to provide more details on Tuesday.

Cheers,

Phil

Maik Riechert

unread,
Sep 12, 2014, 5:29:18 AM9/12/14
to scikit...@googlegroups.com, Stefan van der Walt
Phil, would using mpl mean that you actually manually have to create a figure etc.? Or would this happen behind the scenes and the current skimage.draw API is kept? My use case is drawing around 1000 circles on a 4000x3000 image, and it has to be quite fast (on-demand rendering). 

Cheers
Maik

--
You received this message because you are subscribed to a topic in the Google Groups "scikit-image" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scikit-image/94M63REkxcE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scikit-image...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Maik Riechert

unread,
Sep 12, 2014, 7:52:03 AM9/12/14
to scikit...@googlegroups.com, Stefan van der Walt
Sorry for the spam. One more question: Which library would you recommend in the meantime for drawing circles and (poly)lines with thickness on top of an image? Is pillow my best bet or is there something more lightweight?

Cheers
Maik

Maik Riechert

unread,
Sep 12, 2014, 10:44:16 AM9/12/14
to scikit...@googlegroups.com, Stefan van der Walt
I found a suitable work-around for me now, using matplotlib. Basically preparing the figure and loading the image into it such that it can be saved again in native resolution. Also, drawing things is in native image coordinates: https://gist.github.com/neothemachine/ec1d11172d4edf8221af

Cheers
Maik
Reply all
Reply to author
Forward
0 new messages