From ffb6b9f2bda8eda074b1d1730d51b3035adc9475 Mon Sep 17 00:00:00 2001 From: Edoardo Pasca Date: Thu, 9 May 2019 17:03:36 +0100 Subject: Added loader with number of test images --- Wrappers/Python/ccpi/framework/TestData.py | 65 ++++++++++++++++++++++-------- Wrappers/Python/setup.py | 3 +- 2 files changed, 51 insertions(+), 17 deletions(-) (limited to 'Wrappers') diff --git a/Wrappers/Python/ccpi/framework/TestData.py b/Wrappers/Python/ccpi/framework/TestData.py index 61ed4df..45ee1d4 100755 --- a/Wrappers/Python/ccpi/framework/TestData.py +++ b/Wrappers/Python/ccpi/framework/TestData.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -from ccpi.framework import ImageData +from ccpi.framework import ImageData, ImageGeometry import numpy from PIL import Image import os @@ -14,29 +14,62 @@ class TestData(object): BOAT = 'boat.tiff' CAMERA = 'camera.png' PEPPERS = 'peppers.tiff' + RESOLUTION_CHART = 'resolution_chart.tiff' + SIMPLE_PHANTOM_2D = 'simple_jakobs_phantom' def __init__(self, **kwargs): self.data_dir = kwargs.get('data_dir', data_dir) def load(self, which, size=(512,512), scale=(0,1), **kwargs): - if which not in [TestData.BOAT, TestData.CAMERA, TestData.PEPPERS]: + if which not in [TestData.BOAT, TestData.CAMERA, + TestData.PEPPERS, TestData.RESOLUTION_CHART, + TestData.SIMPLE_PHANTOM_2D]: raise ValueError('Unknown TestData {}.'.format(which)) - tmp = Image.open(os.path.join(data_dir, which)) - - data = numpy.array(tmp.resize(size)) - - if scale is not None: - dmax = data.max() - dmin = data.min() - - data = data -dmin / (dmax - dmin) + if which == TestData.SIMPLE_PHANTOM_2D: + N = size[0] + M = size[1] + sdata = numpy.zeros((N,M)) + sdata[round(N/4):round(3*N/4),round(N/4):round(3*N/4)] = 0.5 + sdata[round(M/8):round(7*M/8),round(3*M/8):round(5*M/8)] = 1 + ig = ImageGeometry(voxel_num_x = N, voxel_num_y = M, dimension_labels=[ImageGeometry.HORIZONTAL_X, ImageGeometry.HORIZONTAL_Y]) + data = ig.allocate() + data.geometry = ig + data.fill(sdata) + else: + tmp = Image.open(os.path.join(self.data_dir, which)) + print (tmp) + bands = tmp.getbands() + if len(bands) > 1: + # convert to greyscale + #tmp = tmp.convert('L') + ig = ImageGeometry(voxel_num_x=size[0], voxel_num_y=size[1], channels=len(bands), + dimension_labels=[ImageGeometry.HORIZONTAL_X, ImageGeometry.HORIZONTAL_Y, ImageGeometry.CHANNEL]) + + data = ig.allocate() + data.geometry = ig + #newsize = (size[0], size[1], len(bands)) + else: + ig = ImageGeometry(voxel_num_x = size[0], voxel_num_y = size[1], dimension_labels=[ImageGeometry.HORIZONTAL_X, ImageGeometry.HORIZONTAL_Y]) + data = ig.allocate() + data.geometry = ig + #newsize = size - if scale != (0,1): - #data = (data-dmin)/(dmax-dmin) * (scale[1]-scale[0]) +scale[0]) - data *= (scale[1]-scale[0]) - data += scale[0] + data.fill(numpy.array(tmp.resize((size[1],size[0])))) + + if scale is not None: + dmax = data.as_array().max() + dmin = data.as_array().min() + + # scale 0,1 + data = (data -dmin) / (dmax - dmin) + + if scale != (0,1): + #data = (data-dmin)/(dmax-dmin) * (scale[1]-scale[0]) +scale[0]) + data *= (scale[1]-scale[0]) + data += scale[0] - return ImageData(data) + print ("data.geometry", data.geometry) + return data def camera(**kwargs): diff --git a/Wrappers/Python/setup.py b/Wrappers/Python/setup.py index 44da471..8bd33a6 100644 --- a/Wrappers/Python/setup.py +++ b/Wrappers/Python/setup.py @@ -40,7 +40,8 @@ setup( 'ccpi.contrib','ccpi.contrib.optimisation', 'ccpi.contrib.optimisation.algorithms'], data_files = [('share/ccpi', ['data/boat.tiff', 'data/peppers.tiff', - 'data/camera.png'])], + 'data/camera.png', + 'data/resolution_chart.tiff'])], # Project uses reStructuredText, so ensure that the docutils get # installed or upgraded on the target machine -- cgit v1.2.3