Re: Overlay transparent PNG with JPG
- From: "Meier Anton" <sonyc@xxxxxx>
- Date: Mon, 22 Jun 2009 21:41:01 +0000 (UTC)
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
- References:
- Overlay transparent PNG with JPG
- From: Meier Anton
- Re: Overlay transparent PNG with JPG
- From: Oliver Woodford
- Overlay transparent PNG with JPG
- Prev by Date: Re: MathCAD customers base size?
- Next by Date: Need help with Besself
- Previous by thread: Re: Overlay transparent PNG with JPG
- Next by thread: Re: Plot3D and contours
- Index(es):
Relevant Pages
|