run("pip")

ip1_orig = load_image("{data}/img/img2.png")

grayscale(ip1_orig)

bin = ip1_orig.duplicate()

auto_threshold(bin)

edm = edm(bin, in_place=False)


ws = bin.duplicate()
ws.setTitle("watershed")
watershed(ws)


up = bin.duplicate()
up.setTitle("ultimate points")
ultimate_points(up)

vr = bin.duplicate()
vr.setTitle("veronoi")
veronoi(vr)

edm_disp = remap(edm, in_place=False)
#edm.duplicate()
#edm_disp.getProcessor().setMinAndMax(0,get_statistics(edm,Measurements.MIN_MAX).max)


ws_disp = grayscale(ws, False)
up_disp = enhance_contrast(up, in_place=False)
vr_disp = enhance_contrast(vr, in_place=False)


create_stack([edm_disp, ip1_orig, bin, edm_disp, ws_disp, up_disp, vr_disp]).show()

final = bin.duplicate()
grayscale(final)
op_const(final,"add", -200)
op_image(final, vr_disp, 'or')
op_image(final, up_disp, 'or')

final.show()