matlab与python读取tiff文件
matlab
t=Tiff('IMG_3952.TIF', 'r+');
k = 1;
t.setDirectory(k);
img{k} = t.read();
src = img{1};
dst(:,:,1) = src(:,:,1) ;
dst(:,:,2) = src(:,:,2) ;
dst(:,:,3) = src(:,:,3) ;
figure;
imshow(dst);
python
#coding=utf-8
from libtiff import TIFF
from scipy import misc
##tiff文件解析成图像序列
##tiff_image_name: tiff文件名;
##out_folder:保存图像序列的文件夹
##out_type:保存图像的类型,如.jpg、.png、.bmp等
def tiff_to_image_array(tiff_image_name, out_folder, out_type):
tif = TIFF.open(tiff_image_name, mode = "r")
idx = 0
for im in list(tif.iter_images()):
#
im_name = out_folder + str(idx) + out_type
misc.imsave(im_name, im)
print (im_name, 'successfully saved!!!')
idx = idx + 1
return
##图像序列保存成tiff文件
##image_dir:图像序列所在文件夹
##file_name:要保存的tiff文件名
##image_type:图像序列的类型
##image_num:要保存的图像数目
def image_array_to_tiff(image_dir, file_name, image_type, image_num):
out_tiff = TIFF.open(file_name, mode = 'w')
#这里假定图像名按序号排列
for i in range(0, image_num):
image_name = image_dir + str(i) + image_type
image_array = Image.open(image_name)
#缩放成统一尺寸
img = image_array.resize((480, 480), Image.ANTIALIAS)
out_tiff.write_image(img, compression = None, write_rgb = True)
out_tiff.close()
return tiff_image_name = "IMG_3952.TIF"
out_folder = "123/"
out_type = ".bmp"
tiff_to_image_array(tiff_image_name, out_folder, out_type);
matlab与python读取tiff文件的更多相关文章
- Python读取txt文件
Python读取txt文件,有两种方式: (1)逐行读取 data=open("data.txt") line=data.readline() while line: print ...
- Python读取Yaml文件
近期看到好多使用Yaml文件做为配置文件或者数据文件的工程,随即也研究了下,发现Yaml有几个优点:可读性好.和脚本语言的交互性好(确实非常好).使用实现语言的数据类型.有一个一致的数据模型.易于实现 ...
- python读取中文文件编码问题
python 读取中文文件后,作为参数使用,经常会遇到乱码或者报错asii错误等. 我们需要对中文进行decode('gbk') 如我有一个data.txt文件有如下内容: 百度 谷歌 现在想读取文件 ...
- Python读取SQLite文件数据
近日在做项目时,意外听说有一种SQLite的数据库,相比自己之前使用的SQL Service甚是轻便,在对数据完整性.并发性要求不高的场景下可以尝试! 1.SQLite简介: SQLite是一个进程内 ...
- Python读取xlsx文件
Python读取xlsx文件 脚本如下: from openpyxl import load_workbook workbook = load_workbook(u'/tmp/test.xlsx') ...
- Python 读取WAV文件并绘制波形图
aa Python 读取WAV文件并绘制波形图 ffmpeg -i test_pcm_mulaw.wav -f wav -codec:a pcm_s16le -ar 8000 -ac 1 out.wa ...
- 使用python读取yaml文件
在做APP测试时,通常需要把参数存到一个字典变量中,这时可以将参数写入yaml文件中,再读取出来. 新建yaml文件(android_caps.yaml),文件内容为: platformName: A ...
- python 读取bin文件
python读取bin文件并下发串口 # coding:utf-8import time, serialfrom struct import *import binascii file = ope ...
- 记录:python读取excel文件
由于最近老是用到python读取excel文件,所以特意记录一下python读取excel文件的大体框架. 库:xlrd(读),直接pip安装即可.想要写excel文件的话,安装xlwd库即可,也是直 ...
随机推荐
- 使用requests进行模拟登陆
import re import requests header = { 'User-Agent': "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWe ...
- equals()与hashCode()
两个都可以用来判断两个对象是否相同一致. hashCode相同的不一定是同一个对象:hashCode不同的一定不是相同对象 equals相同的一定是相同对象,是绝对可靠的 既然equals这么可靠,那 ...
- C++程序设计方法3:对象组合
对象组合 包含其他类的对象 可以在类中使用其他类来定义数据成员,通常称为“子对象”:这种包含与被包含的对象间的关系称为“组合”,组合关系可以嵌套. 子对象构造时若需要参数,则应当在当前类的构造函数的初 ...
- BeanPostProcessor出现init方法无法被调用Invocation of init method failed
是因为 返回了null,要返回object即可,arg0是bean对象本身,arg1是bean名字,即bean的id
- 深入理解JVM(7)——类加载器
一.类和类加载器 a) 类加载器的作用:将class文件加载到JVM的方法区,并且在方法区中创建一个java.lang.Class对象作为外界访问这个类的接口. b) 类和 ...
- [asp.net core]The requested page cannot be accessed because the related configuration data for the page is invalid.
bug HTTP Error 500.19 - Internal Server Error The requested page cannot be accessed because the rela ...
- Accounting Calendar template
SELECT INITCAP (TO_CHAR (TO_DATE (&year || '-' || LPAD (ROWNUM, 2, '0'), 'yyyy-mm'), 'MON', 'NLS ...
- SpringMVC整合FastJson:用"最快的json转换工具"替换SpringMVC的默认json转换
2017年11月23日 09:18:03 阅读数:306 一.环境说明 Windows 10 1709 Spring 4.3.12.RELEASE FastJson 1.2.40 IDEA 2017. ...
- PDF.js实现个性化PDF渲染(文本复制)
我肥来啦
- Spark2.3(四十三):Spark Broadcast总结
为什么要使用广播(broadcast)变量? Spark中因为算子中的真正逻辑是发送到Executor中去运行的,所以当Executor中需要引用外部变量时,需要使用广播变量.进一步解释: 如果exe ...