-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiff_reader_and_movie_player.py
More file actions
37 lines (30 loc) · 1.01 KB
/
Copy pathtiff_reader_and_movie_player.py
File metadata and controls
37 lines (30 loc) · 1.01 KB
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
35
36
37
import numpy as np
import tifffile as tiff
import matplotlib.pyplot as plt
# Load the TIFF file
filename = '' #place path to file here
# Load the TIFF file
tif = tiff.TiffFile(filename)
# Get the dimensions of the image
images = tif.asarray()
frames = images.shape[0]
max_height = max(image.shape[0] for image in images)
max_width = max(image.shape[1] for image in images)
# Create the movie matrix with maximum dimensions
movie = np.zeros((max_height, max_width, frames), dtype=np.uint16)
# Populate the movie matrix with the image data, adjusting frame sizes if necessary
for i in range(frames):
height, width = images[i].shape
movie[:height, :width, i] = images[i]
# Close the TIFF file
tif.close()
# Display the movie frames
plt.ion() # Turn on interactive mode for real-time updating
fig, ax = plt.subplots()
for i in range(frames):
ax.clear()
ax.imshow(movie[:, :, i], cmap='gray')
plt.draw()
plt.pause(0.001) # Pause to create a movie effect
plt.ioff() # Turn off interactive mode
plt.show()