当前位置: 首页>>代码示例>>Python>>正文


Python skimage.data方法代码示例

本文整理汇总了Python中skimage.data方法的典型用法代码示例。如果您正苦于以下问题:Python skimage.data方法的具体用法?Python skimage.data怎么用?Python skimage.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在skimage的用法示例。


在下文中一共展示了skimage.data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_image

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def load_image(path):
    """Open, load and normalize an image.

    :param path: Image path.
    :type path: String

    :returns: Normalized image.
    :rtype: np.ndarray
    """
    img = skimage.data.imread(path)

    if img.dtype == np.uint8:
        normalizer = 255.
    else:
        normalizer = 65535.

    img = img / normalizer
    return img.astype(np.float32) 
开发者ID:tum-vision,项目名称:learn_prox_ops,代码行数:20,代码来源:data.py

示例2: init_file_lists

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def init_file_lists(self):
        """
        Load and split the BSDS500 dataset.

        :returns: Two lists of train and test file paths.
        :rtype: Tuple
        """
        if self.noise_type == 'gaussian_random_sigma':
            self.patch_size = 50
            self.train_set_multiplier = 960  # to have 128 * 3000 patches in one epoche

        data_path = os.path.join(ROOT_DIR, 'data/bsds_500')
        if self.grayscale:
            train_files = glob(os.path.join(data_path, "greyscale_images/train/*.png"))
            test_files = glob(os.path.join(data_path, "greyscale_images/test/*.png"))
            self.img_decoder = tf.image.decode_png
        else:
            train_files = glob(os.path.join(data_path, 'color_images/train/*.jpg')) + \
                          glob(os.path.join(data_path, 'color_images/test/*.jpg'))
            train_files = train_files[:400]
            test_files = glob(os.path.join(data_path, 'data/color_images/val/*.jpg'))[:68]

        return train_files, test_files 
开发者ID:tum-vision,项目名称:learn_prox_ops,代码行数:25,代码来源:data.py

示例3: load_data

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def load_data(data_dir):
    """Loads a data set and returns two lists:
    
    images: a list of Numpy arrays, each representing an image.
    labels: a list of numbers that represent the images labels.
    """
    # Get all the subdirectories of the data folder (i.e. traing or test). Each folder represents an unique label.
    directories = [d for d in os.listdir(data_dir) 
                   if os.path.isdir(os.path.join(data_dir, d))]
    
    # Iterate for loop through the label directories and collect the data in two lists, labels and images.
    labels = []
    images = []
    for d in directories:
        label_dir = os.path.join(data_dir, d)
        file_names = [os.path.join(label_dir, f) for f in os.listdir(label_dir) if f.endswith(".ppm")]

        # For each label, load it's images and add them to the images list.
        # And add the label number (i.e. directory name) to the labels list.
        for f in file_names:
            images.append(skimage.data.imread(f))
            labels.append(int(d))
    return images, labels

# Load training and testing datasets. 
开发者ID:PacktPublishing,项目名称:Practical-Convolutional-Neural-Networks,代码行数:27,代码来源:custom.py

示例4: plot

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def plot(data, test, predicted, figsize=(5, 6)):
    data = [reshape(d) for d in data]
    test = [reshape(d) for d in test]
    predicted = [reshape(d) for d in predicted]

    fig, axarr = plt.subplots(len(data), 3, figsize=figsize)
    for i in range(len(data)):
        if i==0:
            axarr[i, 0].set_title('Train data')
            axarr[i, 1].set_title("Input data")
            axarr[i, 2].set_title('Output data')

        axarr[i, 0].imshow(data[i])
        axarr[i, 0].axis('off')
        axarr[i, 1].imshow(test[i])
        axarr[i, 1].axis('off')
        axarr[i, 2].imshow(predicted[i])
        axarr[i, 2].axis('off')

    plt.tight_layout()
    plt.savefig("result.png")
    plt.show() 
开发者ID:takyamamoto,项目名称:Hopfield-Network,代码行数:24,代码来源:train.py

示例5: ReadDirNames

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def ReadDirNames(DirNamesPath, TrainPath):
    """
    Inputs: 
    Path is the path of the file you want to read
    Outputs:
    DirNames is the data loaded from ./TxtFiles/DirNames.txt which has full path to all image files without extension
    """
    # Read DirNames file
    DirNames = open(DirNamesPath, 'r')
    DirNames = DirNames.read()
    DirNames = DirNames.split()

    # Read TestIdxs file
    TrainIdxs = open(TrainPath, 'r')
    TrainIdxs = TrainIdxs.read()
    TrainIdxs = TrainIdxs.split()
    TrainIdxs = [int(val) for val in TrainIdxs]
    TrainNames = [DirNames[i] for i in TrainIdxs]

    return DirNames, TrainNames 
开发者ID:prgumd,项目名称:EVDodgeNet,代码行数:22,代码来源:RunEVHomographyNet.py

示例6: ReadDirNames

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def ReadDirNames(DirNamesPath, LabelNamesPath, TrainPath):
    """
    Inputs: 
    Path is the path of the file you want to read
    Outputs:
    DirNames is the data loaded from ./TxtFiles/DirNames.txt which has full path to all image files without extension
    """
    # Read DirNames and LabelNames files
    DirNames = open(DirNamesPath, 'r')
    DirNames = DirNames.read()
    DirNames = DirNames.split()

    LabelNames = open(LabelNamesPath, 'r')
    LabelNames = LabelNames.read()
    LabelNames = LabelNames.split()
    
    # Read Train, Val and Test Idxs
    TrainIdxs = open(TrainPath, 'r')
    TrainIdxs = TrainIdxs.read()
    TrainIdxs = TrainIdxs.split()
    TrainIdxs = [int(val) for val in TrainIdxs]
    TrainNames = [DirNames[i] for i in TrainIdxs]
    TrainLabels = [LabelNames[i] for i in TrainIdxs]

    return DirNames, TrainNames, TrainLabels 
开发者ID:prgumd,项目名称:EVDodgeNet,代码行数:27,代码来源:TrainEVSegNet.py

示例7: classify_image

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def classify_image(path_dir=cfg.ROOT + '/data/download/words',
                   dest_path=cfg.ROOT + '/data/download/words-classify'):
    """
        :param path_dir:
        :param dest_path:
        :return:
    """
    temp = filter(lambda s: not s.startswith("."), os.listdir(path_dir))
    for words_name in temp:
        print words_name
        if not os.path.exists(dest_path):
            os.makedirs(dest_path)
        sub_root_path = os.path.join(path_dir, words_name)
        if os.path.isdir(sub_root_path):
            classify_image(sub_root_path, os.path.join(dest_path, words_name))
            continue
        img = cv2.imread(sub_root_path, 0)
        new_img = judge_the_image_size(img)
        cv2.imwrite(os.path.join(dest_path, words_name), new_img)
    return 0 
开发者ID:aaronshan,项目名称:12306-captcha,代码行数:22,代码来源:words.py

示例8: test_other_dtypes

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def test_other_dtypes(self):
        aug = iaa.AllChannelsHistogramEqualization()

        # np.uint16: cv2.error: OpenCV(3.4.5) (...)/histogram.cpp:3345:
        #            error: (-215:Assertion failed)
        #            src.type() == CV_8UC1 in function 'equalizeHist'
        # np.uint32: TypeError: src data type = 6 is not supported
        # np.uint64: see np.uint16
        # np.int8: see np.uint16
        # np.int16: see np.uint16
        # np.int32: see np.uint16
        # np.int64: see np.uint16
        # np.float16: TypeError: src data type = 23 is not supported
        # np.float32: see np.uint16
        # np.float64: see np.uint16
        # np.float128: TypeError: src data type = 13 is not supported
        for dtype in [np.uint8]:
            with self.subTest(dtype=np.dtype(dtype).name):
                min_value, _center_value, max_value = \
                    iadt.get_value_range_of_dtype(dtype)
                dynamic_range = max_value + abs(min_value)
                if np.dtype(dtype).kind == "f":
                    img = np.zeros((16,), dtype=dtype)
                    for i in sm.xrange(16):
                        img[i] = min_value + i * (0.01 * dynamic_range)
                    img = img.reshape((4, 4))
                else:
                    img = np.arange(
                        min_value, min_value + 16, dtype=dtype).reshape((4, 4))
                img_aug = aug.augment_image(img)
                assert img_aug.dtype.name == np.dtype(dtype).name
                assert img_aug.shape == img.shape
                assert np.min(img_aug) < min_value + 0.1 * dynamic_range
                assert np.max(img_aug) > max_value - 0.1 * dynamic_range 
开发者ID:aleju,项目名称:imgaug,代码行数:36,代码来源:test_contrast.py

示例9: load_deblurring_grey_data

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def load_deblurring_grey_data(experiment_name=None, image_name=None):
    """
    Load the data for the grayscale deblurring experiments on 11 standard test
    images first conducted in [A machine learning approach for non-blind image deconvolution](http://www.cv-foundation.org/openaccess/content_cvpr_2013/papers/Schuler_A_Machine_Learning_2013_CVPR_paper.pdf).

    :param experiment_name: Name of the experiment a-e: experiment_*
    :type experiment_name: String
    :param image_name: Name of the image
    :type image_name: String

    :returns: Experiment data as Dict or single Tuple
    :rtype: Tuple
    """
    crop = 12
    data_dir = os.path.join(ROOT_DIR, 'data/deblurring_grey')
    experiments_data = {os.path.basename(experiment_dir):
                        {os.path.basename(image_dir):
                         {'f': load_image(os.path.join(image_dir, 'blurred_observation.png')),
                          'img': load_image(os.path.join(image_dir, 'original.png'))}
                         for image_dir in glob(experiment_dir + '/*')
                         if os.path.isdir(image_dir)}
                        for experiment_dir in glob(data_dir + '/*')}

    for experiment, experiment_images in experiments_data.items():
        kernel_img = load_image(os.path.join(data_dir, experiment + '/kernel.png'))
        kernel_img /= kernel_img.sum()
        experiment_images['kernel_img'] = kernel_img

    if experiment_name is not None:
        experiment_data = experiments_data[experiment_name]
        if image_name is not None:
            image_data = experiment_data[image_name]
            return (image_data['f'], image_data['img'], experiment_data['kernel_img'], crop)
        return experiment_data, crop
    else:
        if image_name is not None:
            print("Specifying only an image is not possible.")
        return experiments_data, crop 
开发者ID:tum-vision,项目名称:learn_prox_ops,代码行数:40,代码来源:data.py

示例10: load_demosaicking_data

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def load_demosaicking_data(image_name=None, dataset="mc_master"):
    """
    Load McMaster or Kodak demosaicking data.

    :param image_name: Name of a particular image
    :type image_name: String

    :return test_images: Experiment data as Dict or single Tuple
    :rtype test_images: Tuple
    """
    crop = 5
    image_paths = glob(os.path.join(ROOT_DIR,
                                    "data/demosaicking",
                                    dataset.lower(),
                                    "*"))

    def sort_key(d): return os.path.splitext(os.path.basename(d))[0]
    data = {os.path.splitext(os.path.basename(d))[0]:
            {'img': load_image(d)}
             for d in sorted(image_paths, key=sort_key)}

    if image_name is not None:
        return (data[str(image_name).lower()]['img'],
                crop)
    else:
        return data, crop 
开发者ID:tum-vision,项目名称:learn_prox_ops,代码行数:28,代码来源:data.py

示例11: __init__

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def __init__(self, opt, test_epochs):
        """
        Class constructor.

        :param opt: Option flags.
        :type opt: tf.app.flags.FLAGS
        :param test_epochs: Number of test_epochs. Usually None for 1 entire epoch.
        :type test_epochs: Int
        """
        self.input_shape = (self.patch_size, self.patch_size, opt.channels)
        self.train_shape = (self.patch_size, self.patch_size, opt.channels)
        self.test_shape = (self.patch_size, self.patch_size, opt.channels)
        self.sigma_noise = opt.sigma_noise
        self.noise_type = opt.noise_type
        self.batch_size = opt.batch_size
        self.img_decoder = tf.image.decode_jpeg
        self.is_train = tf.placeholder(tf.bool, name='is_train')

        train_files, test_files = self.init_file_lists()
        train_pipe = self.tf_data_pipeline(train_files * self.train_set_multiplier,
                                           self.train_shape,
                                           'train_pipeline',
                                           opt.train_epochs)
        test_pipe = self.tf_data_pipeline(test_files * self.test_set_multiplier,
                                          self.test_shape,
                                          'test_pipeline',
                                          test_epochs,
                                          train=False)

        Pipeline = namedtuple('Pipeline',
                              ['data', 'labels', 'num', 'epochs', 'batch_size'])
        self.train = Pipeline(*train_pipe,
                              epochs=opt.train_epochs,
                              batch_size=opt.batch_size)
        self.test = Pipeline(*test_pipe,
                             epochs=test_epochs,
                             batch_size=opt.batch_size) 
开发者ID:tum-vision,项目名称:learn_prox_ops,代码行数:39,代码来源:data.py

示例12: _label_statistics

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def _label_statistics(image_paths):
    '''

    Calculates label statistics (number of picked pixels for each class)

    Parameters
    ----------
    image_paths : list
        List of absolute paths for picked images

    Returns
    -------
    array: numpy array
        Number of selected pixels per class


    '''
    ds = KittiDataset()

    def _rgb_2_label(rgb):
        return ds.color2label[tuple(rgb)].trainId

    total_counts = np.zeros(ds.num_classes())
    for img in image_paths:
        rgb = skimage.data.load(img)
        labels = np.apply_along_axis(_rgb_2_label, 2, rgb)
        indices, counts = np.unique(labels, return_counts=True)
        if indices[-1] >= ds.num_classes():
            indices = indices[0:-1]
            counts = counts[0:-1]
        total_counts[indices] += counts
    return total_counts 
开发者ID:Vaan5,项目名称:piecewisecrf,代码行数:34,代码来源:train_validation_split.py

示例13: img_to_array

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def img_to_array(img, data_format=None):
    """Converts a PIL Image instance to a Numpy array.

    # Arguments
        img: PIL Image instance.
        data_format: Image data format.

    # Returns
        A 3D Numpy array.

    # Raises
        ValueError: if invalid `img` or `data_format` is passed.
    """
    if data_format is None:
        data_format = K.image_data_format()
    if data_format not in {'channels_first', 'channels_last'}:
        raise ValueError('Unknown data_format: ', data_format)
    # Numpy array x has format (height, width, channel)
    # or (channel, height, width)
    # but original PIL image has format (width, height, channel)
    x = np.asarray(img, dtype=K.floatx())
    if len(x.shape) == 3:
        if data_format == 'channels_first':
            x = x.transpose(2, 0, 1)
    elif len(x.shape) == 2:
        if data_format == 'channels_first':
            x = x.reshape((1, x.shape[0], x.shape[1]))
        else:
            x = x.reshape((x.shape[0], x.shape[1], 1))
    else:
        raise ValueError('Unsupported image shape: ', x.shape)
    return x 
开发者ID:thomaskuestner,项目名称:CNNArt,代码行数:34,代码来源:image_preprocessing.py

示例14: __init__

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def __init__(self, x, y, image_data_generator,
                 batch_size=32, shuffle=False, seed=None,
                 data_format=None,
                 save_to_dir=None, save_prefix='', save_format='png'):
        if y is not None and len(x) != len(y):
            raise ValueError('X (images tensor) and y (labels) '
                             'should have the same length. '
                             'Found: X.shape = %s, y.shape = %s' %
                             (np.asarray(x).shape, np.asarray(y).shape))

        if data_format is None:
            data_format = K.image_data_format()
        self.x = np.asarray(x, dtype=K.floatx())

        if self.x.ndim != 4:
            raise ValueError('Input data in `NumpyArrayIterator` '
                             'should have rank 4. You passed an array '
                             'with shape', self.x.shape)
        channels_axis = 3 if data_format == 'channels_last' else 1
        if self.x.shape[channels_axis] not in {1, 3, 4}:
            warnings.warn('NumpyArrayIterator is set to use the '
                          'data format convention "' + data_format + '" '
                          '(channels on axis ' + str(channels_axis) + '), i.e. expected '
                          'either 1, 3 or 4 channels on axis ' + str(channels_axis) + '. '
                          'However, it was passed an array with shape ' + str(self.x.shape) +
                          ' (' + str(self.x.shape[channels_axis]) + ' channels).')
        if y is not None:
            self.y = np.asarray(y)
        else:
            self.y = None
        self.image_data_generator = image_data_generator
        self.data_format = data_format
        self.save_to_dir = save_to_dir
        self.save_prefix = save_prefix
        self.save_format = save_format
        super(NumpyArrayIterator, self).__init__(x.shape[0], batch_size, shuffle, seed) 
开发者ID:thomaskuestner,项目名称:CNNArt,代码行数:38,代码来源:image_preprocessing.py

示例15: _get_batches_of_transformed_samples

# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import data [as 别名]
def _get_batches_of_transformed_samples(self, index_array):
        batch_x = np.zeros((len(index_array),) + self.image_shape, dtype=K.floatx())
        grayscale = self.color_mode == 'grayscale'
        # build batch of image data
        for i, j in enumerate(index_array):
            fname = self.filenames[j]
            img = load_img(os.path.join(self.directory, fname),
                           grayscale=grayscale,
                           target_size=self.target_size)
            x = img_to_array(img, data_format=self.data_format)
            x = self.image_data_generator.random_transform(x)
            x = self.image_data_generator.standardize(x)
            batch_x[i] = x
        # optionally save augmented images to disk for debugging purposes
        if self.save_to_dir:
            for i, j in enumerate(index_array):
                img = array_to_img(batch_x[i], self.data_format, scale=True)
                fname = '{prefix}_{index}_{hash}.{format}'.format(prefix=self.save_prefix,
                                                                  index=j,
                                                                  hash=np.random.randint(1e7),
                                                                  format=self.save_format)
                img.save(os.path.join(self.save_to_dir, fname))
        # build batch of labels
        if self.class_mode == 'input':
            batch_y = batch_x.copy()
        elif self.class_mode == 'sparse':
            batch_y = self.classes[index_array]
        elif self.class_mode == 'binary':
            batch_y = self.classes[index_array].astype(K.floatx())
        elif self.class_mode == 'categorical':
            batch_y = np.zeros((len(batch_x), self.num_classes), dtype=K.floatx())
            for i, label in enumerate(self.classes[index_array]):
                batch_y[i, label] = 1.
        else:
            return batch_x
        return batch_x, batch_y 
开发者ID:thomaskuestner,项目名称:CNNArt,代码行数:38,代码来源:image_preprocessing.py


注:本文中的skimage.data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。