def labels2output_map(label,lppts,dim,stride):

	side = ((float(dim) + 40.)/2.)/stride # 7.75 when dim = 208 and stride = 16

	outsize = dim/stride
	Y  = np.zeros((outsize,outsize,2*4+1),dtype='float32')
	MN = np.array([outsize,outsize])
	WH = np.array([dim,dim],dtype=float)

	tlx,tly = np.floor(np.maximum(label.tl(),0.)*MN).astype(int).tolist()
	brx,bry = np.ceil (np.minimum(label.br(),1.)*MN).astype(int).tolist()

	for x in range(tlx,brx):
		for y in range(tly,bry):

			mn = np.array([float(x) + .5, float(y) + .5])
			iou = IOU_centre_and_dims(mn/MN,label.wh(),label.cc(),label.wh())

			if iou > .5:

				p_WH = lppts*WH.reshape((2,1))
				p_MN = p_WH/stride

				p_MN_center_mn = p_MN - mn.reshape((2,1))

				p_side = p_MN_center_mn/side

				Y[y,x,0] = 1.
				Y[y,x,1:] = p_side.T.flatten()

	return Y
def labels2output_map(label,lppts,dim_w, dim_h,stride, cls):

	side = ((float(dim_w) + 40.)/2.)/stride # 7.75 when dim = 208 and stride = 16

	outsize = int(dim_w/stride)
	Y  = np.zeros((outsize,outsize,2*4+3),dtype='float32')
	non_object_probs_template = np.ones((outsize,outsize),dtype='float32')
	Y[...,10] = non_object_probs_template.copy()
	MN = np.array([outsize,outsize])
	WH = np.array([dim_w,dim_h],dtype=float)

	tlx,tly = np.floor(np.maximum(label.tl(),0.)*MN).astype(int).tolist()
	brx,bry = np.ceil (np.minimum(label.br(),1.)*MN).astype(int).tolist()
	is_there_plate = False
	for x in range(tlx,brx):
		for y in range(tly,bry):

			mn = np.array([float(x) + .5, float(y) + .5])
			iou = IOU_centre_and_dims(mn/MN,label.wh(),label.cc(),label.wh())
			iou2 = iou_alternative(mn/MN, label.wh(), label.cc(), label.wh())
			iou_max = max(iou, iou2)

			if iou_max > .5:
				is_there_plate = True
				p_WH = lppts*WH.reshape((2,1))
				p_MN = p_WH/stride

				p_MN_center_mn = p_MN - mn.reshape((2,1))

				p_side = p_MN_center_mn/side
				if cls=='0':
					Y[y,x,0] = 1.
					Y[y,x,9] = 0.
				else:
					Y[y, x, 0] = 0.
					Y[y, x, 9] = 1.
				Y[y,x,1:9] = p_side.T.flatten()
				Y[y, x, 10] = 0.

	# if not is_there_plate:
	# 	print('sem placa na amostra: %s' % image_abs_path)
	return Y, is_there_plate