-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage_database.py
714 lines (549 loc) · 28.5 KB
/
image_database.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
import numpy as np
import keras.backend as K
import keras
import h5py
from keras.applications import imagenet_utils
class ImageDatabase:
def __init__(self, images, labels, patch_labels=None, segs=None, image_names=None, boundary_names=None,
area_names=None, patch_class_names=None, fullsize_class_names=None,
image_range=None, filename=None, name=None, num_classes=None,
dim_inds=None, dim_names=None, mode_type=None, set=None, padding=None, dim_ordering=None, ram_load=1, reps_channels=None,
imagenet=False, open_filename=None, imdb1=None, imdb2=None):
self.images = images
self.labels = labels
self.patch_labels = patch_labels
self.image_names = image_names
self.boundary_names = boundary_names
self.area_names = area_names
self.patch_class_names = patch_class_names
self.fullsize_class_names = fullsize_class_names
self.segs = segs
if filename is not None:
self.filename = filename.split("/")[-1]
else:
self.filename = filename
self.name = name
self.num_classes = num_classes
self.ram_load = ram_load
self.open_filename = open_filename
self.reps_channels = reps_channels
self.imdb1 = imdb1
self.imdb2 = imdb2
if self.images is None:
self.num_images = self.imdb1.num_images + self.imdb2.num_images
self.image_width = self.imdb1.image_width
self.image_height = self.imdb1.image_height
if self.reps_channels is not None:
self.num_channels = self.imdb1.num_channels * self.reps_channels
else:
self.num_channels = self.imdb1.num_channels
self.labels_shape = self.imdb1.labels_shape
else:
if ram_load == 0:
loadfile = h5py.File(self.open_filename, 'r')
fileimages = loadfile["images"]
self.num_images = fileimages.shape[0]
self.image_width = fileimages.shape[1]
self.image_height = fileimages.shape[2]
if self.reps_channels is not None:
self.num_channels = fileimages.shape[3] * self.reps_channels
else:
self.num_channels = fileimages.shape[3]
filelabels = loadfile["labels"]
if self.labels is not None:
self.labels_shape = list(filelabels.shape)
loadfile.close()
else:
self.num_images = images.shape[0]
self.image_width = images.shape[1]
self.image_height = images.shape[2]
self.num_channels = images.shape[3]
if self.labels is not None:
self.labels_shape = list(self.labels.shape)
if ram_load == 0 and padding is not None:
self.image_width = self.image_width + padding[1][0] + padding[1][1]
self.image_height = self.image_height + padding[2][0] + padding[2][1]
self.dim_inds = dim_inds
self.dim_names = dim_names
self.type = mode_type
self.set = set
self.padding = padding
if self.dim_inds is not None:
self.ind_name = ""
dim_count = 0
for dim_name in dim_names:
if self.dim_inds[dim_count] is not None:
self.ind_name += "_" + dim_name + ": " + str(self.dim_inds[dim_count])
else:
self.ind_name = "_allinds"
self.image_range = image_range
if self.image_range is None:
self.image_range = range(self.num_images)
self.start_image_ind = self.image_range[0]
self.end_image_ind = self.image_range[-1] + 1
self.num_images = self.end_image_ind - self.start_image_ind
self.dim_ordering = dim_ordering
if self.labels is not None:
if mode_type == 'fullsize':
if self.dim_ordering == 'channels_last':
self.labels_shape[3] = self.num_classes
elif self.dim_ordering == 'channels_first':
self.labels_shape[1] = self.num_classes
if self.ram_load == 0 and self.padding is not None:
if self.dim_ordering == 'channels_last':
self.labels_shape[1] = self.labels_shape[1] + self.padding[1][0] + self.padding[1][1]
self.labels_shape[2] = self.labels_shape[2] + self.padding[2][0] + self.padding[2][1]
elif self.dim_ordering == 'channels_last':
self.labels_shape[2] = self.labels_shape[2] + self.padding[2][0] + self.padding[2][1]
self.labels_shape[3] = self.labels_shape[3] + self.padding[3][0] + self.padding[3][1]
elif mode_type == 'patch':
print(self.labels_shape)
self.labels_shape[1] = self.num_classes
self.labels_shape = tuple(self.labels_shape)
self.imagenet = imagenet
if self.ram_load == 1 and self.imagenet is True:
self.images = imagenet_utils.preprocess_input(self.images, data_format=None, mode='tf')
def get_image_names_range(self):
if self.image_names is not None:
return self.image_names[self.start_image_ind:self.end_image_ind]
else:
return None
def get_images_subrange_disk(self, a, b):
loadfile = h5py.File(self.open_filename, 'r')
fileimages = loadfile["images"]
if b is not None and a is not None:
images = fileimages[self.start_image_ind + a:self.start_image_ind + a + b]
elif a is not None:
images = fileimages[self.start_image_ind + a:self.end_image_ind]
elif b is not None:
images = fileimages[self.start_image_ind:self.end_image_ind + b]
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
images = np.transpose(images, axes=(0, 2, 3, 1))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
images = np.transpose(images, axes=(0, 3, 1, 2))
if self.padding is not None:
images = np.pad(images, self.padding, mode='constant')
if self.reps_channels is not None:
if self.dim_ordering == 'channels_first':
images = np.repeat(images, self.reps_channels, axis=1)
elif self.dim_ordering == 'channels_last':
images = np.repeat(images, self.reps_channels, axis=3)
if self.imagenet is True:
images = imagenet_utils.preprocess_input(images, data_format=None, mode='tf')
loadfile.close()
return images
def get_labels_subrange_disk(self, a, b):
loadfile = h5py.File(self.open_filename, 'r')
filelabels = loadfile["labels"]
if b is not None and a is not None:
labels = filelabels[self.start_image_ind + a:self.start_image_ind + a + b]
elif a is not None:
labels = filelabels[self.start_image_ind + a:self.end_image_ind]
elif b is not None:
labels = filelabels[self.start_image_ind:self.start_image_ind + b]
if self.type == "fullsize":
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
labels = np.transpose(labels, axes=(0, 2, 3, 1))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
labels = np.transpose(labels, axes=(0, 3, 1, 2))
if self.padding is not None:
labels = np.pad(labels, self.padding, mode='constant')
labels = keras.utils.to_categorical(labels, num_classes=self.num_classes)
loadfile.close()
return labels
def get_images_range(self):
if self.images is None:
num_images1 = self.imdb1.num_images
num_images2 = self.imdb2.num_images
if self.start_image_ind < num_images1 and self.end_image_ind < num_images1:
images = self.imdb1.get_images_subrange_disk()[self.start_image_ind:self.end_image_ind]
elif self.start_image_ind < num_images1 and self.end_image_ind >= num_images1:
images = np.concatenate(self.imdb1.get_images_subrange_disk(self.start_image_ind, None), self.imdb2.get_images_subrange_disk(None, self.end_image_ind - num_images1), axis=0)
else:
images = self.imdb2.get_images_subrange_disk(self.start_image_ind - num_images1, self.end_image_ind - num_images1)
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
images = np.transpose(images, axes=(0, 2, 3, 1))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
images = np.transpose(images, axes=(0, 3, 1, 2))
if self.padding is not None:
images = np.pad(images, self.padding, mode='constant')
if self.reps_channels is not None:
if self.dim_ordering == 'channels_first':
images = np.repeat(images, self.reps_channels, axis=1)
elif self.dim_ordering == 'channels_last':
images = np.repeat(images, self.reps_channels, axis=3)
if self.imagenet is True:
images = imagenet_utils.preprocess_input(images, data_format=None, mode='tf')
return images
else:
if self.ram_load == 1:
return self.images[self.start_image_ind:self.end_image_ind]
else:
loadfile = h5py.File(self.open_filename, 'r')
fileimages = loadfile["images"]
images = fileimages[self.start_image_ind:self.end_image_ind]
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
images = np.transpose(images, axes=(0, 2, 3, 1))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
images = np.transpose(images, axes=(0, 3, 1, 2))
if self.padding is not None:
images = np.pad(images, self.padding, mode='constant')
if self.reps_channels is not None:
if self.dim_ordering == 'channels_first':
images = np.repeat(images, self.reps_channels, axis=1)
elif self.dim_ordering == 'channels_last':
images = np.repeat(images, self.reps_channels, axis=3)
if self.imagenet is True:
images = imagenet_utils.preprocess_input(images, data_format=None, mode='tf')
loadfile.close()
return images
def get_labels_range(self):
if self.labels is not None:
if self.images is None:
num_labels1 = self.imdb1.num_images
num_labels2 = self.imdb2.num_images
if self.start_image_ind < num_labels1 and self.end_image_ind < num_labels1:
labels = self.imdb1.get_labels_subrange_disk(self.start_image_ind, self.end_image_ind)
elif self.start_image_ind < num_labels1 and self.end_image_ind >= num_labels1:
labels = np.concatenate(self.imdb1.get_labels_subrange_disk(self.start_image_ind, None),
self.imdb2.get_labels_subrange_disk(None, self.end_image_ind - num_labels1), axis=0)
else:
labels = self.imdb2.get_labels_subrange_disk(self.start_image_ind - num_labels1, self.end_image_ind - num_labels1)
if self.type == "fullsize":
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
labels = np.transpose(labels, axes=(0, 2, 3, 1))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
labels = np.transpose(labels, axes=(0, 3, 1, 2))
if self.padding is not None:
labels = np.pad(labels, self.padding, mode='constant')
labels = keras.utils.to_categorical(labels, num_classes=self.num_classes)
return labels
else:
if self.ram_load == 1:
return self.labels[self.start_image_ind:self.end_image_ind]
else:
loadfile = h5py.File(self.open_filename, 'r')
filelabels = loadfile["labels"]
labels = filelabels[self.start_image_ind:self.end_image_ind]
if self.type == "fullsize":
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
labels = np.transpose(labels, axes=(0, 2, 3, 1))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
labels = np.transpose(labels, axes=(0, 3, 1, 2))
if self.padding is not None:
labels = np.pad(labels, self.padding, mode='constant')
labels = keras.utils.to_categorical(labels, num_classes=self.num_classes)
loadfile.close()
return labels
else:
return None
def get_patch_labels_range(self):
if self.patch_labels is not None:
if self.ram_load == 1:
return self.patch_labels[self.start_image_ind:self.end_image_ind]
else:
loadfile = h5py.File(self.open_filename, 'r')
filepatchlabels = loadfile["patch_labels"]
patch_labels = filepatchlabels[self.start_image_ind:self.end_image_ind]
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
patch_labels = np.transpose(patch_labels, axes=(0, 2, 3, 1))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
patch_labels = np.transpose(patch_labels, axes=(0, 3, 1, 2))
if self.padding is not None:
patch_labels = np.pad(patch_labels, self.padding, mode='constant')
loadfile.close()
return patch_labels
else:
return None
def get_segs_range(self):
if self.segs is not None:
if self.ram_load == 1:
return self.segs[self.start_image_ind:self.end_image_ind]
else:
loadfile = h5py.File(self.open_filename, 'r')
filesegs = loadfile["segs"]
segs = filesegs[self.start_image_ind:self.end_image_ind]
if self.padding is not None:
segs[segs != 0] = segs[segs != 0] + self.padding[2][0]
loadfile.close()
return segs
else:
return None
def get_image_range(self, ind):
if self.images is None:
num_images1 = self.imdb1.num_images
num_images2 = self.imdb2.num_images
if ind + self.start_image_ind < num_images1:
image = self.imdb1.get_image_range(ind + self.start_image_ind)
else:
image = self.imdb2.get_image_range(ind + self.start_image_ind - num_images1)
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
image = np.transpose(image, axes=(1, 2, 0))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
image = np.transpose(image, axes=(2, 0, 1))
if self.padding is not None:
image = np.pad(image, self.padding[1:], mode='constant')
if self.reps_channels is not None:
if self.dim_ordering == 'channels_first':
image = np.repeat(image, self.reps_channels, axis=1)
elif self.dim_ordering == 'channels_last':
image = np.repeat(image, self.reps_channels, axis=3)
if self.imagenet is True:
image = imagenet_utils.preprocess_input(image, data_format=None, mode='tf')
return image
else:
if self.ram_load == 1:
return self.images[ind + self.start_image_ind]
else:
loadfile = h5py.File(self.open_filename, 'r')
fileimages = loadfile["images"]
image = fileimages[ind + self.start_image_ind]
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
image = np.transpose(image, axes=(1, 2, 0))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
image = np.transpose(image, axes=(2, 0, 1))
if self.padding is not None:
image = np.pad(image, self.padding[1:], mode='constant')
if self.reps_channels is not None:
if self.dim_ordering == 'channels_first':
image = np.repeat(image, self.reps_channels, axis=1)
elif self.dim_ordering == 'channels_last':
image = np.repeat(image, self.reps_channels, axis=3)
if self.imagenet is True:
image = imagenet_utils.preprocess_input(image, data_format=self.dim_ordering, mode='tf')
loadfile.close()
return image
def get_patch_label(self, ind):
if self.patch_labels is not None:
if self.ram_load == 1:
return self.patch_labels[ind]
else:
loadfile = h5py.File(self.open_filename, 'r')
filepatchlabels = loadfile["patch_labels"]
patch_label = filepatchlabels[ind]
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
patch_label = np.transpose(patch_label, axes=(1, 2, 0))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
patch_label = np.transpose(patch_label, axes=(2, 0, 1))
if self.padding is not None:
patch_label = np.pad(patch_label, self.padding[1:], mode='constant')
loadfile.close()
return patch_label
else:
return None
def get_patch_label_range(self, ind):
if self.patch_labels is not None:
if self.ram_load == 1:
return self.patch_labels[ind + self.start_image_ind]
else:
loadfile = h5py.File(self.open_filename, 'r')
filepatchlabels = loadfile["patch_labels"]
patch_label = filepatchlabels[ind + self.start_image_ind]
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
patch_label = np.transpose(patch_label, axes=(1, 2, 0))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
patch_label = np.transpose(patch_label, axes=(2, 0, 1))
if self.padding is not None:
patch_label = np.pad(patch_label, self.padding[1:], mode='constant')
loadfile.close()
return patch_label
else:
return None
def get_image(self, ind):
if self.images is None:
num_images1 = self.imdb1.num_images
num_images2 = self.imdb2.num_images
if ind < num_images1:
image = self.imdb1.get_image(ind)
else:
image = self.imdb2.get_image(ind - num_images1)
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
image = np.transpose(image, axes=(1, 2, 0))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
image = np.transpose(image, axes=(2, 0, 1))
if self.padding is not None:
image = np.pad(image, self.padding[1:], mode='constant')
if self.reps_channels is not None:
if self.dim_ordering == 'channels_first':
image = np.repeat(image, self.reps_channels, axis=1)
elif self.dim_ordering == 'channels_last':
image = np.repeat(image, self.reps_channels, axis=3)
if self.imagenet is True:
image = imagenet_utils.preprocess_input(image, data_format=None, mode='tf')
return image
else:
if self.ram_load == 1:
return self.images[ind]
else:
loadfile = h5py.File(self.open_filename, 'r')
fileimages = loadfile["images"]
image = fileimages[ind]
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
image = np.transpose(image, axes=(1, 2, 0))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
image = np.transpose(image, axes=(2, 0, 1))
if self.padding is not None:
print(image.shape)
print(self.padding[1:])
image = np.pad(image, self.padding[1:], mode='constant')
if self.reps_channels is not None:
if self.dim_ordering == 'channels_first':
image = np.repeat(image, self.reps_channels, axis=0)
elif self.dim_ordering == 'channels_last':
image = np.repeat(image, self.reps_channels, axis=2)
if self.imagenet is True:
image = imagenet_utils.preprocess_input(image, data_format=None, mode='tf')
loadfile.close()
return image
def get_label(self, ind):
if self.labels is not None:
if self.images is None:
num_labels1 = self.imdb1.num_images
num_labels2 = self.imdb2.num_images
if ind < num_labels1:
label = self.imdb1.get_label(ind)
else:
label = self.imdb2.get_label(ind - num_labels1)
if self.type == "fullsize":
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
label = np.transpose(label, axes=(1, 2, 0))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
label = np.transpose(label, axes=(2, 0, 1))
if self.padding is not None:
label = np.pad(label, self.padding[1:], mode='constant')
label = keras.utils.to_categorical(label, num_classes=self.num_classes)
return label
else:
if self.ram_load == 1:
return self.labels[ind]
else:
loadfile = h5py.File(self.open_filename, 'r')
filelabels = loadfile["labels"]
label = filelabels[ind]
if self.type == "fullsize":
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
label = np.transpose(label, axes=(1, 2, 0))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
label = np.transpose(label, axes=(2, 0, 1))
if self.padding is not None:
label = np.pad(label, self.padding[1:], mode='constant')
label = keras.utils.to_categorical(label, num_classes=self.num_classes)
loadfile.close()
return label
else:
return None
def get_label_range(self, ind):
if self.labels is not None:
if self.images is None:
num_labels1 = self.imdb1.num_images
num_labels2 = self.imdb2.num_images
if ind + self.image_range < num_labels1:
label = self.imdb1.get_label_range(ind + self.image_range)
else:
label = self.imdb2.get_label_range(ind + self.image_range - num_labels1)
if self.type == "fullsize":
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
label = np.transpose(label, axes=(1, 2, 0))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
label = np.transpose(label, axes=(2, 0, 1))
if self.padding is not None:
label = np.pad(label, self.padding[1:], mode='constant')
label = keras.utils.to_categorical(label, num_classes=self.num_classes)
return label
else:
if self.ram_load == 1:
return self.labels[ind + self.start_image_ind]
else:
loadfile = h5py.File(self.open_filename, 'r')
filelabels = loadfile["labels"]
label = filelabels[ind + self.start_image_ind]
if self.type == "fullsize":
if K.image_dim_ordering() == 'tf' and self.dim_ordering == 'channels_first':
label = np.transpose(label, axes=(1, 2, 0))
elif K.image_dim_ordering() == 'th' and self.dim_ordering == 'channels_last':
label = np.transpose(label, axes=(2, 0, 1))
if self.padding is not None:
label = np.pad(label, self.padding[1:], mode='constant')
label = keras.utils.to_categorical(label, num_classes=self.num_classes)
loadfile.close()
return label
else:
return None
def get_seg(self, ind):
if self.segs is not None:
if self.ram_load == 1:
return self.segs[ind]
else:
loadfile = h5py.File(self.open_filename, 'r')
filesegs = loadfile["segs"]
seg = filesegs[ind]
if self.padding is not None:
seg[seg != 0] = seg[seg != 0] + self.padding[2][0]
loadfile.close()
return seg
else:
return None
def get_seg_range(self, ind):
if self.segs is not None:
if self.ram_load == 1:
return self.segs[ind + self.start_image_ind]
else:
loadfile = h5py.File(self.open_filename, 'r')
filesegs = loadfile["segs"]
seg = filesegs[ind + self.start_image_ind]
if self.padding is not None:
seg[seg != 0] = seg[seg != 0] + self.padding[2][0]
loadfile.close()
return seg
else:
return None
def get_image_name(self, ind):
if self.image_names is not None:
return self.image_names[ind]
else:
return None
def get_image_name_range(self, ind):
if self.image_names is not None:
return self.image_names[ind + self.start_image_ind]
else:
return None
def get_boundary_names(self):
if self.boundary_names is not None:
return self.boundary_names[:]
else:
return None
def get_boundary_name(self, ind):
if self.boundary_names is not None:
return self.boundary_names[ind]
else:
return None
def get_area_names(self):
if self.area_names is not None:
return self.area_names[:]
else:
return None
def get_area_name(self, ind):
if self.area_names is not None:
return self.area_names[ind]
else:
return None
def get_patch_class_names(self):
if self.patch_class_names is not None:
return self.patch_class_names[:]
else:
return None
def get_patch_class_name(self, ind):
if self.patch_class_names is not None:
return self.patch_class_names[ind]
else:
return None
def get_fullsize_class_names(self):
if self.fullsize_class_names is not None:
return self.fullsize_class_names[:]
else:
return None
def get_fullsize_class_name(self, ind):
if self.fullsize_class_names is not None:
return self.fullsize_class_names[ind]
else:
return None