How to use skimage - 10 common examples

To help you get started, we’ve selected a few skimage examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ndrplz / dreyeve / experiments / assessment / create_attentional_videos.py View on Github external
Parameters
    ----------
    seq: int
        the sequence number.
    idx: int
        the frame number.

    Returns
    -------
    np.array
        the image.
    """

    seq_dir = join(dreyeve_root, 'DATA', '{:02d}'.format(seq), 'frames')

    img = io.imread(join(seq_dir, '{:06d}.jpg'.format(idx)))
    img = resize(img, output_shape=(1080 // 2, 1920 // 2), mode='constant', preserve_range=True)

    return np.uint8(img)
github scikit-image / scikit-image / doc / ext / plot2rst.py View on Github external
centered in an array of the specified shape before saving.
    """
    rescale = min(float(w_1) / w_2 for w_1, w_2 in zip(shape, image.shape))
    small_shape = (rescale * np.asarray(image.shape[:2])).astype(int)
    small_image = transform.resize(image, small_shape)

    if len(image.shape) == 3:
        shape = shape + (image.shape[2],)
    background_value = dtype_range[small_image.dtype.type][1]
    thumb = background_value * np.ones(shape, dtype=small_image.dtype)

    i = (shape[0] - small_shape[0]) // 2
    j = (shape[1] - small_shape[1]) // 2
    thumb[i:i+small_shape[0], j:j+small_shape[1]] = small_image

    io.imsave(thumb_path, thumb)
github scikit-image / scikit-image / skimage / morphology / attribute.py View on Github external
>>> closed = attribute.diameter_closing(f, 3, connectivity=1)

    The small (but deep) dark objects are removed, except for the longest one.
    """

    if mask is not None and mask.shape != image.shape:
        raise ValueError("mask must have same shape as image")
    if mask is None:
        # Use a complete `True` mask if none is provided
        mask = np.ones(image.shape, bool)

    neighbors, offset = _validate_connectivity(image.ndim, connectivity,
                                               offset=None)

    seeds_bin = local_minima(image, selem=neighbors)
    seeds = label(seeds_bin, connectivity=connectivity).astype(np.uint64)
    output = image.copy()

    image = np.pad(image, 1, mode='constant')
    mask = np.pad(mask, 1, mode='constant')
    seeds = np.pad(seeds, 1, mode='constant')
    output = np.pad(output, 1, mode='constant')

    flat_neighborhood = _compute_neighbors(image, neighbors, offset)
    image_strides = np.array(image.strides, dtype=np.int32) // image.itemsize

    _attribute.diameter_closing(image.ravel(),
                                diameter_threshold,
                                seeds.ravel(),
                                flat_neighborhood,
                                mask.ravel().astype(np.uint8),
                                image_strides,
github samocooper / nuclitrack / nuclitrack / nuclitrack_tools / segmentimages.py View on Github external
if 8 > val >= 4:
        k = morphology.octagon(val//2 + 1, val//2 + 1)

        im = filters.gaussian(im, val)
        im = filters.gaussian(im, val)

        im = morphology.erosion(im, k)
        im = morphology.erosion(im, k)

        im = morphology.dilation(im, k)
        im = morphology.dilation(im, k)

    if val >= 8:
        k = morphology.octagon(val // 4 + 1, val // 4 + 1)

        im = filters.gaussian(im, val)
        im = filters.gaussian(im, val)
        im = filters.gaussian(im, val)
        im = filters.gaussian(im, val)

        im = morphology.erosion(im, k)
        im = morphology.erosion(im, k)
        im = morphology.erosion(im, k)
        im = morphology.erosion(im, k)

        im = morphology.dilation(im, k)
        im = morphology.dilation(im, k)
        im = morphology.dilation(im, k)
        im = morphology.dilation(im, k)

    return im
github samocooper / nuclitrack / nuclitrack / nuclitrack_tools / segmentimages.py View on Github external
if 4 > val > 0:

        k = morphology.octagon(val, val)

        im = filters.gaussian(im, val)

        im = morphology.erosion(im, k)

        im = morphology.dilation(im, k)

    if 8 > val >= 4:
        k = morphology.octagon(val//2 + 1, val//2 + 1)

        im = filters.gaussian(im, val)
        im = filters.gaussian(im, val)

        im = morphology.erosion(im, k)
        im = morphology.erosion(im, k)

        im = morphology.dilation(im, k)
        im = morphology.dilation(im, k)

    if val >= 8:
        k = morphology.octagon(val // 4 + 1, val // 4 + 1)

        im = filters.gaussian(im, val)
        im = filters.gaussian(im, val)
        im = filters.gaussian(im, val)
        im = filters.gaussian(im, val)

        im = morphology.erosion(im, k)
github liu-vis / DualResidualNetworks / test / haze.py View on Github external
ave_psnr+= psnr(res, label_v, data_range=255)
                ave_ssim+= ski_ssim(res, label_v, data_range=255, multichannel=True)
                Image.fromarray(res).save(show_dst+im_name[0].split('.')[0]+'_'+str(vi+1)+'.png')

    elif data_name == 'DCPDNData':
        ct_num+= 1
        label = label.numpy()[0]
        label = label.transpose((1,2,0))        
        hazy = Variable(hazy, requires_grad=False).cuda()
        res = cleaner(hazy)
        res = res.data.cpu().numpy()[0]
        res[res>1] = 1
        res[res<0] = 0
        res = res.transpose((1,2,0))
        ave_psnr+= psnr(res, label, data_range=1)
        ave_ssim+= ski_ssim(res, label, data_range=1, multichannel=True)
        
        res*= 255
        res = res.astype(np.uint8)        
        Image.fromarray(res).save(show_dst+im_name[0].split('.')[0]+'.png')

    else:
        print("Unknown dataset name.")

print('psnr: '+str(ave_psnr/float(ct_num))+'.')
print('ssim: '+str(ave_ssim/float(ct_num))+'.')
print('Test done.')
github wangzhecheng / DeepSolar / test_classification.py View on Github external
def load_image(path):
    img = skimage.io.imread(path)
    resized_img = skimage.transform.resize(img, (IMAGE_SIZE, IMAGE_SIZE))
    if resized_img.shape[2] != 3:
        resized_img = resized_img[:, :, 0:3]
    return resized_img
github gongxijun / lantern-detection / detector / test-classifier.py View on Github external
'/home/gongxijun/data/苹果',
            '/home/gongxijun/data/山楂',
            '/home/gongxijun/data/西瓜',
            '/home/gongxijun/data/object-detector/11',
            '/home/gongxijun/data/灯笼',
            '/home/gongxijun/data/test3',
            '/home/gongxijun/文档'
            ]
    # Read the image
    root_path = list[-1]
    _cnt = 0;
    _num = 0
    for image_path in os.listdir(root_path):
        img = cv2.imread(os.path.join(root_path, image_path))
        img = transform.resize(img, (400, 400))
        imt = color.rgb2gray(img)
        min_wdw_sz = (90, 128)
        step_size = (10, 5)
        downscale = args['downscale']
        visualize_det = args['visualize']

        # Load the classifier
        clf = joblib.load(model_path)

        # List to store the detections
        detections = []
        # The current scale of the image
        scale = 0
        # Downscale the image and iterate
        for im_scaled in pyramid_gaussian(imt, downscale=downscale):
            # This list contains detections at the current scale
            cd = []
github mpicbg-csbd / stardist / tests / _old_test_all.py View on Github external
def random_image(shape=(128,128)):
    from skimage.measure import label
    from skimage.morphology import binary_closing, binary_opening
    from skimage.morphology import disk
    img = np.random.normal(size=shape)
    img = img > -0.7
    img = binary_opening(img,disk(2))
    img = binary_closing(img,disk(1))
    img = label(img)
    return img
github mpicbg-csbd / stardist / tests / _old_test_all.py View on Github external
def random_image(shape=(128,128)):
    from skimage.measure import label
    from skimage.morphology import binary_closing, binary_opening
    from skimage.morphology import disk
    img = np.random.normal(size=shape)
    img = img > -0.7
    img = binary_opening(img,disk(2))
    img = binary_closing(img,disk(1))
    img = label(img)
    return img