当前位置:首页 » 编程语言 » python读取tif

python读取tif

发布时间: 2022-06-27 00:32:22

python对卫星地图tif文件转换

pathjoin那里错了。应该是:

图一中的错误表明,imread返回值img是None
imread的第一个参数,即使传入的是一个无效的文件名,它也不会抛出错误,而是返回一个None.

第一个参数的赋值是this.dir = os.path.join(dir + ...)
这种写法并不好,一般来说,应该是写成
this.dir = os.path.join(dir , filename)
并且,你应当在这之后检查一下这个文件是否存在:
if not os.path.isfile(this.dir):
....raise FileNotFoundError(this.dir)
然后才可以交给imread()去读取

② python 读取文件

各有各的特点,open是一般方法,可以打开一般的文档。
pandas模块可以处理大数据,数据分析,数据挖掘等等的用法,其里面的read_csv()方法可以打开csv格式的数据库文件,并对数据进行分块读取等等的妙用,这是open不能实现的。

一般文本数据可以用open,数据库等大体积的文件用read_csv

③ python如何读取图像文件

import os
folder_name = '文件夹名字'
folders = os.listdir(folder_name)
for folder in folders:
files = os.listdir(os.path.join(folder_name, folder))

for f in files:

#这里对图片做操作

④ python如何读取文件的内容

# _*_ coding: utf-8 _*_

import pandas as pd

# 获取文件的内容

def get_contends(path):

with open(path) as file_object:

contends = file_object.read()

return contends

# 将一行内容变成数组

def get_contends_arr(contends):

contends_arr_new = []

contends_arr = str(contends).split(']')

for i in range(len(contends_arr)):

if (contends_arr[i].__contains__('[')):

index = contends_arr[i].rfind('[')

temp_str = contends_arr[i][index + 1:]

if temp_str.__contains__('"'):

contends_arr_new.append(temp_str.replace('"', ''))

# print(index)

# print(contends_arr[i])

return contends_arr_new

if __name__ == '__main__':

path = 'event.txt'

contends = get_contends(path)

contends_arr = get_contends_arr(contends)

contents = []

for content in contends_arr:

contents.append(content.split(','))

df = pd.DataFrame(contents, columns=['shelf_code', 'robotid', 'event', 'time'])

(4)python读取tif扩展阅读:

python控制语句

1、if语句,当条件成立时运行语句块。经常与else, elif(相当于else if) 配合使用。

2、for语句,遍历列表、字符串、字典、集合等迭代器,依次处理迭代器中的每个元素。

3、while语句,当条件为真时,循环运行语句块。

4、try语句,与except,finally配合使用处理在程序运行中出现的异常情况。

5、class语句,用于定义类型。

6、def语句,用于定义函数和类型的方法。

⑤ 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读取一个图像

  • 打开winPython工具包

  • 输入以下代码,如图所示。

    from skimage import io

    if __name__ == '__main__':

    img_name="D:\WinPython-64bit-3.5.3.0Qt5\notebooks\hashiqi.jpg"

    print("我的图片!")

    img=io.imread(img_name,as_grey=False)

    io.imshow(img)

    其中变量img_name是为了指定自己图片所存的路径。

  • 单击保存按钮,

    会跳出一个设置文件名的界面,填入要保存的名字即可。

  • 单击运行按钮,一般要单击两次才行,运行代码。

  • 单击后,就可以查看的我们显示的图片了。

热点内容
安卓手机为什么最新微信安装不了 发布:2025-02-05 02:31:03 浏览:106
安卓手机什么时候开售 发布:2025-02-05 02:14:15 浏览:660
编程车模型 发布:2025-02-05 02:09:55 浏览:680
雅马哈天剑哪个配置好 发布:2025-02-05 02:00:35 浏览:170
我的世界国际服推荐118服务器 发布:2025-02-05 01:50:48 浏览:46
普通电脑做服务器怎么操作 发布:2025-02-05 01:46:22 浏览:628
原神为什么同服务器加不起好友 发布:2025-02-05 01:41:03 浏览:337
android连接打印机 发布:2025-02-05 01:40:09 浏览:959
外国电脑代理服务器地址端口 发布:2025-02-05 01:38:30 浏览:387
德意龙鼠标宏怎么配置 发布:2025-02-05 01:34:13 浏览:318