import warnings
warnings.filterwarnings('ignore')
import numpy as np, seaborn as sns, os
from matplotlib import pyplot as plt
from sklearn import datasets
stimdir = '/mnt/c/Users/easso/docs/neurohackademy/eeg-notebooks/notebooks/stimulus_presentation/stim/olivetti_faces'
imprefix = 'image'
try:
os.makedirs(stimdir)
except:
pass
faces = datasets.fetch_olivetti_faces()
data = faces.data
images = faces.images
targets = faces.target
print(faces.DESCR)
for i in range(np.shape(images)[0]):
fig, ax=plt.subplots(1)
plt.imshow(images[i,:,:],'gray')
plt.axis('off')
ax.get_xaxis().set_visible(False) # this removes the ticks and numbers for x axis
ax.get_yaxis().set_visible(False) # this removes the ticks and numbers for y axis
plt.savefig(stimdir + '/' + imprefix + '_' + str(i+1) + '.jpg',bbox_inches='tight',pad_inches=0)
plt.close
This is a large dataset: 200MB! Use with caution.
stimdir = '/mnt/c/Users/easso/docs/neurohackademy/eeg-notebooks/notebooks/stimulus_presentation/stim/faces_in_wild'
imprefix = 'image'
n_images = 200
try:
os.makedirs(stimdir)
except:
pass
faces = datasets.fetch_lfw_people()
data = faces.data
images = faces.images
targets = faces.target
names = faces.target_names
for i in range(n_images):
fig, ax=plt.subplots(1)
plt.imshow(images[i,:,:],'gray')
plt.axis('off')
ax.get_xaxis().set_visible(False) # this removes the ticks and numbers for x axis
ax.get_yaxis().set_visible(False) # this removes the ticks and numbers for y axis
plt.savefig(stimdir + '/' + imprefix + '_' + str(i+1) + '.jpg',bbox_inches='tight',pad_inches=0)
plt.close
stimdir = '/mnt/c/Users/easso/docs/neurohackademy/eeg-notebooks/notebooks/stimulus_presentation/stim/digits'
imprefix = 'image'
n_images = 20
try:
os.makedirs(stimdir)
except:
pass
digits = datasets.load_digits()
data = digits.data
images = digits.images
targets = digits.target
names = digits.target_names
for i in range(n_images):
fig, ax=plt.subplots(1)
plt.imshow(images[i,:,:],'gray')
plt.axis('off')
ax.get_xaxis().set_visible(False) # this removes the ticks and numbers for x axis
ax.get_yaxis().set_visible(False) # this removes the ticks and numbers for y axis
plt.savefig(stimdir + '/' + imprefix + '_' + str(i+1) + '.jpg',bbox_inches='tight',pad_inches=0)
plt.close