コード例 #1
0
ファイル: test_colorconv.py プロジェクト: AceHao/scikit-image
def test_guess_spatial_dimensions():
    im1 = np.zeros((5, 5))
    im2 = np.zeros((5, 5, 5))
    im3 = np.zeros((5, 5, 3))
    im4 = np.zeros((5, 5, 5, 3))
    im5 = np.zeros((5,))
    assert_equal(guess_spatial_dimensions(im1), 2)
    assert_equal(guess_spatial_dimensions(im2), 3)
    assert_equal(guess_spatial_dimensions(im3), None)
    assert_equal(guess_spatial_dimensions(im4), 3)
    assert_raises(ValueError, guess_spatial_dimensions, im5)
コード例 #2
0
def test_guess_spatial_dimensions():
    im1 = np.zeros((5, 5))
    im2 = np.zeros((5, 5, 5))
    im3 = np.zeros((5, 5, 3))
    im4 = np.zeros((5, 5, 5, 3))
    im5 = np.zeros((5, ))
    assert_equal(guess_spatial_dimensions(im1), 2)
    assert_equal(guess_spatial_dimensions(im2), 3)
    assert_equal(guess_spatial_dimensions(im3), None)
    assert_equal(guess_spatial_dimensions(im4), 3)
    assert_raises(ValueError, guess_spatial_dimensions, im5)
コード例 #3
0
def read_test_data(IMG_WIDTH=256, IMG_HEIGHT=256, IMG_CHANNELS=3):
    X_test = np.zeros((len(test_ids), IMG_HEIGHT, IMG_WIDTH, IMG_CHANNELS),
                      dtype=np.uint8)
    sizes_test = []
    print('\nGetting and resizing test images ... ')
    sys.stdout.flush()
    if os.path.isfile("test_img.npy") and os.path.isfile("test_size.npy"):
        print("Test file loaded from memory")
        X_test = np.load("test_img.npy")
        sizes_test = np.load("test_size.npy")
        return X_test, sizes_test
    b = Progbar(len(test_ids))
    for n, id_ in enumerate(test_ids):
        path = TEST_PATH + id_
        #        img = imread(path + '/images/' + id_ + '.png')[:,:,:IMG_CHANNELS]
        img = imread(path + '/images/' + id_ + '.png')

        if (guess_spatial_dimensions(img) == 2):
            img = gray2rgb(img)
        else:
            img = img[:, :, :IMG_CHANNELS]

        sizes_test.append([img.shape[0], img.shape[1]])
        img = resize(img, (IMG_HEIGHT, IMG_WIDTH),
                     mode='constant',
                     preserve_range=True)
        X_test[n] = img
        b.update(n)
    np.save("test_img", X_test)
    np.save("test_size", sizes_test)
    return X_test, sizes_test
コード例 #4
0
def convert_rgb(img):
    nchannel = color.guess_spatial_dimensions(img)
    res = img
    if nchannel == 1 or nchannel == None:
        res = color.gray2rgb(img)
    elif nchannel == 4:
        res = img[:, :, 0:3]
    nchannel = res.shape[2]
    if nchannel == 4:
        res = img[:, :, 0:3]
    print res.shape
    return res
コード例 #5
0
fig = plt.figure(figsize=(6, 6))
ani = animation.FuncAnimation(fig,
                              animate,
                              np.arange(0, 1, 0.05),
                              init_func=init,
                              interval=20)
ani.save("ejercicio1.gif", fps=5)

#########################################

# EJERCICIO 2

#########################################

img = io.imread('arbol.png')
dimensions = color.guess_spatial_dimensions(img)
print(dimensions)
io.show()
#io.imsave('arbol2.png',img)

#https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html
fig = plt.figure(figsize=(5, 5))
p = plt.contourf(img[:, :, 0],
                 cmap=plt.cm.get_cmap('viridis'),
                 levels=np.arange(0, 240, 2))
plt.axis('off')
#fig.colorbar(p)

xyz = img.shape

x = np.arange(0, xyz[0], 1)
コード例 #6
0
import os
from skimage import io, data, color
import skimage
import os
print(skimage.data_dir)
filename = os.path.join(skimage.data_dir, "camera.png")
camera = io.imread(filename)
print(color.guess_spatial_dimensions(camera))
# io.imshow(camera)
# io.show()