Commit 1e6e8d20 authored by Gaetano Raffaele's avatar Gaetano Raffaele
Browse files

ENH: tentative tiled vectorization (tbc).

parent afc5f2a8
No related merge requests found
Showing with 11 additions and 10 deletions
+11 -10
......@@ -188,7 +188,7 @@ def write_qgis_seg_style(out_file, line_color='255,255,0,255', line_width=0.46):
)
return out_file
def vectorize_tile(obj, startx, starty, sizex, sizey, to_do, out):
def vectorize_tile(obj, startx, starty, sizex, sizey, to_skip, out):
print('Using startx {} and starty {}'.format(startx, starty))
r = otb.itkRegion()
r['index'][0], r['index'][1] = startx, starty
......@@ -200,7 +200,6 @@ def vectorize_tile(obj, startx, starty, sizex, sizey, to_do, out):
min_bb_y = 0
rp = regionprops(np.squeeze(clip['array'].astype(np.int)))
to_do += [o.label for o in rp]
for o in rp:
if o.bbox[2] > sizey - 1 or o.bbox[3] > sizex - 1:
......@@ -209,11 +208,12 @@ def vectorize_tile(obj, startx, starty, sizex, sizey, to_do, out):
min_bb_x = sizex - o.bbox[1]
if o.bbox[2] > sizey - 1 and sizey - o.bbox[0] > min_bb_y:
min_bb_y = sizey - o.bbox[0]
else:
if o not in to_do:
clip['array'][clip['array'] == o.label] = 0
else:
to_do.remove(o)
elif o.label in to_skip:
clip['array'][clip['array'] == o.label] = 0
for o in rp:
if (o.bbox[2] >= sizey - min_bb_y and o.bbox[2] <= sizey - 1) or (o.bbox[3] >= sizex - min_bb_x and o.bbox[3] <= sizex - 1) :
to_skip.append(o.label)
vec = otb.Registry.CreateApplication('SimpleVectorization')
vec.ImportImage('in', clip)
......@@ -222,14 +222,15 @@ def vectorize_tile(obj, startx, starty, sizex, sizey, to_do, out):
print('Returning min_bb_x {} and min_bb_y {}'.format(min_bb_x, min_bb_y))
return min_bb_x, min_bb_y, to_do
return min_bb_x, min_bb_y, to_skip
def tiled_vectorization(input_segm, nominal_tile_size, output_template):
obj_to_tile_map = {}
in_seg = to_otb_pipeline(input_segm)
W,H = in_seg.GetImageSize('out')
idx = 0
to_do = []
vec_list = []
to_skip = []
min_bb_x, min_bb_y = 0, 0
for x in range(0,W,nominal_tile_size[0]):
x = max(0, x - min_bb_x - 1)
......@@ -239,7 +240,7 @@ def tiled_vectorization(input_segm, nominal_tile_size, output_template):
y = max(0, y - min_bb_y - 1)
th = min(nominal_tile_size[1]+min_bb_y+1, H-y)
fn = output_template.format(idx)
min_bb_x_tmp, min_bb_y = vectorize_tile(in_seg, x, y, tw, th, fn)
min_bb_x_tmp, min_bb_y, to_skip = vectorize_tile(in_seg, x, y, tw, th, to_skip, fn)
min_bb_x = max(min_bb_x, min_bb_x_tmp)
vec_list.append(fn)
idx += 1
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment