资源简介
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实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论