File size: 985 Bytes
135cad5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import streamlit as st
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider
from scipy.ndimage import gaussian_filter
from sklearn.decomposition import PCA

# Dummy PCA Data - Replace with actual PCA-transformed data
h, w, d = 100, 100, 4  # Example shape
pc_data = np.random.rand(h, w, d)

# Streamlit UI
st.title("Interactive PCA Visualization")

# Sliders for PC Weights
pc1_weight = st.slider("PC1 Weight", -1.0, 1.0, 0.0, 0.02)
pc2_weight = st.slider("PC2 Weight", -1.0, 1.0, 0.0, 0.02)
pc3_weight = st.slider("PC3 Weight", -1.0, 1.0, 0.0, 0.02)
pc4_weight = st.slider("PC4 Weight", -1.0, 1.0, 0.0, 0.02)

# Generate Image
composite_image = (
    pc1_weight * pc_data[:, :, 0] +
    pc2_weight * pc_data[:, :, 1] +
    pc3_weight * pc_data[:, :, 2] +
    pc4_weight * pc_data[:, :, 3]
)
composite_image = gaussian_filter(composite_image, sigma=1)

# Display Image
fig, ax = plt.subplots()
ax.imshow(composite_image, cmap="gray")
st.pyplot(fig)