I am working on an image processing script. I need to let the user specify how to remap some classes in an image via a text file. The syntax in this file should be simple and self-evident. What I thought of doing is to get the user to write the string version of a dictionary:
125:126, 126:126, 127:128, 128:128
and then transform it into a real dictionary (this is the missing link):
a = {125:126, 126:126, 127:128, 128:128}
The remapping of the classes of the image would then be done like this:
u, indices = numpy.unique(image, return_inverse=True)
for i in range(0, len(u)):
u[i] = a[u[i]]
updatedimage = u[indices]
updatedimage = numpy.resize(updatedimage, (height, width)) #Resize to original dims
Is there a simple way to do this transformation from the "string version" to a real dictionary? Can you think of an easier/alternative one-line syntax that the user could use?