Ejemplo n.º 1
0
def test_imexport_imimport():
    shape = (2, 2)
    image = np.zeros(shape)
    with expected_warnings(['precision loss']):
        pil_image = ndarray_to_pil(image)
    out = pil_to_ndarray(pil_image)
    assert out.shape == shape
Ejemplo n.º 2
0
    def __call__(self, img):
        noise_type = random.random()
        if noise_type < .33:
            noise_type = 's&p'
        elif noise_type < .66:
            noise_type = 'speckle'
        elif noise_type < 1.:
            noise_type = 'gaussian'
        else:
            return img

        nd_img = np.array(img) / 255.0
        nd_noised = random_noise(np.asarray(nd_img),
                                 mode=noise_type,
                                 clip=True)
        img = ndarray_to_pil(nd_noised)
        return img
Ejemplo n.º 3
0
 def roundtrip_pil_image(self, x):
     pil_image = ndarray_to_pil(x)
     y = pil_to_ndarray(pil_image)
     return y
Ejemplo n.º 4
0
def test_imexport_imimport():
    shape = (2, 2)
    image = np.zeros(shape)
    pil_image = ndarray_to_pil(image)
    out = pil_to_ndarray(pil_image)
    assert out.shape == shape
Ejemplo n.º 5
0
def test_imexport_imimport():
    shape = (2, 2)
    image = np.zeros(shape)
    pil_image = ndarray_to_pil(image)
    out = pil_to_ndarray(pil_image)
    assert out.shape == shape
Ejemplo n.º 6
0
 def roundtrip_pil_image(self, x):
     pil_image = ndarray_to_pil(x)
     y = pil_to_ndarray(pil_image)
     return y
Ejemplo n.º 7
0
draw.text((10, 60),"This Homework is cooly cool",(255), font=font)
draw.text((10, 85),"This Homework is cooly cool",(255), font=font)
draw.text((10, 110),"This Homework is cooly cool",(255), font=font)
draw.text((10, 135),"This Homework is cooly cool",(255), font=font)
draw.text((10, 160),"This Homework is cooly cool",(255), font=font)
draw.text((10, 185),"This Homework is cooly cool",(255), font=font)
draw.text((10, 210),"This Homework is cooly cool",(255), font=font)
draw.text((10, 235),"This Homework is cooly cool",(255), font=font)
draw.text((10, 260),"This Homework is cooly cool",(255), font=font)
y_test_missing.save('y_test_missing.png')

#Building and saving the mask
mask = ImageChops.difference(y_test_missing, y_test)
mask = np.array(pil_to_ndarray(mask) <= 0.1, dtype=int)
mask_img = mask * 255
mask = ndarray_to_pil(mask)
mask_img = ndarray_to_pil(mask_img)
mask_img.save('mask.png', 'PNG')


psnr_y_test_y_test_missing = peak_signal_noise_ratio(pil_to_ndarray(y_test), pil_to_ndarray(y_test_missing))
ssim_y_test_y_test_missing = structural_similarity(pil_to_ndarray(y_test), pil_to_ndarray(y_test_missing))
print(psnr_y_test_y_test_missing)
print(ssim_y_test_y_test_missing)
print('\n')

"""
plt.imshow(y_train, cmap='gray')
plt.show()
plt.imshow(y_test, cmap='gray')
plt.show()