forked from bnsreenu/python_for_image_processing_APEER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial20_functions.py
56 lines (35 loc) · 1.29 KB
/
tutorial20_functions.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
#Video Playlist: https://www.youtube.com/playlist?list=PLHae9ggVvqPgyRQQOtENr6hK0m1UquGaG
"""
Functions
"""
def my_function():
print("Hello from inside a function")
#Now we are outside the function
my_function() #When you call the function it executes it including print
#You can provide inputs to functions
def my_function(your_name="Michael"): #Michael is the default value in case nothing is provided
print("Your name is: ", your_name)
#Now we are outside the function
my_function("John")
my_function("Mary")
my_function()
#Iterate through lists from inside a function
def my_microscopes(mic):
for x in mic:
print(x)
mic = ["AxioImager", "Elyra", "LSM", "GeminiSEM", "Versa"]
my_microscopes(mic)
#Returning values
#When the function is done executing it can return values.
def add_numbers(a,b):
return a+b
print(add_numbers(5,3))
#Let us write a function to perform Gaussian smoothing
from skimage import io, filters
from matplotlib import pyplot as plt
def gaussian_of_img(img, sigma=1):
gaussian_img = filters.gaussian(img, sigma)
return(gaussian_img)
my_image = io.imread('images/Osteosarcoma_01_8bit_salt_pepper_cropped.tif')
filtered = gaussian_of_img(my_image, 3)
plt.imshow(filtered)