def newBBcoords(img_pred_Log, test_image):
    kernel_ones = np.ones([3, 3], np.uint8)
    closing_Log = cv2.morphologyEx(img_pred_Log, cv2.MORPH_CLOSE, kernel_ones)
    (labelsLog, numLog) = label(closing_Log, neighbors=8, background=0, return_num=True)
    regionsLog = regionprops(labelsLog)
    areasLog = [region['area'] for region in regionsLog]
    areasLogArr = np.array(areasLog)
    maxIndex = np.argmax(areasLogArr)
    value = labelsLog[(regionsLog[maxIndex]['coords'][0][0], regionsLog[maxIndex]['coords'][0][1])]
    labelsLog[(labelsLog != value)] = 0
    labelsLog[(labelsLog == value)] = 1
    labelsImg = np.multiply(np.array(labelsLog, np.uint8), 255)
    sizeBoxX = (regionsLog[maxIndex]['bbox'][3] - regionsLog[maxIndex]['bbox'][1])
    sizeBoxY = (regionsLog[maxIndex]['bbox'][2] - regionsLog[maxIndex]['bbox'][0])
    coordsBbox = list(regionsLog[maxIndex]['bbox'])
    if (sizeBoxX <= (0.5 * img_pred_Log.shape[1])):
        newSizeBoxX = (0.3 / (sizeBoxX / img_pred_Log.shape[1]))
        coordsBbox[1] = (coordsBbox[1] - (sizeBoxX * (0.5 * (newSizeBoxX - 1))))
        coordsBbox[3] = (coordsBbox[3] + (sizeBoxX * (0.5 * (newSizeBoxX - 1))))
    if (sizeBoxY <= (0.5 * img_pred_Log.shape[0])):
        newSizeBoxY = (0.5 / (sizeBoxY / img_pred_Log.shape[0]))
        coordsBbox[0] = (coordsBbox[0] - (sizeBoxY * (0.5 * (newSizeBoxY - 1))))
        coordsBbox[2] = (coordsBbox[2] + (sizeBoxY * (0.5 * (newSizeBoxY - 1))))
    if (coordsBbox[0] < 0):
        coordsBbox[0] = 0
    if (coordsBbox[1] < 0):
        coordsBbox[1] = 0
    if (coordsBbox[2] > test_image.shape[0]):
        coordsBbox[2] = (test_image.shape[0] - 1)
    if (coordsBbox[3] > test_image.shape[1]):
        coordsBbox[3] = (test_image.shape[1] - 1)
    coordsBboxInt = [round(x) for x in coordsBbox]
    return coordsBboxInt
def newBBcoords(img_pred_Log, test_image):
    kernel_ones = np.ones([3, 3], np.uint8)
    closing_Log = cv2.morphologyEx(img_pred_Log, cv2.MORPH_CLOSE, kernel_ones)
    (labelsLog, numLog) = label(closing_Log, neighbors=8, background=0, return_num=True)
    regionsLog = regionprops(labelsLog)
    areasLog = [region['area'] for region in regionsLog]
    areasLogArr = np.array(areasLog)
    maxIndex = np.argmax(areasLogArr)
    value = labelsLog[(regionsLog[maxIndex]['coords'][0][0], regionsLog[maxIndex]['coords'][0][1])]
    labelsLog[(labelsLog != value)] = 0
    labelsLog[(labelsLog == value)] = 1
    labelsImg = np.multiply(np.array(labelsLog, np.uint8), 255)
    sizeBoxX = (regionsLog[maxIndex]['bbox'][3] - regionsLog[maxIndex]['bbox'][1])
    sizeBoxY = (regionsLog[maxIndex]['bbox'][2] - regionsLog[maxIndex]['bbox'][0])
    coordsBbox = list(regionsLog[maxIndex]['bbox'])
    if (sizeBoxX <= (0.5 * img_pred_Log.shape[1])):
        newSizeBoxX = (0.3 / (sizeBoxX / img_pred_Log.shape[1]))
        coordsBbox[1] = (coordsBbox[1] - (sizeBoxX * (0.5 * (newSizeBoxX - 1))))
        coordsBbox[3] = (coordsBbox[3] + (sizeBoxX * (0.5 * (newSizeBoxX - 1))))
    if (sizeBoxY <= (0.5 * img_pred_Log.shape[0])):
        newSizeBoxY = (0.5 / (sizeBoxY / img_pred_Log.shape[0]))
        coordsBbox[0] = (coordsBbox[0] - (sizeBoxY * (0.5 * (newSizeBoxY - 1))))
        coordsBbox[2] = (coordsBbox[2] + (sizeBoxY * (0.5 * (newSizeBoxY - 1))))
    if (coordsBbox[0] < 0):
        coordsBbox[0] = 0
    if (coordsBbox[1] < 0):
        coordsBbox[1] = 0
    if (coordsBbox[2] > test_image.shape[0]):
        coordsBbox[2] = (test_image.shape[0] - 1)
    if (coordsBbox[3] > test_image.shape[1]):
        coordsBbox[3] = (test_image.shape[1] - 1)
    coordsBboxInt = [round(x) for x in coordsBbox]
    return coordsBboxInt