Konturen in Bildern erstellen.
riesigen Pool in zahllosen Biblioheken.
Code: Alles auswählen
import matplotlib.pyplot as plt
from skimage import data
from skimage import color
from skimage import img_as_float, img_as_ubyte
grayscale_image = img_as_float(data.camera()[::2, ::2])
image = color.gray2rgb(grayscale_image)
import matplotlib.pyplot as plt
# Matrix erstellen
matrix = [
[1,0,0,1],
[0,2,2,0],
[0,2,2,0],
[1,0,0,1],
]
leinwand, diagramm = plt.subplots()
diagramm.imshow(matrix)
plt.title("Matrix 4 x 4 ")
plt.show()
# Matrix erstellen
matrix = [
[1,0,0,1,2,1],
[0,2,2,0,3,1 ],
[0,2,2,0,1,2],
[1,0,0,1,3,4],
]
# Figure und Axes erstellen
leinwand, diagramm = plt.subplots()
# Diagramm malen
diagramm.imshow(matrix)
# Diagramm anzeigen
plt.title("Matrix 6 x 4")
plt.show()
# Matrix erstellen
matrix = [
[1,0,0,1,2,1,1,2,1,2],
[0,2,2,0,3,1,2 ,1,1,1],
[0,2,2,0,1,2,1,1,2,2],
[1,0,0,1,3,4, 2,3,1,1],
[1,0,0,1,2,1,1,2,1,2],
[0,2,2,0,3,1,2 ,1,1,1],
[0,2,2,0,1,2,1,1,2,2],
[1,0,0,1,3,4 ,2,3,1,1],
[1,0,0,1,2,1,1,2,1,2],
[0,2,2,0,1,3,1,2 ,1,1],]
# Figure und Axes erstellen
leinwand, diagramm = plt.subplots()
# Diagramm malen
diagramm.imshow(matrix)
# Diagramm anzeigen
plt.title("Matrix 10 x 10")
plt.show()
########################################
## Hier Farbe in Bildern ändern
########################## Jeder Multiplier kann beliebig verändert werden
A_multiplier = [1, 2, 255] # die Farbskala geht von 0 .... 255
B_multiplier = [2, 0, 255] #Werte höher als 255 werden ignoriert
########################################
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4), sharex=True, sharey=True)
ax1.imshow(A_multiplier * image)
ax2.imshow(B_multiplier * image)
plt.show()
######################Konturen bilden#########################
### Konturen an Bild teilen anpassen (hier am Kopf)
import numpy as np
import matplotlib.pyplot as plt
from skimage.color import rgb2gray
from skimage import data
from skimage.filters import gaussian
from skimage.segmentation import active_contour
img = data.astronaut()
img = rgb2gray(img)
s = np.linspace(0, 2 * np.pi, 400)
r = 100 + 100 * np.sin(s)
c = 220 + 100 * np.cos(s)
init = np.array([r, c]).T
snake = active_contour(
gaussian(img, sigma=3, preserve_range=False),
init,
alpha=0.015,
beta=10,
gamma=0.001,
)
fig, ax = plt.subplots(figsize=(7, 7))
ax.imshow(img, cmap=plt.cm.gray)
ax.plot(init[:, 1], init[:, 0], '--r', lw=3)
ax.plot(snake[:, 1], snake[:, 0], '-b', lw=3)
ax.set_xticks([]), ax.set_yticks([])
ax.axis([0, img.shape[1], img.shape[0], 0])
plt.show()