-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcustom_utils.py
59 lines (55 loc) · 1.65 KB
/
custom_utils.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
"""
Artery Vein Network (AV-Net).
This file is stores several utility functions, namely:
- load_multichannel_image
@author: dleninja, mansour2002
"""
#
import tensorflow as tf
#
import numpy as np
import pandas as pd
import os
from skimage import img_as_float, transform, exposure, io, color
from pathlib import Path
from matplotlib import image
import matplotlib.pyplot as plt
import cv2
#
def load_multichannel_image(df, im_shape, path_list, column):
"""
Custom multi-channal image reader.
Args:
df: dataframe, contains the image name with extension, e.g. "image001.png"
im_shape: tuple, containing the height and width of the images.
path_list: list of Paths, for all the different directories containing the different inputs.
column: integer, the specific column to read the dataframe from.
Returns:
Outputs a multi-dimension array, of size (len(df), im_shape[0], im_shape[1], len(path_list)).
"""
#
images = []
n_channels = len(path_list)
#
for i, item in df.iterrows():
#
image = np.zeros([im_shape[0], im_shape[1], n_channels])
#
for j in range(n_channels):
temp_item = path_list[j] / item[column]
temp_image = io.imread(temp_item)
temp_image = temp_image / 255
#
if j == 0:
temp_im_shape = temp_image.shape
#
image[0:temp_im_shape[0],0:temp_im_shape[1],j] = temp_image
#
#
images.append(image)
#
images = np.array(images)
print(' --- Images loaded --- ');
print('\t{}'.format(images.shape))
#
return images