本文整理汇总了Python中matplotlib.pyplot.imread方法的典型用法代码示例。如果您正苦于以下问题:Python pyplot.imread方法的具体用法?Python pyplot.imread怎么用?Python pyplot.imread使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.pyplot
的用法示例。
在下文中一共展示了pyplot.imread方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: draw_boxes
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def draw_boxes(filename, v_boxes, v_labels, v_scores, output_photo_name):
# load the image
data = pyplot.imread(filename)
# plot the image
pyplot.imshow(data)
# get the context for drawing boxes
ax = pyplot.gca()
# plot each box
for i in range(len(v_boxes)):
box = v_boxes[i]
# get coordinates
y1, x1, y2, x2 = box.ymin, box.xmin, box.ymax, box.xmax
# calculate width and height of the box
width, height = x2 - x1, y2 - y1
# create the shape
rect = Rectangle((x1, y1), width, height, fill=False, color='white')
# draw the box
ax.add_patch(rect)
# draw text and score in top left corner
label = "%s (%.3f)" % (v_labels[i], v_scores[i])
pyplot.text(x1, y1, label, color='white')
# show the plot
#pyplot.show()
pyplot.savefig(output_photo_name)
示例2: load_data
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def load_data(folder):
images_sat = [img for img in os.listdir(os.path.join(folder, "sat_img")) if fnmatch.fnmatch(img, "*.tif*")]
images_map = [img for img in os.listdir(os.path.join(folder, "map")) if fnmatch.fnmatch(img, "*.tif*")]
assert(len(images_sat) == len(images_map))
images_sat.sort()
images_map.sort()
# images are 1500 by 1500 pixels each
data = np.zeros((len(images_sat), 3, 1500, 1500), dtype=np.uint8)
target = np.zeros((len(images_sat), 1, 1500, 1500), dtype=np.uint8)
ctr = 0
for sat_im, map_im in zip(images_sat, images_map):
data[ctr] = plt.imread(os.path.join(folder, "sat_img", sat_im)).transpose((2, 0, 1))
# target has values 0 and 255. make that 0 and 1
target[ctr, 0] = plt.imread(os.path.join(folder, "map", map_im))/255
ctr += 1
return data, target
示例3: load_image
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def load_image(image_path):
"""
加载图像
:param image_path: 图像路径
:return: [h,w,3] numpy数组
"""
image = plt.imread(image_path)
# 灰度图转为RGB
if len(image.shape) == 2:
image = np.expand_dims(image, axis=2)
image = np.tile(image, (1, 1, 3))
elif image.shape[-1] == 1:
image = skimage.color.gray2rgb(image) # io.imread 报ValueError: Input image expected to be RGB, RGBA or gray
# 标准化为0~255之间
if image.dtype == np.float32:
image *= 255
image = image.astype(np.uint8)
# 删除alpha通道
return image[..., :3]
示例4: load_data
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def load_data(self):
# Please make sure to change this function to load your train/validation/test data.
train_data = np.array([plt.imread('./data/test_images/0.jpg'), plt.imread('./data/test_images/1.jpg'),
plt.imread('./data/test_images/2.jpg'), plt.imread('./data/test_images/3.jpg')])
self.X_train = train_data
self.y_train = np.array([284, 264, 682, 2])
val_data = np.array([plt.imread('./data/test_images/0.jpg'), plt.imread('./data/test_images/1.jpg'),
plt.imread('./data/test_images/2.jpg'), plt.imread('./data/test_images/3.jpg')])
self.X_val = val_data
self.y_val = np.array([284, 264, 682, 2])
self.train_data_len = self.X_train.shape[0]
self.val_data_len = self.X_val.shape[0]
img_height = 224
img_width = 224
num_channels = 3
return img_height, img_width, num_channels, self.train_data_len, self.val_data_len
示例5: load_large_image
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def load_large_image(img_path):
""" loading very large images
.. note:: For the loading we have to use matplotlib while ImageMagic nor other
lib (opencv, skimage, Pillow) is able to load larger images then 64k or 32k.
:param str img_path: path to the image
:return ndarray: image
"""
assert os.path.isfile(img_path), 'missing image: %s' % img_path
img = plt.imread(img_path)
if img.ndim == 3 and img.shape[2] == 4:
img = cvtColor(img, COLOR_RGBA2RGB)
if np.max(img) <= 1.5:
np.clip(img, a_min=0, a_max=1, out=img)
# this command split should reduce mount of required memory
np.multiply(img, 255, out=img)
img = img.astype(np.uint8, copy=False)
return img
示例6: previous
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def previous(self, event):
if (self.index>self.checkpoint):
self.index-=1
#print (self.img_paths[self.index][:-3]+'txt')
os.remove(self.img_paths[self.index][:-3]+'txt')
self.ax.clear()
self.ax.set_yticklabels([])
self.ax.set_xticklabels([])
image = plt.imread(self.img_paths[self.index])
self.ax.imshow(image, aspect='auto')
im = Image.open(self.img_paths[self.index])
width, height = im.size
im.close()
self.reset_all()
self.text+=str(self.index)+'\n'+os.path.abspath(self.img_paths[self.index])+'\n'+str(width)+' '+str(height)+'\n\n'
示例7: clusterClubs
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def clusterClubs(numClust=5):
datList = []
for line in open('places.txt').readlines():
lineArr = line.split('\t')
datList.append([float(lineArr[4]), float(lineArr[3])])
datMat = mat(datList)
myCentroids, clustAssing = biKmeans(datMat, numClust, distMeas=distSLC)
fig = plt.figure()
rect=[0.1,0.1,0.8,0.8]
scatterMarkers=['s', 'o', '^', '8', 'p', \
'd', 'v', 'h', '>', '<']
axprops = dict(xticks=[], yticks=[])
ax0=fig.add_axes(rect, label='ax0', **axprops)
imgP = plt.imread('Portland.png')
ax0.imshow(imgP)
ax1=fig.add_axes(rect, label='ax1', frameon=False)
for i in range(numClust):
ptsInCurrCluster = datMat[nonzero(clustAssing[:,0].A==i)[0],:]
markerStyle = scatterMarkers[i % len(scatterMarkers)]
ax1.scatter(ptsInCurrCluster[:,0].flatten().A[0], ptsInCurrCluster[:,1].flatten().A[0], marker=markerStyle, s=90)
ax1.scatter(myCentroids[:,0].flatten().A[0], myCentroids[:,1].flatten().A[0], marker='+', s=300)
plt.show()
示例8: test_imsave_color_alpha
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def test_imsave_color_alpha():
# Test that imsave accept arrays with ndim=3 where the third dimension is
# color and alpha without raising any exceptions, and that the data is
# acceptably preserved through a save/read roundtrip.
from numpy import random
random.seed(1)
data = random.rand(256, 128, 4)
buff = io.BytesIO()
plt.imsave(buff, data)
buff.seek(0)
arr_buf = plt.imread(buff)
# Recreate the float -> uint8 -> float32 conversion of the data
data = (255*data).astype('uint8').astype('float32')/255
# Wherever alpha values were rounded down to 0, the rgb values all get set
# to 0 during imsave (this is reasonable behaviour).
# Recreate that here:
for j in range(3):
data[data[:, :, 3] == 0, j] = 1
assert_array_equal(data, arr_buf)
示例9: test_pngsuite
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def test_pngsuite():
dirname = os.path.join(
os.path.dirname(__file__),
'baseline_images',
'pngsuite')
files = glob.glob(os.path.join(dirname, 'basn*.png'))
files.sort()
fig = plt.figure(figsize=(len(files), 2))
for i, fname in enumerate(files):
data = plt.imread(fname)
cmap = None # use default colormap
if data.ndim == 2:
# keep grayscale images gray
cmap = cm.gray
plt.imshow(data, extent=[i, i + 1, 0, 1], cmap=cmap)
plt.gca().patch.set_facecolor("#ddffff")
plt.gca().set_xlim(0, len(files))
示例10: test_pngsuite
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def test_pngsuite():
dirname = os.path.join(
os.path.dirname(__file__),
'baseline_images',
'pngsuite')
files = sorted(glob.iglob(os.path.join(dirname, 'basn*.png')))
fig = plt.figure(figsize=(len(files), 2))
for i, fname in enumerate(files):
data = plt.imread(fname)
cmap = None # use default colormap
if data.ndim == 2:
# keep grayscale images gray
cmap = cm.gray
plt.imshow(data, extent=[i, i + 1, 0, 1], cmap=cmap)
plt.gca().patch.set_facecolor("#ddffff")
plt.gca().set_xlim(0, len(files))
示例11: __init__
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def __init__(self, level='level1', scale=1):
self.level = level
if not '.' in level: level += '.bmp'
self.walls = np.logical_not(plt.imread(os.path.join(os.path.dirname(os.path.realpath(__file__)), level)))
self.height = self.walls.shape[0]
self.width = 32
# observations
self.screen_shape = (self.height, self.width)
self.padding = self.width // 2 - 1
self.padded_walls = np.logical_not(np.pad(np.logical_not(self.walls), ((0, 0), (self.padding, self.padding)), 'constant'))
self.observation_space = spaces.Box(0, 255, (self.height, self.width, 3), dtype=np.float32)
# coordinates
self.scale = scale
self.coords_shape = (self.height // scale, self.width // scale)
self.available_coords = np.array(np.where(np.logical_not(self.walls))).transpose()
# actions
self.action_space = spaces.Discrete(4)
# miscellaneous
self.name = 'GridWorld_obs{}x{}x3_qframes{}x{}x4-v0'.format(*self.screen_shape, *self.coords_shape)
self.viewer = None
self.seed()
示例12: load_segmap_as_matrix
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def load_segmap_as_matrix(
map_path: str,
label_resolution: int = VSEG_LABEL_RESOLUTION):
"""
Loads a .map file and returns a matrix of the label values (uint8 between 0
and 255).
Args:
map_path: path to the .map file to load
label_resolution: max. number of labels used in the map's encoding,
must be a power of 2
Returns:
A np.ndarray of the semantic segmentation labels.
"""
png_map = plt.imread(map_path)
label_bin_size = MAX_LABELS // label_resolution
lbl_map = np.copy(png_map[:, :, 0]) # slice of first image layer
lbl_map = lbl_map / label_bin_size
return lbl_map
示例13: demo2
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def demo2(fun):
'''
Smiled Monalisa
'''
p = np.array([
[186, 140], [295, 135], [208, 181], [261, 181], [184, 203], [304, 202], [213, 225],
[243, 225], [211, 244], [253, 244], [195, 254], [232, 281], [285, 252]
])
q = np.array([
[186, 140], [295, 135], [208, 181], [261, 181], [184, 203], [304, 202], [213, 225],
[243, 225], [207, 238], [261, 237], [199, 253], [232, 281], [279, 249]
])
image = plt.imread(os.path.join(sys.path[0], "monalisa.jpg"))
plt.subplot(121)
plt.axis('off')
plt.imshow(image)
transformed_image = fun(image, p, q, alpha=1, density=1)
plt.subplot(122)
plt.axis('off')
plt.imshow(transformed_image)
plt.tight_layout(w_pad=1.0, h_pad=1.0)
plt.show()
示例14: load_data
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def load_data(self):
# This method is an example of loading a dataset. Change it to suit your needs..
import matplotlib.pyplot as plt
# For going in the same experiment as the paper. Resizing the input image data to 224x224 is done.
train_data = np.array([plt.imread('./data/0.jpg')], dtype=np.float32)
self.X_train = train_data
self.y_train = np.array([283], dtype=np.int32)
val_data = np.array([plt.imread('./data/0.jpg')], dtype=np.float32)
self.X_val = val_data
self.y_val = np.array([283])
self.train_data_len = self.X_train.shape[0]
self.val_data_len = self.X_val.shape[0]
img_height = 224
img_width = 224
num_channels = 3
return img_height, img_width, num_channels, self.train_data_len, self.val_data_len
示例15: test_display_ImageVizArray
# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import imread [as 别名]
def test_display_ImageVizArray(display, data):
"""Assert that show calls the mocked display function
"""
image_path = os.path.join(os.path.dirname(__file__), 'mosaic.png')
image = imread(image_path)
coordinates = [
[-123.40515640309, 32.08296982365502],
[-115.92938988349292, 32.08296982365502],
[-115.92938988349292, 38.534294809274336],
[-123.40515640309, 38.534294809274336]][::-1]
viz = ImageViz(image, coordinates, access_token=TOKEN)
viz.show()
display.assert_called_once()