merge two png pic

C

cocobear

This two png file has their own palette
False

I can use this code to merge two png pic together:

Map = Image.new("RGB", (x,y))
Map.paste(im, box)
Map.paste(im1,box)

Map = Map.convert("L", optimize=True, palette=Image.ADAPTIVE)

But if the two png pic is too big , or if I have to merge more pic
together, I will get MemoryError:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1710, in
new
return Image()._new(core.fill(mode, size, color))
MemoryError

How can I directly merge two pic to a ‘P' mode png with palette.
 
C

cocobear

Thistwopngfile has their own palette


False

I can use this code tomergetwopngpictogether:

Map = Image.new("RGB", (x,y))
Map.paste(im, box)
Map.paste(im1,box)

Map = Map.convert("L", optimize=True, palette=Image.ADAPTIVE)

But if thetwopngpicis too big , or if I have tomergemorepic
together, I will get MemoryError:


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1710, in
new
    return Image()._new(core.fill(mode, size, color))
MemoryError

How can I directlymergetwopicto a ‘P' modepngwith palette.


Nobody replied.
 
P

Peter Otten

As a workaround you could split the image into tiles that fit into your
machine's RAM. Or you could try to do the rendering on a 64-bit system.
You'll need at least
4.8109130859375

5 gigabytes for the target image plus memory for the biggest source image.
Alternatively there are probably tools that can keep parts of the image on
disk (imagemagick, maybe? you'll have to check yourself or ask in a
specialized forum). As a last resort you should be able to write such a tool
yourself. I don't know how hard it would be to generate the PNG, but the RGB
pasting should be trivial.
Nobody replied.

What do you want to do with such a big image? You will run into the same
limitation when you are trying to display it.

Peter
 
C

cocobear

As a workaround you could split the image into tiles that fit into your
machine's RAM. Or you could try to do the rendering on a 64-bit system.
You'll need at least


4.8109130859375

5 gigabytes for the target image plus memory for the biggest source image..
Alternatively there are probably tools that can keep parts of the image on
disk (imagemagick, maybe? you'll have to check yourself or ask in a
specialized forum). As a last resort you should be able to write such a tool
yourself. I don't know how hard it would be to generate the PNG, but the RGB
pasting should be trivial.

Thanks for you reply.

Map = Image.new("RGB", ((x2-x1+1)*256, (y2-y1+1)*256))
for x in range(x1,x2+1):
for y in range(y1,y2+1):
#print x,y
filename = "v=cn1.11&hl=zh-CN&x=%d&y=%d&z=%d&s=Galile" %
(x,y,z)
#
box = ((x-x1)*256, (y-y1)*256, (x-x1)*256+256, (y-y1)
*256+256)
#print box
im = Image.open(filename+".png")
Map.paste(im, box)

temp = "temp_map.png"
Map.save(temp)
del Map
print "converting"
Map = Image.open(temp)
Map = Map.convert("P", palette=Image.ADAPTIVE)

Now I use code above, the problem is when I create a RGB image, I need
four times spaces then a 'P' mode image.

Can I directly create a 'P' mode image, and paste those images on?
(NOTICE: this small image has different palette)

What do you want to do with such a big image? You will run into the same
limitation when you are trying to display it.

I want to download a map from google map with high precision
 
N

News123

Hi,
I want to download a map from google map with high precision


For me it sounds strange to handle such big files.

Is the map you download from Google really that big?
Mostly Google maps uses normally tiles of sizes 256x256 pixel, wich you
have to compose to get the big image.

If your problem is to combine tiles with different palettes, then you
should pobably look at a way to 'unify' the palette of all tiles befor
combining them.

Being no expert of PIL I don't know whether this is easily possible though?


bye


N
 
C

cocobear

Hi,







For me it sounds strange to handle such big files.

Is the map you download from Google really that big?
Mostly Google maps uses normally tiles of sizes 256x256 pixel, wich you
have to compose to get the  big image.

The map I downloaded from Google is small(256x256). These small maps
will compose a big image.


If your problem is to combine tiles with different palettes, then you
should pobably look at a way to  'unify' the palette of all tiles befor
combining them.

I think it is impossible to 'unify' all this tiles.
 
N

News123

You didn't really tell us why you need one big file, which contains more
pixel, than you can probably store in RAM

Is it for printing?
Not knwoing your goal makes it difficult to suggest solutions.


Can't you use other image formats like raw RGB or
What other image formats are supported?
tiff? Raw? PPM ( http://en.wikipedia.org/wiki/Portable_pixmap )?

concatenating raw/ppm files with the same width would be really trivial.

so you could use python to create horizontal raw/ppm stripes.

then you could concatenate them without having to have the whole image
in RAM.


Perhaps there's even converters from ppm to png, that don't need the
whole image in RAM.
 
C

cocobear

You didn't really tell us why you need one big file, which contains more
pixel, than you can probably store in RAM

In fact I do not need such a big image.
I just want to know the solution.

Is it for printing?
Not knwoing your goal makes it difficult to suggest solutions.

Can't you use other image formats like raw RGB or
What other image formats are supported?
tiff? Raw? PPM (http://en.wikipedia.org/wiki/Portable_pixmap)?

I want to view image use Windows Pic View.

I don't familiar with PPM, photoshop don't support PPM, does PIL
support this format?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top