pythontiff读取
⑴ 如何用python读取和写入TIFF文件1
Python读写文件
1.open
使用open打开文件后一定要记得调用文件对象的close()方法。比如可以用try/finally语句来确保最后能关闭文件。
file_object = open('thefile.txt')
try:
all_the_text = file_object.read( )
finally:
file_object.close( )
注:不能把open语句放在try块里,因为当打开文件出现异常时,文件对象file_object无法执行close()方法。
2.读文件
读文本文件
input = open('data', 'r')
#第二个参数默认为r
input = open('data')
读二进制文件
input = open('data', 'rb')
读取所有内容
file_object = open('thefile.txt')
try:
all_the_text = file_object.read( )
finally:
file_object.close( )
读固定字节
file_object = open('abinfile', 'rb')
try:
while True:
chunk = file_object.read(100)
if not chunk:
break
do_something_with(chunk)
finally:
file_object.close( )
读每行
list_of_all_the_lines = file_object.readlines( )
如果文件是文本文件,还可以直接遍历文件对象获取每行:
for line in file_object:
process line
3.写文件
写文本文件
output = open('data', 'w')
写二进制文件
output = open('data', 'wb')
追加写文件
output = open('data', 'w+')
写数据
file_object = open('thefile.txt', 'w')
file_object.write(all_the_text)
file_object.close( )
写入多行
file_object.writelines(list_of_text_strings)
注意,调用writelines写入多行在性能上会比使用write一次性写入要高。
⑵ python 用PIL打开TIFF格式图片无法转换为灰度图是为什么一直报错,有代码注释,和错误截图
It's either a bug or unimplemented in PIL/Pillow. Here is a workaround:
import Image
image = Image.open("Fredy1_002.tif")
image.mode = 'I'
image.point(lambda i:i*(1./256)).convert('L').save('my.jpeg')
⑶ python 怎么打开tiff影像
1. Scikit-learn Scikit-learn 是基于Scipy为机器学习建造的的一个Python模块,他的特色就是多样化的分类,回归和聚类的算法包括支持向量机,逻辑回归,朴素贝叶斯分类器,随机森林,Gradient Boosting,聚类算法和DBSCAN。而且也设计出了Python...
⑷ 如何读取多页TIFF图像中任意一页
Imports System.Drawing.Image
________________________________
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Sets the tiff file as an image object.
Dim objImage As Drawing.Image
objImage = objImage.FromFile(txtAddress.Text)
Dim objGuid As Guid = (objImage.FrameDimensionsList(0))
Dim objDimension As System.Drawing.Imaging.FrameDimension = New System.Drawing.Imaging.FrameDimension(objGuid)
'Gets the total number of frames in the .tiff file
Dim totFrame As Int16
totFrame = objImage.GetFrameCount(objDimension)
'Adds number of frames to the combo box for displaying purposes.
Dim i As Integer
For i = 0 To totFrame - 1
cboFrameNo.Items.Add(i)
Next
cboFrameNo.Items.IndexOf(1)
'Sets the temporary folder to "C:\temp\"
Dim strPath As String
strPath = "c:\temp\"
'Saves every frame as a seperate file.
Dim z, curF As Integer
z = 0
curF = 0'curF是页码
For z = 0 To 1'(totFrame - 1)
objImage.SelectActiveFrame(objDimension, curF)
objImage.Save(strPath & curF & ".tif", Imaging.ImageFormat.Tiff)
curF = curF + 1
Next
End Sub
⑸ 如何用python读取和写入TIFF文件1
使用open打开文件后一定要记得调用文件对象的close()方法。比如可以用try/finally语句来确保最后能关闭文件。
file_object = open('thefile.txt')
try:
all_the_text = file_object.read( )
finally
⑹ 如何用python对文件夹下的tif文件(有多种文件类型)重命名,换成1,2,3,4这种
import os
n=1
for x in os.listdir(r'e:/tif'): #文件夹路径自己改
if x[-3:]=='tif':
os.renames(x,str(n)+'.tif')
n+=1
⑺ 如何从tiff文件中读取出像素的颜色值数据到数组
安装opencv 使用cvLoadImage函数读图 2、将文件图像数据部分读出,然后自己创建BMP文件头
⑻ Python PIL的斗争与未压缩的16位TIFF图像问题,怎么解决
关于Pillow与PIL
PIL(Python Imaging Library)Python强便图像处理库名气比较支持Python 2.7
PIL官网站:
PillowPIL派支今已经发展比PIL本身更具力图像处理库目前新版本3.0.0
PillowGithub主页:
Pillow文档(应版本v3.0.0):
Pillow文档文翻译(应版本v2.4.0):
Python 3.x 安装Pillow
给Python安装Pillow非简单使用pip或easy_install要行代码即
命令行使用PIP安装:
pip install Pillow
或命令行使用easy_install安装:
easy_install Pillow
安装完使用from PIL import Image引用使用库比:
from PIL import Image
im = Image.open("bride.jpg")
im.rotate(45).show()
简单便
⑼ python gdal.Open(file) Warning1:TIFFReadDirectory:Sum of Photometric type-related color channels
你好,除了这两行后面还应该还有信息的。
如果能打印出图片的信息的话,这个读入就没有问题。
下面是一些没有问题的提示例子。
What seems OK:
$ tiff2rgba 001.tif 001rgba.tiff
proces a picture that seems OK viewed with gwenview.
$ tiffdither rietkleur003.tif rikldit003.tif
TIFFReadDirectory: Warning, Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples..
tiffdither: Not a b&w image.
OK, it is a color image, decent message to me.
$ tiffdither gray1.tif gray1dit.tif
proces a heavily dithered image. Seems OK.
$ tiffgt rietkleur004.tif
displays the picture decently.
$ tiffinfo rietkleur004.tif
TIFFReadDirectory: Warning, Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples..
TIFF Directory at offset 0x1a51b08 (27597576)
Image Width: 2144 Image Length: 3218
Bits/Sample: 8
Compression Scheme: None
Photometric Interpretation: RGB color
Samples/Pixel: 4
Planar Configuration: single image plane
Seems OK.
$ tiffsplit rietkleur004.tif
TIFFReadDirectory: Warning, Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples..
There is nothing really to split, but it generates a decent xaaa.tif file, of the original picture. OK for me.
]$ tiffmedian rietkleur007.tif riklmed007.tif
TIFFReadDirectory: Warning, Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples..
proces an akward color picture with only a few week but quite different colors. I guess that's what I asked for.
⑽ 如何用python读取和写入TIFF文件2
能说的详细点嘛,有什么区别,是不是需要加载个外部工具,谁能提供一下?