Python scipy.misc.face() Examples
The following are 30
code examples of scipy.misc.face().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
scipy.misc
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: saliency.py From pytorch-smoothgrad with MIT License | 6 votes |
def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('--cuda', action='store_true', default=False, help='Use NVIDIA GPU acceleration') parser.add_argument('--img', type=str, default='', help='Input image path') parser.add_argument('--out_dir', type=str, default='./result/grad/', help='Result directory path') parser.add_argument('--n_samples', type=int, default=10, help='Sample size of SmoothGrad') args = parser.parse_args() args.cuda = args.cuda and torch.cuda.is_available() if args.cuda: print("Using GPU for acceleration") else: print("Using CPU for computation") if args.img: print('Input image: {}'.format(args.img)) else: print('Input image: raccoon face (scipy.misc.face())') print('Output directory: {}'.format(args.out_dir)) print('Sample size of SmoothGrad: {}'.format(args.n_samples)) print() return args
Example #2
Source File: grad_cam.py From pytorch-smoothgrad with MIT License | 6 votes |
def parse_args(): parser = argparse.ArgumentParser() parser.add_argument('--cuda', action='store_true', default=False, help='Use NVIDIA GPU acceleration') parser.add_argument('--img', type=str, default='', help='Input image path') parser.add_argument('--out_dir', type=str, default='./result/cam/', help='Result directory path') args = parser.parse_args() args.cuda = args.cuda and torch.cuda.is_available() if args.cuda: print("Using GPU for acceleration") else: print("Using CPU for computation") if args.img: print('Input image: {}'.format(args.img)) else: print('Input image: raccoon face (scipy.misc.face())') print('Output directory: {}'.format(args.out_dir)) print() return args
Example #3
Source File: test_image.py From twitter-stock-recommendation with MIT License | 6 votes |
def test_extract_patches_max_patches(): face = downsampled_face i_h, i_w = face.shape p_h, p_w = 16, 16 patches = extract_patches_2d(face, (p_h, p_w), max_patches=100) assert_equal(patches.shape, (100, p_h, p_w)) expected_n_patches = int(0.5 * (i_h - p_h + 1) * (i_w - p_w + 1)) patches = extract_patches_2d(face, (p_h, p_w), max_patches=0.5) assert_equal(patches.shape, (expected_n_patches, p_h, p_w)) assert_raises(ValueError, extract_patches_2d, face, (p_h, p_w), max_patches=2.0) assert_raises(ValueError, extract_patches_2d, face, (p_h, p_w), max_patches=-1.0)
Example #4
Source File: test_image.py From Mastering-Elasticsearch-7.0 with MIT License | 6 votes |
def test_extract_patches_max_patches(): face = downsampled_face i_h, i_w = face.shape p_h, p_w = 16, 16 patches = extract_patches_2d(face, (p_h, p_w), max_patches=100) assert_equal(patches.shape, (100, p_h, p_w)) expected_n_patches = int(0.5 * (i_h - p_h + 1) * (i_w - p_w + 1)) patches = extract_patches_2d(face, (p_h, p_w), max_patches=0.5) assert_equal(patches.shape, (expected_n_patches, p_h, p_w)) assert_raises(ValueError, extract_patches_2d, face, (p_h, p_w), max_patches=2.0) assert_raises(ValueError, extract_patches_2d, face, (p_h, p_w), max_patches=-1.0)
Example #5
Source File: test_image.py From twitter-stock-recommendation with MIT License | 5 votes |
def _downsampled_face(): try: face = sp.face(gray=True) except AttributeError: # Newer versions of scipy have face in misc from scipy import misc face = misc.face(gray=True) face = face.astype(np.float32) face = (face[::2, ::2] + face[1::2, ::2] + face[::2, 1::2] + face[1::2, 1::2]) face = (face[::2, ::2] + face[1::2, ::2] + face[::2, 1::2] + face[1::2, 1::2]) face = face.astype(np.float32) face /= 16.0 return face
Example #6
Source File: image.py From modl with BSD 2-Clause "Simplified" License | 5 votes |
def load_image(source, scale=1, gray=False, memory=Memory(cachedir=None)): data_dir = get_data_dirs()[0] if source == 'face': image = face(gray=gray) image = image.astype(np.float32) / 255 if image.ndim == 2: image = image[..., np.newaxis] if scale != 1: image = memory.cache(rescale)(image, scale=scale) return image elif source == 'lisboa': image = imread(join(data_dir, 'images', 'lisboa.jpg'), as_grey=gray) image = image.astype(np.float32) / 255 if image.ndim == 2: image = image[..., np.newaxis] if scale != 1: image = memory.cache(rescale)(image, scale=scale) return image elif source == 'aviris': from spectral import open_image image = open_image( join(data_dir, 'aviris', 'f100826t01p00r05rdn_b/' 'f100826t01p00r05rdn_b_sc01_ort_img.hdr')) image = np.array(image.open_memmap(), dtype=np.float32) good_bands = list(range(image.shape[2])) good_bands.remove(110) image = image[:, :, good_bands] indices = image == -50 image[indices] = -1 image[~indices] -= np.min(image[~indices]) image[~indices] /= np.max(image[~indices]) return image else: raise ValueError('Data source is not known')
Example #7
Source File: test_common.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def test_face(): assert_equal(face().shape, (768, 1024, 3))
Example #8
Source File: nomalize_img.py From deepdiy with MIT License | 5 votes |
def test(): from scipy.misc import face img=face() img=run(img) cv2.imshow('img',img) cv2.waitKey(0)
Example #9
Source File: test_image.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_connect_regions(): try: face = sp.face(gray=True) except AttributeError: # Newer versions of scipy have face in misc from scipy import misc face = misc.face(gray=True) for thr in (50, 150): mask = face > thr graph = img_to_graph(face, mask) assert_equal(ndimage.label(mask)[1], connected_components(graph)[0])
Example #10
Source File: test_image.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_connect_regions_with_grid(): try: face = sp.face(gray=True) except AttributeError: # Newer versions of scipy have face in misc from scipy import misc face = misc.face(gray=True) mask = face > 50 graph = grid_to_graph(*face.shape, mask=mask) assert_equal(ndimage.label(mask)[1], connected_components(graph)[0]) mask = face > 150 graph = grid_to_graph(*face.shape, mask=mask, dtype=None) assert_equal(ndimage.label(mask)[1], connected_components(graph)[0])
Example #11
Source File: test_image_loader.py From deepchem with MIT License | 5 votes |
def test_png_simple_load(self): loader = dc.data.ImageLoader() dataset = loader.featurize(self.face_path) # These are the known dimensions of face.png assert dataset.X.shape == (1, 768, 1024, 3)
Example #12
Source File: test_image.py From twitter-stock-recommendation with MIT License | 5 votes |
def _orange_face(face=None): face = _downsampled_face() if face is None else face face_color = np.zeros(face.shape + (3,)) face_color[:, :, 0] = 256 - face face_color[:, :, 1] = 256 - face / 2 face_color[:, :, 2] = 256 - face / 4 return face_color
Example #13
Source File: test_image.py From twitter-stock-recommendation with MIT License | 5 votes |
def _make_images(face=None): face = _downsampled_face() if face is None else face # make a collection of faces images = np.zeros((3,) + face.shape) images[0] = face images[1] = face + 1 images[2] = face + 2 return images
Example #14
Source File: test_image.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_extract_patches_all_color(): face = orange_face i_h, i_w = face.shape[:2] p_h, p_w = 16, 16 expected_n_patches = (i_h - p_h + 1) * (i_w - p_w + 1) patches = extract_patches_2d(face, (p_h, p_w)) assert_equal(patches.shape, (expected_n_patches, p_h, p_w, 3))
Example #15
Source File: test_image.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_extract_patches_all_rect(): face = downsampled_face face = face[:, 32:97] i_h, i_w = face.shape p_h, p_w = 16, 12 expected_n_patches = (i_h - p_h + 1) * (i_w - p_w + 1) patches = extract_patches_2d(face, (p_h, p_w)) assert_equal(patches.shape, (expected_n_patches, p_h, p_w))
Example #16
Source File: test_image.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_reconstruct_patches_perfect(): face = downsampled_face p_h, p_w = 16, 16 patches = extract_patches_2d(face, (p_h, p_w)) face_reconstructed = reconstruct_from_patches_2d(patches, face.shape) np.testing.assert_array_almost_equal(face, face_reconstructed)
Example #17
Source File: test_image.py From twitter-stock-recommendation with MIT License | 5 votes |
def test_reconstruct_patches_perfect_color(): face = orange_face p_h, p_w = 16, 16 patches = extract_patches_2d(face, (p_h, p_w)) face_reconstructed = reconstruct_from_patches_2d(patches, face.shape) np.testing.assert_array_almost_equal(face, face_reconstructed)
Example #18
Source File: test_image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_extract_patches_square(): # test same patch size for all dimensions face = downsampled_face i_h, i_w = face.shape p = 8 expected_n_patches = ((i_h - p + 1), (i_w - p + 1)) patches = extract_patches(face, patch_shape=p) assert patches.shape == (expected_n_patches[0], expected_n_patches[1], p, p)
Example #19
Source File: test_image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_reconstruct_patches_perfect_color(): face = orange_face p_h, p_w = 16, 16 patches = extract_patches_2d(face, (p_h, p_w)) face_reconstructed = reconstruct_from_patches_2d(patches, face.shape) np.testing.assert_array_almost_equal(face, face_reconstructed)
Example #20
Source File: test_image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_extract_patches_less_than_max_patches(): face = downsampled_face i_h, i_w = face.shape p_h, p_w = 3 * i_h // 4, 3 * i_w // 4 # this is 3185 expected_n_patches = (i_h - p_h + 1) * (i_w - p_w + 1) patches = extract_patches_2d(face, (p_h, p_w), max_patches=4000) assert_equal(patches.shape, (expected_n_patches, p_h, p_w))
Example #21
Source File: test_image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_extract_patch_same_size_image(): face = downsampled_face # Request patches of the same size as image # Should return just the single patch a.k.a. the image patches = extract_patches_2d(face, face.shape, max_patches=2) assert_equal(patches.shape[0], 1)
Example #22
Source File: test_image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_extract_patches_all_rect(): face = downsampled_face face = face[:, 32:97] i_h, i_w = face.shape p_h, p_w = 16, 12 expected_n_patches = (i_h - p_h + 1) * (i_w - p_w + 1) patches = extract_patches_2d(face, (p_h, p_w)) assert_equal(patches.shape, (expected_n_patches, p_h, p_w))
Example #23
Source File: test_image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_extract_patches_all_color(): face = orange_face i_h, i_w = face.shape[:2] p_h, p_w = 16, 16 expected_n_patches = (i_h - p_h + 1) * (i_w - p_w + 1) patches = extract_patches_2d(face, (p_h, p_w)) assert_equal(patches.shape, (expected_n_patches, p_h, p_w, 3))
Example #24
Source File: test_image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def _make_images(face=None): face = _downsampled_face() if face is None else face # make a collection of faces images = np.zeros((3,) + face.shape) images[0] = face images[1] = face + 1 images[2] = face + 2 return images
Example #25
Source File: test_image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def _orange_face(face=None): face = _downsampled_face() if face is None else face face_color = np.zeros(face.shape + (3,)) face_color[:, :, 0] = 256 - face face_color[:, :, 1] = 256 - face / 2 face_color[:, :, 2] = 256 - face / 4 return face_color
Example #26
Source File: test_image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def _downsampled_face(): try: face = sp.face(gray=True) except AttributeError: # Newer versions of scipy have face in misc from scipy import misc face = misc.face(gray=True) face = face.astype(np.float32) face = (face[::2, ::2] + face[1::2, ::2] + face[::2, 1::2] + face[1::2, 1::2]) face = (face[::2, ::2] + face[1::2, ::2] + face[::2, 1::2] + face[1::2, 1::2]) face = face.astype(np.float32) face /= 16.0 return face
Example #27
Source File: test_image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_connect_regions_with_grid(): try: face = sp.face(gray=True) except AttributeError: # Newer versions of scipy have face in misc from scipy import misc face = misc.face(gray=True) mask = face > 50 graph = grid_to_graph(*face.shape, mask=mask) assert_equal(ndimage.label(mask)[1], connected_components(graph)[0]) mask = face > 150 graph = grid_to_graph(*face.shape, mask=mask, dtype=None) assert_equal(ndimage.label(mask)[1], connected_components(graph)[0])
Example #28
Source File: test_image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def test_connect_regions(): try: face = sp.face(gray=True) except AttributeError: # Newer versions of scipy have face in misc from scipy import misc face = misc.face(gray=True) for thr in (50, 150): mask = face > thr graph = img_to_graph(face, mask) assert_equal(ndimage.label(mask)[1], connected_components(graph)[0])
Example #29
Source File: test_common.py From Computable with MIT License | 5 votes |
def test_face(): assert_equal(face().shape, (768, 1024, 3))
Example #30
Source File: test_image_loader.py From deepchem with MIT License | 5 votes |
def setUp(self): super(TestImageLoader, self).setUp() from PIL import Image self.current_dir = os.path.dirname(os.path.abspath(__file__)) self.tif_image_path = os.path.join(self.current_dir, "a_image.tif") # Create image file self.data_dir = tempfile.mkdtemp() self.face = misc.face() self.face_path = os.path.join(self.data_dir, "face.png") Image.fromarray(self.face).save(self.face_path) self.face_copy_path = os.path.join(self.data_dir, "face_copy.png") Image.fromarray(self.face).save(self.face_copy_path) # Create zip of image file #self.zip_path = "/home/rbharath/misc/cells.zip" self.zip_path = os.path.join(self.data_dir, "face.zip") zipf = zipfile.ZipFile(self.zip_path, "w", zipfile.ZIP_DEFLATED) zipf.write(self.face_path) zipf.close() # Create zip of multiple image files self.multi_zip_path = os.path.join(self.data_dir, "multi_face.zip") zipf = zipfile.ZipFile(self.multi_zip_path, "w", zipfile.ZIP_DEFLATED) zipf.write(self.face_path) zipf.write(self.face_copy_path) zipf.close() # Create zip of multiple image files, multiple_types self.multitype_zip_path = os.path.join(self.data_dir, "multitype_face.zip") zipf = zipfile.ZipFile(self.multitype_zip_path, "w", zipfile.ZIP_DEFLATED) zipf.write(self.face_path) zipf.write(self.tif_image_path) zipf.close() # Create image directory self.image_dir = tempfile.mkdtemp() face_path = os.path.join(self.image_dir, "face.png") Image.fromarray(self.face).save(face_path) face_copy_path = os.path.join(self.image_dir, "face_copy.png") Image.fromarray(self.face).save(face_copy_path)