Ich bin ein relativer Neuling in Python und beschäftige mich derzeit damit, ein Matlab-Skript in Python umzuschreiben. Hierzu gehört auch die Erstellung einer eigenen Colormap. Und genau hierbei stoße ich derzeit an meine Grenzen.
Die Colormap in Matlab besteht aus einer 256x3 (RGB) Matrix, die mittels des colormap()-Befehls auf das Bild gelegt wird:
Code: Alles auswählen
N=256;
map = zeros(N,3);
maxg = N;
map(1:maxg,2) = linspace(1,0,maxg);
maxr = floor(2*N/3);
map(1:maxr,1) = linspace(1,0,maxr);
maxb = floor(N/3);
map(1:maxb,3) = linspace(1,0,maxb);
image(my_image)
colormap(map)
Code: Alles auswählen
import matplotlib.pyplot as plt
# Erstellung der Matrix
N = 256
colmap = numpy.zeros((N, 3))
maxg = N
colmap[:maxg,1] = numpy.linspace(1,0,maxg)
maxr = math.floor(2*N/3)
colmap[:maxr,0] = numpy.linspace(1,0,maxr)
maxb = math.floor(N/3)
colmap[:maxb,2] = numpy.linspace(1,0,maxb)
# Erstellung der Colormap
cm = matplotlib.colors.ListedColormap(colmap)
# Benutzung
plt.imshow(my_image, cmap = cm)
Es kann auch nicht daran liegen, dass ich ein Numpy Array übergebe, da auch eine umwandlung per tolist()-Befehl nichts ändert:
Code: Alles auswählen
colmap2 = colmap.tolist()
cm = matplotlib.colors.ListedColormap(colmap2)
mfg Nikero