Esempio n. 1
0
def get_dataset():
    cache_file = 'dataset_cache.pkl.gz')
    if os.path.exists(cache_file):
        with open(cache_file, 'rb') as f:
            dataset = pickle.load(f)
        return dataset['data'], dataset['target']

    raw_dataset = load_raw_images()
    data = load_image_files(raw_dataset.filenames)
    data = np.array(list(data))

    mask_dataset = load_mask_images()
    masks = load_image_files(mask_dataset.filenames)
    target = convert_masks_to_target(masks, negative=True)

    with open(cache_file, 'wb') as f:
        dataset = {'data': data, 'target': target}
        pickle.dump(dataset, f)

    return data, target
Esempio n. 2
0
from skimage.transform import resize

from dip.load_data import load_raw_images, load_mask_images


parser = argparse.ArgumentParser()
parser.add_argument('--shape0', type=int, default=1424)
parser.add_argument('--shape1', type=int, default=2136)
args = parser.parse_args()

shape = (args.shape0, args.shape1)

raw_dataset = load_raw_images()
for i, f in enumerate(raw_dataset.filenames):
    print(f)
    img = io.imread(f)
    if i == 0:
        print('resize: {0} -> {1}'.format(img.shape[:2], shape))
    resized = resize(img, output_shape=shape)
    io.imsave(f, resized)


mask_dataset = load_mask_images()
for i, f in enumerate(mask_dataset.filenames):
    print(f)
    img = io.imread(f)
    if i == 0:
        print('resize: {0} -> {1}'.format(img.shape[:2], shape))
    resized = resize(img, output_shape=shape)
    io.imsave(f, resized)
Esempio n. 3
0
from __future__ import print_function
import collections
import cPickle as pickle
from future_builtins import zip
import gzip

import numpy as np
from skimage import io
from sklearn.datasets.base import Bunch

from dip.load_data import load_image_files, load_mask_images
from dip.mask import bounding_rect_of_mask


datasets = load_mask_images()

data = []
for f, mask in zip(
        datasets.filenames,
        load_image_files(datasets.filenames),
        ):
    # rect: (min_x, max_x, min_y, max_x)
    rect = bounding_rect_of_mask(mask, negative=True)
    data.append(list(rect))
    print('{0}: {1}'.format(f, rect))

bunch = Bunch(name='mask rects')
bunch.data = np.array(data)
bunch.filenames = datasets.filenames
bunch.target = datasets.target