def rect2raster(r,h):
    """Convert iulib rectangles to raster coordinates.  Raster coordinates are given
    as (row0,col0,row1,col1).  Note that this is different from some other parts of
    Python, which transpose the rows and columns."""
    (x0,y0,x1,y1) = (r.x0,r.y0,r.x1,r.y1)
    y1 = h-y1-1
    y0 = h-y0-1
    return (y1,x0,y0,x1)