-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathData_loading.py
More file actions
46 lines (38 loc) · 1.48 KB
/
Data_loading.py
File metadata and controls
46 lines (38 loc) · 1.48 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
38
39
40
41
42
43
44
45
46
import numpy as np
from skimage.io import imread
def read_mg(file_paths, img_rows, img_cols, as_gray, channels):
"""
Read the image files (mammography) and normalize the pixel values
@params:
file_paths - Array of file paths to read from
img_rows - The image height.
img_cols - The image width.
as_grey - Read the image as Greyscale.
channels - Number of channels.
"""
images=[]
for file_path in file_paths:
images.append(imread(file_path, as_gray))
images = np.asarray(images, dtype=np.float32)
images = np.stack((images,)*3, axis=-1)
images = (images-images.min())/(images.max()-images.min())
images = images.reshape(images.shape[0], img_rows, img_cols, channels)
return images
def read_us(file_paths, img_rows, img_cols, as_gray, channels):
"""
Reads the image files (ultrasound) and normalize the pixel values
@params:
file_paths - Array of file paths to read from
img_rows - The image height.
img_cols - The image width.
as_grey - Read the image as Greyscale.
channels - Number of channels.
"""
images=[]
for file_path in file_paths:
images.append(imread(file_path, as_gray))
images = np.asarray(images, dtype=np.float32)
images = np.stack((images,)*3, axis=-1)
images = (images-images.min())/(images.max()-images.min())
images = images.reshape(images.shape[0], img_rows, img_cols, channels)
return images