Re: Overlay transparent PNG with JPG




Thanks a lot.

Exactly what I was searching for. Works perfectly :)

For the interested reader:
The files Ijpg and Ipng were read with imread(...) and stored automatically in a 'uint8' matrix. The same is true for the alpha channel which goes from 0 to 255. Since 'uint8' can hold only the maximum value of 255 the typical way of normalisation is not working and it took me quite long to figure this out.

instead of: A = (Ijpg .* (Mmax - M) + Ipng .* M)./Mmax;
i needed to do: A = (Ijpg .*( (Mmax - M)./Mmax + Ipng .*(M./Mmax);

This avoids the calculation of values greater then 255 which can't be used. This problem does not happen if you work with doubles, but takes a lot more memory.

All the best




"Oliver Woodford" <o.j.woodford.98@xxxxxxxxxx> wrote in message <h1if0h$pla$1@xxxxxxxxxxxxxxxxxx>...
"Meier Anton" <sonyc@xxxxxx> wrote in message <h1fhjp$3bm$1@xxxxxxxxxxxxxxxxxx>...
Hi all,
I have thousands of background images (all 256x256 pixels) in JPG format and an equal number of corresponding foreground images in PNG format, where the background is transparent (there are only completely transparent or non-transparent pixels in the PNG).

My job is now to put each JPG image "behind" each corresponding PNG image so that I can see on all transparent places the background (=JPG). Since those images are tiles of a really huge "map-image" I need to stitch/merge them afterwards together in a grid/matrix according to their file name and save the huge image (I have solved that task already partly).

How can I do all this memory and time efficiently? Do I need to loop through all the pixels? Is there a similar way to do it like: imread(..., 'background', JPGIMAGE) or does imread really work only with one specific color?

My script right now looks basically something like this:

%--> how can I preallocate memory for the known number of images (100x100 image tiles) for the cell array C?
for i=1:...
for j=1:..
C{i,j} = imread(JPG...);
end
end
M=cell2mat(C);
imwrite(...)


I found only partly usefull hints in the forum over the last week. Any help or improvement would be great.

All the best
Meier Anton





I searched now for quite a long time

format which need to be used as background of thousands of other images of the same size in PNG format with background

Hi Meier

This works even if you have a non-integer alpha values. For each jpg-png pair do the following:

M = alpha(:,:,[1 1 1]); % Make the png's alphamatte 3 channel
A = Ijpg .* (1 - M) + Ipng .* M; % This generates the composited image

Then stitch all the A's together as you were doing before.

HTH,
Oliver
.



Relevant Pages

  • Re: Overlay transparent PNG with JPG
    ... How can I do all this memory and time efficiently? ... Do I need to loop through all the pixels? ... %--> how can I preallocate memory for the known number of images for the cell array C? ... format which need to be used as background of thousands of other images of the same size in PNG format with background ...
    (comp.soft-sys.matlab)
  • Overlay transparent PNG with JPG
    ... How can I do all this memory and time efficiently? ... Do I need to loop through all the pixels? ... %--> how can I preallocate memory for the known number of images for the cell array C? ... format which need to be used as background of thousands of other images of the same size in PNG format with background ...
    (comp.soft-sys.matlab)
  • Re: HUGE problem with A7V8X-LA and data corruption issues! (Hewlett Packard System)
    ... I create images to a seperate drive in the machine. ... Large file transfers across the network no matter what ... Ran memory tests, removed memory, used different ... for awhile than crapped again(I've tried various NICS and the ones I've ...
    (alt.comp.periphs.mainboard.asus)
  • Re: Rapid gfx display Qs
    ... using a completely random set of images that I resized to 1280x720. ... I don't have the display memory now to support that (I don't ... target system will use a full-screen borderless form, ... should be more than fast enough for loading JPGs. ...
    (microsoft.public.vb.general.discussion)
  • Re: How do I put a sprite into a dynamic area ?
    ... My worries over 'protecting' my dynamic area stem from all the stuff ... They're basically for use if you wanted to use the Dynamic Area to be resizeable and behave like a cache in a similar manner to the Font Manager. ... What the Font Manager does is to cache a lot of its images into the font cache. ... When you resize it, these calls are used to allow the font manager to choose how to rearrange its memory before and/or after the memory has been reduced in size, to make sure that it keeps the most useful bits. ...
    (comp.sys.acorn.programmer)