如何对我的数据应用水平过滤器?
How to apply horizontal filter to my data?
我正在生成合成数据以使用热图。
Example of the data
我想知道是否有办法水平“扩展”数据或水平应用过滤器,使值看起来与时间相关。
知道我该怎么做吗?
这是我使用的代码和数据:
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
data = pd.read_csv('data9.csv')
cl = sns.heatmap(data, cmap= 'viridis')
plt.show()
您可以从 this link
下载 CSV 文件
我的方法是在水平轴上使用 average-like 过滤器。您必须测试其他 filters/kernels 并在需要时填充您的输入以避免数据边界附近的垂直淡入淡出线。此外,如果您只想模糊那个圆圈,您必须在该区域周围找到感兴趣区域 (ROI),然后对其进行模糊处理。
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
data = pd.read_csv("data9.csv").to_numpy()
plt.subplot(2, 3, 1)
plt.imshow(data, cmap="viridis", vmin=0, vmax=40)
plt.title("Original")
# Average 3 elements
filter = np.ones(3)
for line in range(data.shape[0]):
data[line] = np.convolve(data[line], filter, mode="same")/np.sum(filter)
plt.subplot(2, 3, 2)
plt.imshow(data, cmap="viridis", vmin=0, vmax=40)
plt.title("Avg3")
# Average 5 elements
filter = np.ones(5)
for line in range(data.shape[0]):
data[line] = np.convolve(data[line], filter, mode="same")/np.sum(filter)
plt.subplot(2, 3, 3)
plt.imshow(data, cmap="viridis", vmin=0, vmax=40)
plt.title("Avg5")
# Average 7 elements
filter = np.ones(7)
for line in range(data.shape[0]):
data[line] = np.convolve(data[line], filter, mode="same")/np.sum(filter)
plt.subplot(2, 3, 4)
plt.imshow(data, cmap="viridis", vmin=0, vmax=40)
plt.title("Avg7")
# Average 3 elements with emphasis on central element
filter = np.array([1, 2, 1])
for line in range(data.shape[0]):
data[line] = np.convolve(data[line], filter, mode="same")/np.sum(filter)
plt.subplot(2, 3, 5)
plt.imshow(data, cmap="viridis", vmin=0, vmax=40)
plt.title("Avg3 Emphasis")
# Average 5 elements with emphasis on central element
filter = np.array([1, 1, 2, 1, 1])
for line in range(data.shape[0]):
data[line] = np.convolve(data[line], filter, mode="same")/np.sum(filter)
plt.subplot(2, 3, 6)
plt.imshow(data, cmap="viridis", vmin=0, vmax=40)
plt.title("Avg5 Emphasis")
plt.tight_layout()
plt.show()
水平轴上的模糊数据:
我正在生成合成数据以使用热图。
Example of the data
我想知道是否有办法水平“扩展”数据或水平应用过滤器,使值看起来与时间相关。
知道我该怎么做吗?
这是我使用的代码和数据:
import pandas as pd
import seaborn as sns
from matplotlib import pyplot as plt
data = pd.read_csv('data9.csv')
cl = sns.heatmap(data, cmap= 'viridis')
plt.show()
您可以从 this link
下载 CSV 文件我的方法是在水平轴上使用 average-like 过滤器。您必须测试其他 filters/kernels 并在需要时填充您的输入以避免数据边界附近的垂直淡入淡出线。此外,如果您只想模糊那个圆圈,您必须在该区域周围找到感兴趣区域 (ROI),然后对其进行模糊处理。
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
data = pd.read_csv("data9.csv").to_numpy()
plt.subplot(2, 3, 1)
plt.imshow(data, cmap="viridis", vmin=0, vmax=40)
plt.title("Original")
# Average 3 elements
filter = np.ones(3)
for line in range(data.shape[0]):
data[line] = np.convolve(data[line], filter, mode="same")/np.sum(filter)
plt.subplot(2, 3, 2)
plt.imshow(data, cmap="viridis", vmin=0, vmax=40)
plt.title("Avg3")
# Average 5 elements
filter = np.ones(5)
for line in range(data.shape[0]):
data[line] = np.convolve(data[line], filter, mode="same")/np.sum(filter)
plt.subplot(2, 3, 3)
plt.imshow(data, cmap="viridis", vmin=0, vmax=40)
plt.title("Avg5")
# Average 7 elements
filter = np.ones(7)
for line in range(data.shape[0]):
data[line] = np.convolve(data[line], filter, mode="same")/np.sum(filter)
plt.subplot(2, 3, 4)
plt.imshow(data, cmap="viridis", vmin=0, vmax=40)
plt.title("Avg7")
# Average 3 elements with emphasis on central element
filter = np.array([1, 2, 1])
for line in range(data.shape[0]):
data[line] = np.convolve(data[line], filter, mode="same")/np.sum(filter)
plt.subplot(2, 3, 5)
plt.imshow(data, cmap="viridis", vmin=0, vmax=40)
plt.title("Avg3 Emphasis")
# Average 5 elements with emphasis on central element
filter = np.array([1, 1, 2, 1, 1])
for line in range(data.shape[0]):
data[line] = np.convolve(data[line], filter, mode="same")/np.sum(filter)
plt.subplot(2, 3, 6)
plt.imshow(data, cmap="viridis", vmin=0, vmax=40)
plt.title("Avg5 Emphasis")
plt.tight_layout()
plt.show()
水平轴上的模糊数据: