Beispiel #1
0
def main():
    parser = argparse.ArgumentParser(
        description="Photometric Stereo",
    )
    parser.add_argument(
        "--lightning",
        nargs="?",
        help="Filename of JSON file containing lightning information",
    )
    parser.add_argument(
        "--mask",
        nargs="?",
        help="Filename of an image containing a mask of the object",
    )
    parser.add_argument(
        "image",
        nargs="*",
        help="Images filenames",
    )
    parser.add_argument(
        "--generate-map",
        action='store_true',
        help="Generate a map.png file which represends the colors of the "
             "normal mapping.",
    )
    args = parser.parse_args()

    if args.generate_map:
        normals = generateNormalMap()
        plt.imsave('map.png', normals)
        return

    if not len(args.image) >= 3:
        print("Please specify 3+ image files.")
        return

    if args.lightning:
        normals = photometricStereo(args.lightning, args.image)
        if False:
            try:
                with open('data.pkl', 'rb') as fhdl:
                    normals = pickle.load(fhdl)
            except:
                
                with open('data.pkl', 'wb') as fhdl:
                    pickle.dump(normals, fhdl)
    else:
        normals = photometricStereoWithoutLightning(args.image)

    if args.mask:
        mask = getImage(args.mask)
        mask = mask.T
        print(normals.shape, mask.shape)
        normals[mask<(mask.max() - mask.min())/2.] = np.nan

    color = colorizeNormals(normals)
    plt.imsave('out.png', color)
    mesh.write3dNormals(normals, 'out-3dn.stl')
    surface = mesh.surfaceFromNormals(normals)
    mesh.writeMesh(surface, normals, 'out-mesh.stl')
Beispiel #2
0
def doTestAndComparePMSwL(images, lightning_file, file_prefix):
    normals = pms.photometricStereoWithoutLightning(images)

    color = pms.colorizeNormals(normals)
    plt.imsave('{}-normals.png'.format(file_prefix), color)
    mesh.write3dNormals(normals, '{}-3dn.stl'.format(file_prefix))
    surface = mesh.surfaceFromNormals(normals)
    mesh.writeMesh(surface, normals, '{}-mesh.stl'.format(file_prefix))
Beispiel #3
0
def doTestAndComparePMSwL(images, lightning_file, file_prefix):
    normals = pms.photometricStereoWithoutLightning(images)

    color = pms.colorizeNormals(normals)
    plt.imsave('{}-normals.png'.format(file_prefix), color)
    mesh.write3dNormals(normals, '{}-3dn.stl'.format(file_prefix))
    surface = mesh.surfaceFromNormals(normals)
    mesh.writeMesh(surface, normals, '{}-mesh.stl'.format(file_prefix))
Beispiel #4
0
def doTestAndComparePMS(images, lightning_file, file_prefix):
    normals = pms.photometricStereo(lightning_file, images)

    color = pms.colorizeNormals(normals)
    plt.imsave('{}-normals.png'.format(file_prefix), color)
    mesh.write3dNormals(normals, '{}-3dn.stl'.format(file_prefix))
Beispiel #5
0
def doTestAndComparePMS(images, lightning_file, file_prefix):
    normals = pms.photometricStereo(lightning_file, images)

    color = pms.colorizeNormals(normals)
    plt.imsave('{}-normals.png'.format(file_prefix), color)
    mesh.write3dNormals(normals, '{}-3dn.stl'.format(file_prefix))
Beispiel #6
0
import mesh

imagedir = 'D:/Test Images/quilt/small/'
filenames = os.listdir(imagedir)
images_filenames = [(imagedir + name) for name in filenames
                    if name.endswith("sm.jpg")]
masknames = [(imagedir + name) for name in filenames
             if name.startswith('photo_mask') and name.endswith(".png")]
maskname = masknames[0]
mask = getImage(maskname)
mask = mask.T

#images_filenames = ('IMG_1229sm.jpg', 'IMG_1230sm.jpg', 'IMG_1231sm.jpg', 'IMG_1232sm.jpg', 'IMG_1233sm.jpg', 'IMG_1234sm.jpg', 'IMG_1235sm.jpg', 'IMG_1236sm.jpg')
normals = photometricStereoWithoutLightning(images_filenames)
normals[mask < (mask.max() - mask.min()) / 2.] = np.nan

color = colorizeNormals(normals)
plt.imsave(imagedir + 'out.png', color)
mesh.write3dNormals(normals, imagedir + 'out-3dn.stl')
surface = mesh.surfaceFromNormals(normals)
mesh.writeMesh(surface, normals, imagedir + 'out-mesh.stl')
heightMap = mesh.surfaceToHeight(surface)
plt.imsave(imagedir + 'out-height.png', heightMap)
outfile = OpenEXR.OutputFile(
    imagedir + 'out-height-fl2.exr',
    OpenEXR.Header(surface.shape[0], surface.shape[1]))
R = array.array('f', surface[:, :, 2].reshape(-1, 1)).tostring()
outfile.writePixels({'R': R})
outfile.close()
mesh.writeObj(surface, normals, imagedir + 'out-surface.obj')