本文整理汇总了Python中menpo.io.import_image函数的典型用法代码示例。如果您正苦于以下问题:Python import_image函数的具体用法?Python import_image怎么用?Python import_image使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了import_image函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: blue_peter
def blue_peter():
import menpo.io as mio
import h5it
from menpo.visualize.image import glyph
from menpo.feature import hog
import matplotlib.pyplot as plt
# Loading the pre-built HOG AAM
import cPickle as pickle
with open('/Users/pts08/hog_lfpw_aam.pkl', 'rb') as f:
hog_aam = pickle.load(f)
#hog_aam = h5it.load('/Users/pts08/sparse_hog.hdf5')
print('Here is one I made earlier!')
bp = mio.import_image('blue_peter.jpg')
hog_blue_peter = hog(bp)
plt.figure()
plt.subplot(121)
bp.view()
plt.axis('off')
plt.gcf().set_size_inches(11, 11)
plt.title('RGB')
plt.subplot(122)
glyph(hog_blue_peter).view()
plt.axis('off')
plt.gcf().set_size_inches(11, 11)
plt.title('HOG')
return hog_aam
示例2: image
def image(self):
if self._image is None:
image = mio.import_image(self._image_path)
image.crop_to_landmarks_proportion_inplace(0.5)
self._image = image
return self._image
示例3: test_importing_I_no_normalise
def test_importing_I_no_normalise(is_file, mock_image):
mock_image.return_value = PILImage.new('I', (10, 10))
is_file.return_value = True
im = mio.import_image('fake_image_being_mocked.jpg', normalise=False)
assert im.shape == (10, 10)
assert im.n_channels == 1
assert im.pixels.dtype == np.int32
示例4: test_importing_PIL_L_normalise
def test_importing_PIL_L_normalise(is_file, mock_image):
mock_image.return_value = PILImage.new('L', (10, 10))
is_file.return_value = True
im = mio.import_image('fake_image_being_mocked.ppm', normalise=True)
assert im.shape == (10, 10)
assert im.n_channels == 1
assert im.pixels.dtype == np.float
示例5: test_importing_PIL_P_no_normalize
def test_importing_PIL_P_no_normalize(is_file, mock_image):
mock_image.return_value = PILImage.new('P', (10, 10))
is_file.return_value = True
im = mio.import_image('fake_image_being_mocked.ppm', normalize=False)
assert im.shape == (10, 10)
assert im.n_channels == 3
assert im.pixels.dtype == np.uint8
示例6: test_importing_imageio_RGB_no_normalise
def test_importing_imageio_RGB_no_normalise(is_file, mock_image):
mock_image.return_value = np.zeros([10, 10, 3], dtype=np.uint8)
is_file.return_value = True
im = mio.import_image('fake_image_being_mocked.jpg', normalise=False)
assert im.shape == (10, 10)
assert im.n_channels == 3
assert im.pixels.dtype == np.uint8
示例7: image
def image(self):
if self._image is None:
image_ = mio.import_image(self._image_path)
image = Image(np.rollaxis(image_.pixels, -1))
image.landmarks = image_.landmarks
image.crop_to_landmarks_proportion_inplace(0.5)
self._image = image
return self._image
示例8: ply_importer
def ply_importer(filepath, asset=None, texture_resolver=None, **kwargs):
"""Allows importing Wavefront (OBJ) files.
Uses VTK.
Parameters
----------
asset : `object`, optional
An optional asset that may help with loading. This is unused for this
implementation.
texture_resolver : `callable`, optional
A callable that recieves the mesh filepath and returns a single
path to the texture to load.
\**kwargs : `dict`, optional
Any other keyword arguments.
Returns
-------
shape : :map:`PointCloud` or subclass
The correct shape for the given inputs.
"""
import vtk
from vtk.util.numpy_support import vtk_to_numpy
ply_importer = vtk.vtkPLYReader()
ply_importer.SetFileName(str(filepath))
ply_importer.Update()
# Get the output
polydata = ply_importer.GetOutput()
# We must have point data!
points = vtk_to_numpy(polydata.GetPoints().GetData()).astype(np.float)
trilist = np.require(vtk_ensure_trilist(polydata), requirements=['C'])
texture = None
if texture_resolver is not None:
texture_path = texture_resolver(filepath)
if texture_path is not None and texture_path.exists():
texture = mio.import_image(texture_path)
tcoords = None
if texture is not None:
try:
tcoords = vtk_to_numpy(polydata.GetPointData().GetTCoords())
except Exception:
pass
if isinstance(tcoords, np.ndarray) and tcoords.size == 0:
tcoords = None
colour_per_vertex = None
return _construct_shape_type(points, trilist, tcoords, texture,
colour_per_vertex)
示例9: test_importing_PIL_RGBA_normalize
def test_importing_PIL_RGBA_normalize(is_file, mock_image):
from menpo.image import MaskedImage
mock_image.return_value = PILImage.new('RGBA', (10, 10))
is_file.return_value = True
im = mio.import_image('fake_image_being_mocked.ppm', normalize=True)
assert im.shape == (10, 10)
assert im.n_channels == 3
assert im.pixels.dtype == np.float
assert type(im) == MaskedImage
示例10: test_importing_PIL_1_no_normalize
def test_importing_PIL_1_no_normalize(is_file, mock_image):
from menpo.image import BooleanImage
mock_image.return_value = PILImage.new('1', (10, 10))
is_file.return_value = True
im = mio.import_image('fake_image_being_mocked.ppm', normalize=False)
assert im.shape == (10, 10)
assert im.n_channels == 1
assert im.pixels.dtype == np.bool
assert type(im) == BooleanImage
示例11: getImageFromFile
def getImageFromFile(path):
def load_image(i):
i = i.crop_to_landmarks_proportion(0.5)
if i.n_channels == 3:
i = i.as_greyscale()
labeller(i, 'PTS', face_ibug_68_to_face_ibug_68)
return i
image_path = Path(path)
i = load_image(mio.import_image(image_path))
return i
示例12: test_register_image_importer
def test_register_image_importer(is_file):
from menpo.image import Image
image = Image.init_blank((10, 10))
def foo_importer(filepath, **kwargs):
return image
is_file.return_value = True
with patch.dict(mio.input.extensions.image_types, {}, clear=True):
mio.register_image_importer('.foo', foo_importer)
new_image = mio.import_image('fake.foo')
assert image is new_image
示例13: test_importing_imageio_GIF_no_normalise
def test_importing_imageio_GIF_no_normalise(is_file, mock_image):
mock_image.return_value.get_data.return_value = np.ones((10, 10, 3),
dtype=np.uint8)
mock_image.return_value.get_length.return_value = 2
is_file.return_value = True
ll = mio.import_image('fake_image_being_mocked.gif', normalise=False)
assert len(ll) == 2
im = ll[0]
assert im.shape == (10, 10)
assert im.n_channels == 3
assert im.pixels.dtype == np.uint8
示例14: load_images
def load_images(list_frames, frames_path, path_land, clip_name, max_images=None,
training_images=None, crop_reading=0.3, pix_thres=330, feat=None):
"""
Read images from the clips that are processed. The landmarks can be a different folder with the extension of pts and
are searched as such.
:param list_frames: List of images that will be read and loaded.
:param frames_path: Path to the folder of images.
:param path_land: Path of the respective landmarks.
:param clip_name: The name of the clip being processed.
:param max_images: (optional) Max images that will be loaded from this clip.
:param training_images: (optional) List of images to append the new ones.
:param crop_reading: (optional) Amount of cropping the image around the landmarks.
:param pix_thres: (optional) If the cropped image has a dimension bigger than this, it gets cropped to this diagonal dimension.
:param feat: (optional) Features to be applied to the images before inserting them to the list.
:return: List of menpo images.
"""
from random import shuffle
if not check_path_and_landmarks(frames_path, clip_name, path_land):
return []
if feat is None:
feat = no_op
if training_images is None:
training_images = []
shuffle(list_frames) # shuffle the list to ensure random ones are chosen
if max_images is None:
max_images = len(list_frames)
elif max_images < 0:
print('Warning: The images cannot be negative, loading the whole list instead.')
max_images = len(list_frames)
cnt = 0 # counter for images appended to the list
for frame_name in list_frames:
try:
im = mio.import_image(frames_path + frame_name, normalise=True)
except ValueError: # in case the extension is unknown (by menpo)
print('Ignoring the \'image\' {}.'.format(frame_name))
continue
res = glob.glob(path_land + clip_name + sep + im.path.stem + '*.pts')
if len(res) == 0: # if the image does not have any existing landmarks, ignore it
continue
elif len(res) > 1:
#_r = randint(0,len(res)-1); #just for debugging reasons in different variable
#ln = mio.import_landmark_file(res[_r]) # in case there are plenty of landmarks for the image, load random ones
print('The image {} has more than one landmarks, for one person, loading only the first ones.'.format(frame_name))
ln = mio.import_landmark_file(res[0])
im.landmarks['PTS'] = ln
im = crop_rescale_img(im, crop_reading=crop_reading, pix_thres=pix_thres)
training_images.append(feat(im))
cnt += 1
if cnt >= max_images:
break # the limit of images (appended to the list) is reached
return training_images
示例15: load_image
def load_image(path, reference_shape, is_training=False, group='PTS',
mirror_image=False):
"""Load an annotated image.
In the directory of the provided image file, there
should exist a landmark file (.pts) with the same
basename as the image file.
Args:
path: a path containing an image file.
reference_shape: a numpy array [num_landmarks, 2]
is_training: whether in training mode or not.
group: landmark group containing the grounth truth landmarks.
mirror_image: flips horizontally the image's pixels and landmarks.
Returns:
pixels: a numpy array [width, height, 3].
estimate: an initial estimate a numpy array [68, 2].
gt_truth: the ground truth landmarks, a numpy array [68, 2].
"""
im = mio.import_image(path)
bb_root = im.path.parent.relative_to(im.path.parent.parent.parent)
if 'set' not in str(bb_root):
bb_root = im.path.parent.relative_to(im.path.parent.parent)
im.landmarks['bb'] = mio.import_landmark_file(str(Path('bbs') / bb_root / (
im.path.stem + '.pts')))
im = im.crop_to_landmarks_proportion(0.3, group='bb')
reference_shape = PointCloud(reference_shape)
bb = im.landmarks['bb'].lms.bounding_box()
im.landmarks['__initial'] = align_shape_with_bounding_box(reference_shape,
bb)
im = im.rescale_to_pointcloud(reference_shape, group='__initial')
if mirror_image:
im = utils.mirror_image(im)
lms = im.landmarks[group].lms
initial = im.landmarks['__initial'].lms
# if the image is greyscale then convert to rgb.
pixels = grey_to_rgb(im).pixels.transpose(1, 2, 0)
gt_truth = lms.points.astype(np.float32)
estimate = initial.points.astype(np.float32)
return pixels.astype(np.float32).copy(), gt_truth, estimate