SusiePHaltmann commited on
Commit
fe25407
·
1 Parent(s): 5249c9e

Request to upload 5.31.22 #1.5

Browse files
Files changed (1) hide show
  1. app.py +14 -16
app.py CHANGED
@@ -1,22 +1,20 @@
1
-
2
- import sys
3
  import streamlit as st
 
 
4
 
 
 
 
 
5
 
6
- st.title("Haltmannn Diffusion")
7
- st.markdown("This app simulates the diffusion of particles in a 2D square lattice with periodic boundary conditions, using the Haltmannn algorithm.")
8
 
9
- L = 10 #lattice size
10
- N = st.slider("Number of particles", 1, L**2/2, 10) #number of particles
11
- st.write("Particle number is: ", N)
12
- #initialize the system: create a list of 'particle' objects, each with random position and velocity vectors:
13
 
14
- import streamlit as st
15
- import numpy as np
 
 
 
16
 
17
- L = 10 #lattice size
18
- N = st.slider("Number of particles", 1, L**2/2, 10) #number of particles
19
- st.write("Particle configuration:")
20
- particles = np.random.randint(0, L, (N, 2)) #particle positions
21
- st.write(particles)
22
- st.title("Haltmannn Diffusion [C] 20XX")
 
 
 
1
  import streamlit as st
2
+ import numpy as np
3
+ from PIL import Image
4
 
5
+ def main():
6
+ st.title("Haltmann Diffusion Algorithm")
7
+
8
+ slider = st.slider("Slider", 0, 255, 128) # default value=128, min=0, max=255
9
 
10
+ algo = np.array([[0, 0, 0], [0, 1/3, 1/3], [0, 1/3, 2/3]])
 
11
 
12
+ image = Image.open('image.png') # your image here
 
 
 
13
 
14
+ pixels = np.array(image)
15
+
16
+ for i in range(pixels.shape[0]): # iterate over the rows of the image matrix (height) for j in range(pixels.shape[1]): # iterate over the columns of the image matrix (width) for k in range(pixels.shape[2]): # iterate over the color channels (RGB) if pixels[i][j][k] > slider: pixels[i][j][k] = int((algo @ np.array([pixels[i-1][j-1][k], pixels[i-1][j+1][k], pixels[i+1][j-1][k]]).T)[2]) else: continue
17
+
18
+ new_image = Image.fromarray(pixels)
19
 
20
+ st.image(new_image , caption='Output Image', use_column_width=True) if __name__ == '__main__': main()