English 中文(简体)
1. 处理带有PIL的拖拉图像
原标题:Working with truncated images with PIL

我正试图获得Salph 2.7 PIL图书馆,以便与JPEG图像合作,这些图像只能作为来自HDD形象的溪流提供,而且不完整。

我提出了以下选择:

ImageFile.LOAD_TRUNCATED_IMAGES = True

而且,只要有数据,就装上上游(或者说得更好:只要我100%确信这一数据仍是一个形象,而不是其他一些档案类型)。 我测试了不同的东西,只要我能够知道(对于JPEGs来说),PIL只有在发现<0xFFDA<<>> /code>(斯堪的Marker)。 这是我如何装载数据的一个简短例子:

from PIL import Image
from StringIO import StringIO

ImageFile.LOAD_TRUNCATED_IMAGES = True

with open("/path/to/image.raw",  rb ) as fp:
    fp.seek("""jump to position in image where JPEG starts""")
    data = fp.read("""number of bytes I know that those belong to that jpeg""")
    img = Image.open(StringIO(data)) # This would throw exception if the data does 
                                     # not contain the 0xffda marker
    pixel = img.load()               # Would throw exception if LOAD_TRUNCATED_IMAGES = false

    height,width = img.size
    for i in range(height):
        for j in range(width):
            print pixel[i,j]

在最后一行,我(或希望)至少看到将显示的六氯苯数据。 但是,每张钢板都填好<代码>(0,0),。

www.un.org/Depts/DGACM/index_spanish.htm 问题: 我在这里试图做的是怎么办?

大约几周前,我用一个形象档案尝试了同样的问题,我只用一个编辑从中删除数据。 它为现有的六氯数据做了工作。 一旦达到我截断的一张颜料,该方案就提出一个例外(我今天将再次试图确保我不会忘记错误)。

If somebody is wondering why I am doing this: I need to make sure that the image/picture inside that hdd image is in consecutive blocks/clusters and is not fragmented. To make sure of this I wanted to use pixel matching.

EDIT: I have tried it again and this is what I have seen.

  • 我打开了全球疫苗和免疫机能保值的缩略图像,在上半部分向我展示了几条六线,但消费物价指数至少不能给我以这些餐具的欧洲法郎价值。 它总是返回(0,0)。

  • 我将图像稍加大,这样,图像的4/5下级面目看不见,但这足以让消费物价指数向我展示可资利用的欧洲-联合国达尔富尔混合行动价值观。 其它一切是(0,0,0)。

我仍然无法确定临时自治机构是否能够向我表明欧洲-欧洲合作组织的价值,即使只有看齐数据。

问题回答

我将尝试采用像TGA这样的令人沮丧的形式。 JPG是一种压缩格式,对于从不完整的形象中提取纤维可能没有任何意义。 JPEG实际上为描述形象的方程式而不是粉碎价值而储存参数。 当你问一个PEG,看一个Pixel数值时,它会评估当时的情况,并回报结果。

我对<代码>也有同样的问题。 Pillow=9.2.0

让我们降级为<代码>Pillow=8.3.2,并发挥作用。

I don t really know about streaming, but I think that you simply cannot access rgb value the way you do. Try:

rgb_im = img.convert( RGB )
r, g, b = rgb_im.getpixel((i, j))




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签