Welcome! Log In Create A New Profile

Advanced

Overlay multiple images with transparent background

Posted by reegel 
Overlay multiple images with transparent background
October 30, 2020 07:13AM
Dear all,

Is it possible to overlay multiple images with transparent background (e.g. png or tif format pictures) in NIMH MonkeyLogic?

As we can assign the figure in the upper layer to any position on the surface of the lower layer figure?
Re: Overlay multiple images with transparent background
October 30, 2020 09:59AM
Yes, you can use PNG or ARGB matrices.
https://monkeylogic.nimh.nih.gov/docs_MonkeyLogicGraphicsLibrary.html

Basically an object created first is shown up above the other objects, but you can change their z-orders as well.
https://monkeylogic.nimh.nih.gov/board/read.php?2,12,12#msg-12
Re: Overlay multiple images with transparent background
October 31, 2020 01:41AM
Thanks!
Re: Overlay multiple images with transparent background
November 11, 2020 09:18AM
Hi Jaewon,

Here's a new problem.

I tried to display a series of transparent images located at different places on a background continuously.
(transparent images were called by the mglimread and mglsetorigin)

It turns out that the background could always showed up, but the display of transparent images were very unstable: sometimes it shows up and sometimes it doesn't.

Below are the examples codes:

%%%%%
cycle_num=5;
for cycle=1:cycle_num
toggleobject(scene_background,'status','on');
%idle(100)
item=mglimread(['C:...\item',num2str(cycle),'.png']);
id=mgladdbitmap(item);
mglsetorigin(id,[locations(1,cycle) locations(2,cycle)])
idle(500)

mgldestroygraphic(id)
toggleobject(scene_background,'status','off');
idle(100)
end
%%%%%

I'm running NIMH 2.0.218 (Jul 21, 2020) on matlab 2017b.

Do you have any idea why this happens and how to fix it?


Thanks!
Re: Overlay multiple images with transparent background
November 11, 2020 03:53PM
See my first reply again. I said the object created first is displayed above the other objects. In your script, the background is the first created and therefore covers all the other images.

Update your NIMH ML to the latest version and modify the mglsetorigin line as below.
From:  mglsetorigin(id,[locations(1,cycle) locations(2,cycle)]) 
To:    mglsetproperty(id,'origin',[locations(1,cycle) locations(2,cycle)],'zorder',1);
Re: Overlay multiple images with transparent background
November 11, 2020 09:31PM
Thanks Jaewon!

One more question, now the images called by mglimread showed up on the control but not subject screen, while the images called by the toggleobject showed on both screens.

How can i make all images showed up on both screens?
Re: Overlay multiple images with transparent background
November 12, 2020 03:29PM
Create PIC TaskObjects from the png images and turn them on/off with toggleobject. MGL is a graphics library I wrote to build NIMH ML on. It is a sort of a low level structure and not supposed to be accessed directly in the timing script.

The National Institute of Mental Health (NIMH) is part of the National Institutes of Health (NIH), a component of the U.S. Department of Health and Human Services.