import numpy as np
import matplotlib.pyplot as plt
# Generating data for the heat map
# data = np.random.random(( 12 , 12 ))
data = np.arange(100).reshape((10,10))
data = np.sin(data * 0.1)
fig, ax = plt.subplots()
plt.imshow( data , cmap = 'gray' )
fig
random_image = np.random.rand(500,500)
plt.imshow(random_image, cmap='gray')
fig
import numpy as np
from skimage import data
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
image = data.coins()
astro = data.astronaut()
astro_sq = np.copy(astro)
astro_sq[50:100, 50:100] = [0,255,0]
plt.imshow(astro_sq, cmap='gray')
fig
# Create a signal
sig = np.zeros(100, np.float)
sig[30:60] = 1
fig, ax = plt.subplots()
ax.plot(sig)
ax.set_ylim(-0.1, 1.1)
fig
# Convolve it with a kernel
from scipy import ndimage as ndi
fig, ax = plt.subplots()
diff = np.array([1, 0, -1])
dsig = ndi.convolve(sig, diff)
plt.plot(dsig)
fig
# simple SVD example
U, Sigma, VT = np.linalg.svd([[1,1], [7,7]])
print("U: ", U, "Sigma: ", Sigma, "VT: ", VT)
print("Reconstruct original: ", U @ np.diag(Sigma) @ VT)
import numpy as np
from skimage import data
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
astro = data.astronaut()
def shift_image(X, dx, dy):
X = np.roll(X, dy, axis=0)
X = np.roll(X, dx, axis=1)
if dy>0:
X[:dy, :] = 0
elif dy<0:
X[dy:, :] = 0
if dx>0:
X[:, :dx] = 0
elif dx<0:
X[:, dx:] = 0
return X
def mapRange(value, low1, high1, low2, high2):
return low2 + (high2 - low2) * (value - low1) / (high1 - low1)
def clamp(num, min_value, max_value):
return max(min(num, max_value), min_value)
# Convert to f64 0-1
# astro_shift = shift_image(astro, 10, 0)
astro_f64 = astro.astype(np.float64)
astro_01 = mapRange(astro_f64,0,255,0,1)
# process image here
astro_mod = 1.2 * astro_01 ** 2 + 0.2
# Convert back to uint8 0-255
smallest = astro_mod.min(axis=(0,1))
largest = astro_mod.max(axis=(0,1))
astro_mod = astro_mod.clip(0,1)
astro_0255 = mapRange(astro_mod,0,1,0,255)
# astro_mod = astro - 50 #(astro + astro) // 2.
plt.imshow(astro_0255.astype(np.uint8))
fig