467,923 Members | 1,813 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,923 developers. It's quick & easy.

read part of jpeg file by pure python

Hi, everyone,

I am wondering whether it's possible to read part (e.g. 1000*1000) of
a huge jpeg file (e.g. 30000*30000) and save it to another jpeg file
by pure python. I failed to read the whole file and split it, because
it would cost 2GB memory.

Can anyone help me? Any comments would be appreciated.

Thanks.

Robert

Sep 13 '07 #1
  • viewed: 2748
Share:
4 Replies
Pacino a ¨¦crit :
Hi, everyone,

I am wondering whether it's possible to read part (e.g. 1000*1000) of
a huge jpeg file (e.g. 30000*30000) and save it to another jpeg file
by pure python. I failed to read the whole file and split it, because
it would cost 2GB memory.

Can anyone help me? Any comments would be appreciated.

Thanks.

Robert
Just reading parts of the *file* is easy (see tell() seek() and read()
methods on files).
But to extract a part of the *picture*, you must uncompress the picture
in memory, grab the sub-picture, and save it back - generally with
compression. I can't see how you can bypass the uncompress/compress
phases and the corresponding memory use.

A+

Laurent.
Sep 13 '07 #2
On 9 13 , 4 43 , Laurent Pointal <laurent.poin...@limsi.frwrote:
Pacino a écrit :
Hi, everyone,
I am wondering whether it's possible to read part (e.g. 1000*1000) of
a huge jpeg file (e.g. 30000*30000) and save it to another jpeg file
by pure python. I failed to read the whole file and split it, because
it would cost 2GB memory.
Can anyone help me? Any comments would be appreciated.
Thanks.
Robert

Just reading parts of the *file* is easy (see tell() seek() and read()
methods on files).
But to extract a part of the *picture*, you must uncompress the picture
in memory, grab the sub-picture, and save it back - generally with
compression. I can't see how you can bypass the uncompress/compress
phases and the corresponding memory use.

A+

Laurent.
The most difficult part is the uncompress part. I don't want the whole
picture to be uncompressed in the memory, because it will consume a
lot of memory (2GB, as I mentioned). My goal is to uncompress part of
the picture into the memory.

I just read some article on this subject (http://mail.python.org/
pipermail/image-sig/1999-April/000713.html) , but haven't test it out
yet.

Robert

Sep 13 '07 #3
On 13 Wrz, 10:48, Pacino <xiaoyish...@gmail.comwrote:
On 9 13 , 4 43 , Laurent Pointal <laurent.poin...@limsi.frwrote:
Pacino a écrit :
Hi, everyone,
I am wondering whether it's possible to read part (e.g. 1000*1000) of
a huge jpeg file (e.g. 30000*30000) and save it to another jpeg file
by pure python. I failed to read the whole file and split it, because
it would cost 2GB memory.
Can anyone help me? Any comments would be appreciated.

Just reading parts of the *file* is easy (see tell() seek() and read()
methods on files).
But to extract a part of the *picture*, you must uncompress the picture
in memory, grab the sub-picture, and save it back - generally with
compression. I can't see how you can bypass the uncompress/compress
phases and the corresponding memory use.


The most difficult part is the uncompress part. I don't want the whole
picture to be uncompressed in the memory, because it will consume a
lot of memory (2GB, as I mentioned). My goal is to uncompress part of
the picture into the memory.

I just read some article on this subject (http://mail.python.org/
pipermail/image-sig/1999-April/000713.html) , but haven't test it out
yet.
I have no idea what it does. Anyway - jpeg:
1. RGB -HLV
2. divide data into 8x8 - blocks of data.
3. blocks are treated with discrete cosine transform.
4. Result is filtered to remove "fast changes".
5. Then result is compressed with Huffman alg.

So to get part of image - you can take smaller image before step 4.
As far as I understand code presented at:
http://mail.python.org/pipermail/ima...il/000713.html
- full image will be loaded, and cutted.

--
Regards,
Micha³ Zaborowski (TeXXaS)

Sep 13 '07 #4
On 9 13 , 7 44 , michal.zaborow...@gmail.com wrote:
On 13 Wrz, 10:48, Pacino <xiaoyish...@gmail.comwrote:
On 9 13 , 4 43 , Laurent Pointal <laurent.poin...@limsi.frwrote:
Pacino a écrit :
Hi, everyone,
I am wondering whether it's possible to read part (e.g. 1000*1000) of
a huge jpeg file (e.g. 30000*30000) and save it to another jpeg file
by pure python. I failed to read the whole file and split it, because
it would cost 2GB memory.
Can anyone help me? Any comments would be appreciated.
Just reading parts of the *file* is easy (see tell() seek() and read()
methods on files).
But to extract a part of the *picture*, you must uncompress the picture
in memory, grab the sub-picture, and save it back - generally with
compression. I can't see how you can bypass the uncompress/compress
phases and the corresponding memory use.
The most difficult part is the uncompress part. I don't want the whole
picture to be uncompressed in the memory, because it will consume a
lot of memory (2GB, as I mentioned). My goal is to uncompress part of
the picture into the memory.
I just read some article on this subject (http://mail.python.org/
pipermail/image-sig/1999-April/000713.html) , but haven't test it out
yet.

I have no idea what it does. Anyway - jpeg:
1. RGB -HLV
2. divide data into 8x8 - blocks of data.
3. blocks are treated with discrete cosine transform.
4. Result is filtered to remove "fast changes".
5. Then result is compressed with Huffman alg.

So to get part of image - you can take smaller image before step 4.
As far as I understand code presented at:http://mail.python.org/pipermail/ima...il/000713.html
- full image will be loaded, and cutted.

--
Regards,
Micha³ Zaborowski (TeXXaS)- -

- -
Thanks. Seems no ways to achieve the requirements.

Sep 14 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Brad Tilley | last post: by
3 posts views Thread by Peter | last post: by
reply views Thread by Jack Wu | last post: by
3 posts views Thread by Podi | last post: by
5 posts views Thread by Aljosa Mohorovic | last post: by
4 posts views Thread by rowan | last post: by
2 posts views Thread by devnew | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.