Example #1
0
 def __init__(self, file, dstImgPath):
     self.image = loadImg(file)
     self.fileName = os.path.basename(file)
     self.imgName = self.fileName[:self.fileName.rfind('.')]
     print('ImageColorAug image:', file, self.fileName, self.imgName)
     assert (self.image is not None)
     self.dstImgPath = self._createPath(dstImgPath)
def generateImageLabel(imgPath, annotPath, dst):
    deleteFolder(dst)
    createPath(dst)
    for i in listFile(imgPath, 'png'):
        H, W = getImgHW(loadImg(i))
        # print(H,W)
        fAnnot = getImgAnnotFile(annotPath, i)
        fAnnotName = getFileName(fAnnot)
        dstFile = dst + '\\' + fAnnotName
        print('fAnnot=', fAnnot)
        # print('dstFile=', dstFile)

        deleteFile(dstFile)
        coordinates = getFileCoordinates(fAnnot)
        writeToAnnotFile(H, W, dstFile, coordinates)
def demonstratePrediction(file, gtMaskFile=None):
    img = loadImg(file)
    # img = loadGrayImg(file)
    simg = blurImg(img)
    pMask = getPredictImg(simg)
    pImg = maskToOrignimalImg(img, pMask)

    if gtMaskFile is not None:
        maskImg = loadImg(gtMaskFile)
        # maskImg = resizeImg(maskImg,256,256)
        maskImg = processMaskImg(maskImg)
        # mImg = maskToOrignimalImg(img, maskImg)

    ls, nameList = [], []
    ls.append(img), nameList.append('Original')
    if gtMaskFile is not None:
        ls.append(maskImg), nameList.append('GT mask')
        # ls.append(mImg),nameList.append('GT Segmentation')
    ls.append(pImg), nameList.append('Predict Segmentation')

    if gtMaskFile is not None:
        ls.append(pMask), nameList.append('Predict Mask')

    plotImagList(ls, nameList, gray=True, showticks=False)
def main():
    args = cmd_line()
    src = args.src
    dst = args.dst

    createPath(dst)
    print('src=', src, 'dst=', dst)

    for i in pathsFiles(src, 'jpg'):  # png
        fileName = getFileName(i)
        img = loadImg(i)

        dstFile = args.dst + '\\' + fileName
        print(i, fileName, dstFile)
        predImg = getPredictionMaskImg(img)
        writeImg(predImg, dstFile)
def testFileLabel(imgPath, LabelPath, dstRecImgPath):
    createPath(dstRecImgPath)
    for i in listFile(imgPath):
        imgFile = getFileName(i)
        img = loadImg(i)
        H, W = getImgHW(img)
        print(i, imgFile, H, W)

        labelFile = LabelPath + '\\' + imgFile[:imgFile.rfind('.')] + '.txt'
        # labels = getLabelFileLabels(labelFile)
        # print(labels)
        coordinats = getCoordinatesFromLabels(H, W, labelFile)
        # print(coordinats)
        recImg = rectangleImgFromCoordinates(img.copy(), coordinats)

        destFile = dstRecImgPath + '\\' + imgFile[:imgFile.rfind('.')] + '_rec' + '.png'
        print(destFile)
        writeImg(recImg, destFile)
def getImageMask(file, maskeFile):
    img = loadImg(file)
    mask = loadImg(maskeFile)
    mask = processMaskImg(mask, backColor=0)
    # added_image = cv2.addWeighted(background, 1.0, mask, 0.8, 0)
    return img, mask