def main(): output = directories.loadImagesInFolder(directories.output) output = np.asarray(output) groundTruth = directories.loadImagesInFolder(directories.groundTruth) groundTruth = np.asarray(groundTruth) l = [] for outputImage in output: #Find the corresponding groundTruth image fname = outputImage[1] groundTruthImage = groundTruth[groundTruth[:, 1] == fname][0][0] #Now compare the output with the ground truth groundTruthImage = greyscale(groundTruthImage) pixelsTotal = groundTruthImage.size outputImage = np.asarray(outputImage[0]) outputImage = greyscale(outputImage) img = directories.loadImageByName(directories.data + fname + ".bmp") if img is None: img = directories.loadImageByName(directories.data + fname + ".jpg") assert img is not None img[outputImage == 0] = 0 cv2.cv.SaveImage("maskedImages/" + fname + ".jpg", cv2.cv.fromarray(np.asarray(img, dtype="int"))) print("Done")
def scoreOutput(): output = directories.loadImagesInFolder(directories.output) groundTruth = directories.loadImagesInFolder(directories.groundTruth) for outputImage, groundTruthImage in zip(output, groundTruth): fname = outputImage[1] outputImage = np.asarray(outputImage)[0] outputImage = greyscale(outputImage) threshold(outputImage, 150) groundTruthImage = np.asarray(groundTruthImage)[0] groundTruthImage = greyscale(groundTruthImage) pixelsDifferent = np.count_nonzero(outputImage != groundTruthImage) pixelsTotal = outputImage.shape[0] * outputImage.shape[1] """ visualize(outputImage) visualize(groundTruthImage) """ print fname + ": \t" + "{:.0%}".format(float(pixelsDifferent)/pixelsTotal)
def main(): output = directories.loadImagesInFolder(directories.output) output = np.asarray(output) groundTruth = directories.loadImagesInFolder(directories.groundTruth) groundTruth = np.asarray(groundTruth) print("") print("Name\t\tYour dif") l = [] for outputImage in output: #Find the corresponding groundTruth image fname = outputImage[1] groundTruthImage = groundTruth[groundTruth[:, 1] == fname][0][0] #Now compare the output with the ground truth groundTruthImage = greyscale(groundTruthImage) pixelsTotal = groundTruthImage.size outputImage = np.asarray(outputImage[0]) outputImage = greyscale(outputImage) threshold(outputImage, 150) assert groundTruthImage.shape == outputImage.shape pixelsDifferent = np.count_nonzero(outputImage != groundTruthImage) fractionDifferent = float(pixelsDifferent)/pixelsTotal #pixels2Different = np.count_nonzero(output2Image != groundTruthImage) #print(fname + ": \t" + "{:.0%}".format(fractionDifferent))# + ": \t\t" + "{:.0%}".format(float(pixels2Different)/pixelsTotal)) #visualize(outputImage - groundTruthImage) l.append((fractionDifferent, fname)) for fractionDifferent, fname in sorted(l): print(fname + ": \t" + "{:.1%}".format(fractionDifferent))# + ": \t\t" + "{:.0%}".format(float(pixels2Different)/pixelsTotal)) return l