本文整理汇总了Python中skimage.io方法的典型用法代码示例。如果您正苦于以下问题:Python skimage.io方法的具体用法?Python skimage.io怎么用?Python skimage.io使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类skimage
的用法示例。
在下文中一共展示了skimage.io方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __call__
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def __call__(self, result, out_dir, image_name):
result_tool = ShowResultTool()
result = result_tool(result)
if 'GrayDisparity' in result.keys():
grayEstDisp = result['GrayDisparity']
gray_save_path = osp.join(out_dir, 'flow_0')
mkdir_or_exist(gray_save_path)
skimage.io.imsave(osp.join(gray_save_path, image_name), (grayEstDisp * 256).astype('uint16'))
if 'ColorDisparity' in result.keys():
colorEstDisp = result['ColorDisparity']
color_save_path = osp.join(out_dir, 'color_disp')
mkdir_or_exist(color_save_path)
plt.imsave(osp.join(color_save_path, image_name), colorEstDisp, cmap=plt.cm.hot)
if 'GroupColor' in result.keys():
group_save_path = os.path.join(out_dir, 'group_flow')
mkdir_or_exist(group_save_path)
plt.imsave(osp.join(group_save_path, image_name), result['GroupColor'], cmap=plt.cm.hot)
示例2: __call__
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def __call__(self, result, out_dir, image_name):
result_tool = ShowResultTool()
result = result_tool(result, color_map='gray', bins=100)
if 'GrayDisparity' in result.keys():
grayEstDisp = result['GrayDisparity']
gray_save_path = osp.join(out_dir, 'disp_0')
mkdir_or_exist(gray_save_path)
skimage.io.imsave(osp.join(gray_save_path, image_name), (grayEstDisp * 256).astype('uint16'))
if 'ColorDisparity' in result.keys():
colorEstDisp = result['ColorDisparity']
color_save_path = osp.join(out_dir, 'color_disp')
mkdir_or_exist(color_save_path)
plt.imsave(osp.join(color_save_path, image_name), colorEstDisp, cmap=plt.cm.hot)
if 'GroupColor' in result.keys():
group_save_path = os.path.join(out_dir, 'group_disp')
mkdir_or_exist(group_save_path)
plt.imsave(osp.join(group_save_path, image_name), result['GroupColor'], cmap=plt.cm.hot)
if 'ColorConfidence' in result.keys():
conf_save_path = os.path.join(out_dir, 'confidence')
mkdir_or_exist(conf_save_path)
plt.imsave(osp.join(conf_save_path, image_name), result['ColorConfidence'])
示例3: load_image_array
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def load_image_array(image_file, image_size):
img = skimage.io.imread(image_file)
# GRAYSCALE
if len(img.shape) == 2:
img_new = np.ndarray( (img.shape[0], img.shape[1], 3), dtype = 'uint8')
img_new[:,:,0] = img
img_new[:,:,1] = img
img_new[:,:,2] = img
img = img_new
img_resized = skimage.transform.resize(img, (image_size, image_size))
# FLIP HORIZONTAL WIRH A PROBABILITY 0.5
if random.random() > 0.5:
img_resized = np.fliplr(img_resized)
return img_resized.astype('float32')
示例4: load_img
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def load_img(path):
"""Returns a numpy array of an image specified by its path.
Args:
path: string representing the file path of the image to load
Returns:
resized_img: numpy array representing the loaded RGB image
shape: the image shape
"""
# Load image [height, width, depth]
img = skimage.io.imread(path) / 255.0
assert (0 <= img).all() and (img <= 1.0).all()
# Crop image from center
short_edge = min(img.shape[:2])
yy = int((img.shape[0] - short_edge) / 2)
xx = int((img.shape[1] - short_edge) / 2)
shape = list(img.shape)
crop_img = img[yy: yy + short_edge, xx: xx + short_edge]
resized_img = skimage.transform.resize(crop_img, (shape[0], shape[1]))
return resized_img, shape
示例5: load_image_array_flowers
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def load_image_array_flowers(image_file, image_size):
img = skimage.io.imread(image_file)
# GRAYSCALE
if len(img.shape) == 2:
img_new = np.ndarray( (img.shape[0], img.shape[1], 3), dtype = 'uint8')
img_new[:,:,0] = img
img_new[:,:,1] = img
img_new[:,:,2] = img
img = img_new
img_resized = skimage.transform.resize(img, (image_size, image_size))
# FLIP HORIZONTAL WIRH A PROBABILITY 0.5
if random.random() > 0.5:
img_resized = np.fliplr(img_resized)
return img_resized.astype('float32')
示例6: _update_html_assets
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def _update_html_assets(self, json_data):
"""Update the html file and assets"""
assets_path = os.path.join(os.path.dirname(__file__), 'assets')
dest_path = self.qc_params.root_folder
with io.open(os.path.join(assets_path, 'index.html')) as template_index:
template = Template(template_index.read())
output = template.substitute(sct_json_data=json.dumps(json_data))
io.open(os.path.join(dest_path, 'index.html'), 'w').write(output)
for path in ['css', 'js', 'imgs', 'fonts']:
src_path = os.path.join(assets_path, '_assets', path)
dest_full_path = os.path.join(dest_path, '_assets', path)
if not os.path.exists(dest_full_path):
os.makedirs(dest_full_path, exist_ok = True)
for file_ in os.listdir(src_path):
if not os.path.isfile(os.path.join(dest_full_path, file_)):
sct.copy(os.path.join(src_path, file_),
dest_full_path)
示例7: crop_image
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def crop_image(self, x, target_height=224, target_width=224):
image = skimage.img_as_float(skimage.io.imread(x)).astype(np.float32)
if len(image.shape) == 2:
image = np.tile(image[:,:,None], 3)
elif len(image.shape) == 4:
image = image[:,:,:,0]
height, width, rgb = image.shape
if width == height:
resized_image = cv2.resize(image, (target_height,target_width))
elif height < width:
resized_image = cv2.resize(image, (int(width * float(target_height)/height), target_width))
cropping_length = int((resized_image.shape[1] - target_height) / 2)
resized_image = resized_image[:,cropping_length:resized_image.shape[1] - cropping_length]
else:
resized_image = cv2.resize(image, (target_height, int(height * float(target_width) / width)))
cropping_length = int((resized_image.shape[0] - target_width) / 2)
resized_image = resized_image[cropping_length:resized_image.shape[0] - cropping_length,:]
return cv2.resize(resized_image, (target_height, target_width))
####### Network Parameters ########
示例8: load_scaled_image
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def load_scaled_image( filename, color=True ):
"""
Load an image converting from grayscale or alpha as needed.
From KChen
Args:
filename : string
color : boolean
flag for color format. True (default) loads as RGB while False
loads as intensity (if image is already grayscale).
Returns
image : an image with type np.float32 in range [0, 1]
of size (H x W x 3) in RGB or
of size (H x W x 1) in grayscale.
By kchen
"""
img = skimage.img_as_float(skimage.io.imread(filename, as_grey=not color)).astype(np.float32)
if img.ndim == 2:
img = img[:, :, np.newaxis]
if color:
img = np.tile(img, (1, 1, 3))
elif img.shape[2] == 4:
img = img[:, :, :3]
return img
示例9: flowList
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def flowList(xFileNames, yFileNames):
'''
(x/y)fileNames: List of the fileNames in order to get the flows from
'''
frameList = []
if (len(xFileNames) != len(yFileNames)):
print 'XFILE!=YFILE ERROR: In', xFileNames[0]
for i in range(0, min(len(xFileNames), len(yFileNames))):
imgX = io.imread(xFileNames[i])
imgY = io.imread(yFileNames[i])
frameList.append(np.dstack((imgX, imgY)))
frameList = np.array(frameList)
return frameList
示例10: create_transformer
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def create_transformer(self):
"""
Create the preprocessor and deprocessor using the default settings for
the VGG-19 network.
"""
# Give transformer necessary imput shape. Should be specified from
# argparse arguments when creating the net
transformer = caffe.io.Transformer(
{'data': self.net.blobs['data'].data.shape}
)
# Order of the channels in the input data (not sure why necessary)
transformer.set_transpose('data', (2, 0, 1))
# Use BGR rather than RGB
transformer.set_channel_swap('data', (2, 1, 0))
# Subtract mean pixel
transformer.set_mean('data', MEAN_PIXEL)
# Use 8bit image values
transformer.set_raw_scale('data', 255)
return transformer
示例11: set_content_target
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def set_content_target(self, img):
"""
Create content representation of image and set as the content target.
"""
# XXX: Assume only one content layer
cl = CONTENT_LAYERS[0]
contenti = caffe.io.load_image(img)
# Resize image, set net and transformer shapes accordingly
scaled = self.resize_image(contenti)
self.resize_caffes(scaled)
contenti_pp = self.transformer.preprocess('data', scaled)
self.net.blobs['data'].data[...] = contenti_pp
self.net.forward()
self.content_target = self.net.blobs[cl].data[0].copy()
# Get contenti_pp (after transformer)
self.content_target = (
np.reshape(
self.content_target,
(self.content_target.shape[0],
self.content_target.shape[1] * self.content_target.shape[2]))
)
示例12: load
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def load(path, dtype=np.float64):
"""
Loads an image from file.
Parameters
----------
path : str
Path to image file.
dtype : np.dtype
Defaults to ``np.float64``, which means the image will be returned as a
float with values between 0 and 1. If ``np.uint8`` is specified, the
values will be between 0 and 255 and no conversion cost will be
incurred.
"""
_import_skimage()
import skimage.io
im = skimage.io.imread(path)
if dtype == np.uint8:
return im
elif dtype in {np.float16, np.float32, np.float64}:
return im.astype(dtype) / 255
else:
raise ValueError('Unsupported dtype')
示例13: load_image
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def load_image(path):
# Load image [height, width, depth]
img = skimage.io.imread(path) / 255.0
assert (0 <= img).all() and (img <= 1.0).all()
# Crop image from center
short_edge = min(img.shape[:2])
yy = int((img.shape[0] - short_edge) / 2)
xx = int((img.shape[1] - short_edge) / 2)
shape = list(img.shape)
crop_img = img[yy: yy + short_edge, xx: xx + short_edge]
resized_img = skimage.transform.resize(crop_img, (shape[0], shape[1]))
return resized_img, shape
# Return a resized numpy array of an image specified by its path
示例14: load_image2
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def load_image2(path, height=None, width=None):
# Load image
img = skimage.io.imread(path) / 255.0
if height is not None and width is not None:
ny = height
nx = width
elif height is not None:
ny = height
nx = img.shape[1] * ny / img.shape[0]
elif width is not None:
nx = width
ny = img.shape[0] * nx / img.shape[1]
else:
ny = img.shape[0]
nx = img.shape[1]
return skimage.transform.resize(img, (ny, nx))
# Render the generated image given a tensorflow session and a variable image (x)
示例15: train_main
# 需要导入模块: import skimage [as 别名]
# 或者: from skimage import io [as 别名]
def train_main():
path_dir = '/home/ruifengshan/github/12306-captcha/data/download/'
img_names = filter(lambda s: not s.startswith("."), os.listdir(path_dir + '/all'))
for img_name in img_names:
im = cut_image.read_image(os.path.join(path_dir + '/all', img_name))
if im is None:
print "该图片{ %s }处理异常: " % img_name
continue
# 转为灰度图
list_text = judge_words(cut_image.get_text(cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)))
print "文字部分的内容:"
for text in list_text:
print text
judge_image(cut_image.get_image(im), list_text)
skimage.io.imshow(im)