-
Notifications
You must be signed in to change notification settings - Fork 282
/
Copy pathtutorial23_reading_proprietary_images_into_python.py
120 lines (86 loc) · 3.3 KB
/
tutorial23_reading_proprietary_images_into_python.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#Video Playlist: https://www.youtube.com/playlist?list=PLHae9ggVvqPgyRQQOtENr6hK0m1UquGaG
#Reading standard image formats is easy, especially JPG, PNG and normal Tif files.
from skimage import io
img = io.imread("images/Osteosarcoma_01.tif", as_gray=True)
import cv2
grey_img = cv2.imread("images/Osteosarcoma_01.tif", 0)
color_img = cv2.imread("images/Osteosarcoma_01.tif", 1)
"""
Tiff files.... especially multidimensional tiff files.
Use tifffile
pip install tifffile
"""
import tifffile
#RGB images
img = tifffile.imread("images/Osteosarcoma_01.tif")
import numpy as np
print(np.shape(img))
#3D image
img1 = tifffile.imread("images/3d_nuclei_image_8bit.tif")
#Time series images
img2 = tifffile.imread("images/Scratch_Assay_400_289_8bit.tif")
"""
####################################################################################
#reading czi files
# pip install czifile
# to import the package you need to use import czifile
# https://pypi.org/project/czifile/
"""
################################
import czifile
img = czifile.imread('images/Osteosarcoma_01.czi')
#img = czifile.imread('images/Scratch_Assay_400_289.czi')
print(img.shape) #7 dimensions
#Time series, scenes, channels, y, x, z, RGB
#IN this example (Osteosarcoma) we have 1 time series, 1 scene, 3 channels and each channel grey image
#size 1376 x 1104
#Let us extract only relevant pixels, all channels in x and y
img1=img[0, 0, :, :, :, 0]
print(img1.shape)
#Next, let us extract each channel image.
img2=img1[0,:,:] #First channel, Red
img3=img1[1,:,:] #Second channel, Green
img4=img1[2,:,:] #Third channel, Blue DAPI
from matplotlib import pyplot as plt
fig = plt.figure(figsize=(10, 10))
ax1 = fig.add_subplot(2,2,1)
ax1.imshow(img2, cmap='hot')
ax1.title.set_text('1st channel')
ax2 = fig.add_subplot(2,2,2)
ax2.imshow(img3, cmap='hot')
ax2.title.set_text('2nd channel')
ax3 = fig.add_subplot(2,2,3)
ax3.imshow(img4, cmap='hot')
ax3.title.set_text('3rd channel')
plt.show()
#Olympus images, similar way https://pypi.org/project/oiffile/
###########Reading OME-TIFF using apeer_ometiff_library ###########
# pip install apeer-ometiff-library first
# to import the package you need to use import apeer_ometiff_library
#OME-TIFF has tiff and metada (as XML) embedded
#Image is a 5D array.
from apeer_ometiff_library import io #Use apeer.com free platform for image processing in the cloud
(pic2, omexml) = io.read_ometiff("images/Osteosarcoma_01_8bit.ome.tiff") #Unwrap image and embedded xml metadata
print (pic2.shape) #to verify the shape of the array
print(pic2)
print(omexml)
#Let us extract only relevant pixels, all channels in x and y
img1=img[0, 0, :, :, :, 0]
print(img1.shape)
#Next, let us extract each channel image.
img2=img1[0,:,:] #First channel, Red
img3=img1[1,:,:] #Second channel, Green
img4=img1[2,:,:] #Third channel, Blue
from matplotlib import pyplot as plt
fig = plt.figure(figsize=(10, 10))
ax1 = fig.add_subplot(2,2,1)
ax1.imshow(img2, cmap='hot')
ax1.title.set_text('1st channel')
ax2 = fig.add_subplot(2,2,2)
ax2.imshow(img3, cmap='hot')
ax2.title.set_text('2nd channel')
ax3 = fig.add_subplot(2,2,3)
ax3.imshow(img4, cmap='hot')
ax3.title.set_text('3rd channel')
plt.show()
##################################