-
Notifications
You must be signed in to change notification settings - Fork 3
/
dataval.py
68 lines (54 loc) · 2.03 KB
/
dataval.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Oct 15 10:00:09 2018
@author: ck807
"""
import os, glob
import cv2
import numpy as np
from keras.preprocessing.image import img_to_array
#from keras.preprocessing.image import img_to_array, load_img
#def scaleRadius(img,scale):
# x=img[int(img.shape[0]/2),:,:].sum(1)
# r=(x>x.mean()/10).sum()/2
# s=scale*1.0/r
# return cv2.resize(img,(0,0),fx=s,fy=s)
#scale = 300
image_length = 256
image_height = 256
num_channels = 3
i = 0
data_file = glob.glob('/home/ck807/melenoma_seg/ISIC-2017_Validation_Data/*.jpg')
files = []
data_file_mask = glob.glob('/home/ck807/melenoma_seg/ISIC-2017_Validation_Part1_GroundTruth/*.png')
trainData = np.zeros((len(data_file),image_length, image_height, num_channels))
def rgb2gray(rgb):
return np.dot(rgb[...,:3], [0.299, 0.587, 0.114])
trainLabel = np.zeros((len(data_file_mask),image_length,image_height,1))
for f in (data_file):
a=cv2.imread(f)
# a=scaleRadius(a,scale)
# b=np.zeros(a.shape)
# b=b.astype(np.uint8)
# cv2.circle(b,(int(a.shape[1]/2),int(a.shape[0]/2)),int(scale*0.9),(1,1,1),-1,8,0)
# aa=cv2.addWeighted(a,4,cv2.GaussianBlur(a,(0,0),scale/30),-4,128)*b+128*(1-b)
resized_image = cv2.resize(a, (image_length, image_height))
resized_image = resized_image.astype(np.float64)
trainData[i,:,:,:] = resized_image[:,:,:]
base = os.path.basename("/home/ck807/melenoma_seg/ISIC-2017_Validation_Data/" + f)
fileName = os.path.splitext(base)[0]
files.append(fileName)
i += 1
for k in (data_file_mask):
base = os.path.basename("/home/ck807/melenoma_seg/ISIC-2017_Validation_Part1_GroundTruth/" + k)
fileName = os.path.splitext(base)[0]
fileName = fileName[0:12]
index = files.index(fileName)
image = cv2.imread(k)
gray = rgb2gray(image)
resized_image = cv2.resize(gray, (256, 256))
gray_image = img_to_array(resized_image)
trainLabel[index, :, :, :] = gray_image[:, :, :]
np.save('dataval.npy',trainData)
np.save('dataMaskval.npy', trainLabel)