资源简介
python实现yuv转RGB图片程序,更多说明访问我的博客https://blog.csdn.net/bvngh3247

代码片段和文件信息
“““
Paper: “Fast and Accurate Image Super Resolution by Deep CNN with Skip Connection and Network in Network“
utility functions
“““
import os
import numpy as np
from scipy import misc
from PIL import Image
class LoadError(Exception):
def __init__(self message):
self.message = message
def load_image(filename width=0 height=0 channels=0 alignment=0 print_console=True):
if not os.path.isfile(filename):
raise LoadError(“File not found [%s]“ % filename)
image = misc.imread(filename)
if len(image.shape) == 2:
image = image.reshape(image.shape[0] image.shape[1] 1)
if (width != 0 and image.shape[1] != width) or (height != 0 and image.shape[0] != height):
raise LoadError(“Attributes mismatch“)
if channels != 0 and image.shape[2] != channels:
raise LoadError(“Attributes mismatch“)
if alignment != 0 and ((width % alignment) != 0 or (height % alignment) != 0):
raise LoadError(“Attributes mismatch“)
if print_console:
print(“Loaded [%s]: %d x %d x %d“ % (filename image.shape[1] image.shape[0] image.shape[2]))
return image
def save_image(filename image print_console=True):
if len(image.shape) >= 3 and image.shape[2] == 1:
image = image.reshape(image.shape[0] image.shape[1])
directory = os.path.dirname(filename)
if directory != ““ and not os.path.exists(directory):
os.makedirs(directory)
image = misc.toimage(image cmin=0 cmax=255) # to avoid range rescaling
misc.imsave(filename image)
if print_console:
print(“Saved [%s]“ % filename)
def convert_rgb_to_ycbcr(image jpeg_mode=True max_value=255):
if len(image.shape) < 2 or image.shape[2] == 1:
return image
if jpeg_mode:
xform = np.array([[0.299 0.587 0.114] [-0.169 - 0.331 0.500] [0.500 - 0.419 - 0.081]])
ycbcr_image = image.dot(xform.T)
ycbcr_image[: : [1 2]] += max_value / 2
else:
xform = np.array(
[[65.481 / 256.0 128.553 / 256.0 24.966 / 256.0] [- 37.945 / 256.0 - 74.494 / 256.0 112.439 / 256.0]
[112.439 / 256.0 - 94.154 / 256.0 - 18.285 / 256.0]])
ycbcr_image = image.dot(xform.T)
ycbcr_image[: : 0] += (16.0 * max_value / 256.0)
ycbcr_image[: : [1 2]] += (128.0 * max_value / 256.0)
return ycbcr_image
def convert_rgb_to_y(image jpeg_mode=True max_value=255.0):
if len(image.shape) <= 2 or image.shape[2] == 1:
return image
if jpeg_mode:
xform = np.array([[0.299 0.587 0.114]])
y_image = image.dot(xform.T)
else:
xform = np.array([[65.481 / 256.0 128.553 / 256.0 24.966 / 256.0]])
y_image = image.dot(xform.T) + (16.0 * max_value / 256.0)
return y_image
def read_yuv420_file(r_file y cb cr w h frame_num):
my_file = open(r_file‘rb‘)
my_file.read((frame_num-1)*int(w*h*3/2))
for num in range(0 1):
print (‘frame = ‘ + str(frame_num))
for i in range(0 h):
for j in range(0 w):
data = my_file.read(1)
data = ord(data)
y[i j] = data
for y in
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 6597 2018-11-08 16:27 utilty.py
文件 1499 2018-11-09 14:40 yuv_rgb.py
----------- --------- ---------- ----- ----
8096 2
- 上一篇:简易版扫雷python实现
- 下一篇:python 版本的k-means算法
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论