LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to get alpha images on picture box??

Solved!
Go to solution

Hi,

 

I am currently working on overlaying pictures(PNG format) and texts on the 2DPicture box using Picture Functions in Lv, on reading alpha images using Read PNG file function i could n't reproduce the exact original image. original image has an shadowing effect(you can verify by openning in Microsoft Picture manager) which couldn't be reproduced by LV. if any one has the suggestions pls help me...  

 

With thanks,

Suresh S

0 Kudos
Message 1 of 16
(10,734 Views)
i am not really sure about it, but perhaps, the shadowing effect is done by setting the opacity in the png image as png supports alpha channels. Don't think lv supports these channels? try converting your png to a bmp or remove alpha channel by adding a white background in for example gimp

THINK G!! 😉
------------------------------------------------------------------------------------------------
Using LabView 2010 and 2011 on Mac and Win
Programming in Microsoft Visual C++ (Win), XCode (Mac)
0 Kudos
Message 2 of 16
(10,700 Views)

OK, one of my pet peeves has been LV's handling of the alpha channel in PNG files.  The built-in drawing functions for the picture control only support single bit transparency, ie. a given pixel can be opaque or transparent.  When handling the drawing of PNG (and other) files, they decided to toss the alpha channel for a single-bit mask.  You could use the threshold control and read the file 255 times to back out the alpha channel based on changes to the mask.  What gets truly annoying is that the VI to read the PNG file is password protected and there is no way to retrieve the information that they are tossing away.  They do most of the heavy lifting to read the file and don't let you piggyback.

 

I have dusted off and tried to error check some VIs I had written a while back to handle 32-bit PNG (RGBa) files correctly.  Check it out, the new Read PNG VI will delegate to the built-in VI for most formats, but will retrieve the alpha channel from 32-bit PNG files.  I use a slightly different image data format since the 1D arrays can be annoying, and provide a new VI to draw the PNG onto a picture control.

 

Interlacing is a pain in the butt so I didn't deal with that.  And there are some .NET calls so I hope you are on Windows, if not, let me know and I can try to help you out.  Anyway, enjoy (at your own risk since this code was written in my spare time).

 

TestPNGAlpha.PNG

0 Kudos
Message 3 of 16
(10,692 Views)

Hi Darin.K,

 

Thank you for your valuable response, VI what u developed is good, but i have one concern here that image what shown in "With Alpha" pictre box couldn't maintain its BG as Transparent, is there any other way to make it transparent.

 

I am curious abt making it exact reproduction of image is since i am going to overlay many images(as i given in sample) and texts into one picture for VISION Analysis, the image can overlay in another BG image for that the transparency of the image plays a major role...so pls suggest me what changes i should make to get that transparency

 

I thank once again for your response

 

With Regards,

Suresh S 

0 Kudos
Message 4 of 16
(10,669 Views)

You can set the background color of the picturebox to transparent, right click on the picture box, select the brush tool and hit 'space' then select the 'T' in the upper right hand corner.

 

With the same method you can remove the border.

 

Ton

 

Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 5 of 16
(10,650 Views)
Solution
Accepted by topic author Ssuresh

Without getting too fancy, this modified version shows one way to do it.  I generate a mask from the original picture to find the would-be transparent regions.  Then I have to threshold the alpha matrix to find the opaque region of the PNG image.  For the image blending I specify the background color to be the pane color so the blending looks reasonable.  If there are underlying objects the blending may get a little weird, but the alternatives are venturing way into hack territory (even further than I am already).

 

TestPNGAlphaMod.png

Message 6 of 16
(10,648 Views)

TCPlomp wrote:

You can set the background color of the picturebox to transparent, right click on the picture box, select the brush tool and hit 'space' then select the 'T' in the upper right hand corner.

 

With the same method you can remove the border.

 

Ton

 


 
The OP's concern was that after changing the background to transparent, the image held onto the white area between the red and blue boxes despite the fact that it was the background of the picture control.  Transparency is hard to deal with in this case since it is very hard to find the underlying pixel on the FP (why I don't often set picture backgrounds to transparent).  I have to blend with some color, so the pane color seems like a reasonable guess in this case.   Someday I will refine this a bit more if I am in the mood.

 

0 Kudos
Message 7 of 16
(10,640 Views)

Hi,

 

Thanks a lot...i hope it will help me a lot...Thanks for your timely help.. 

0 Kudos
Message 8 of 16
(10,625 Views)

Darin, I thought I'd ask a fellow PNG bit basher this question...

 

   With the single bit alpha channel ("mask") - did you happen to notice an extra 14 bits per horizontal line when you go from the 1D mask to a 2D pixelated display?

 

I'm not seeing it in a 2D hex display of the mask, but using the Reshape Array VI always requires me to pad each row by 14 bits, or I come up misregistered.

 

I noticed it if you do this: open a Full color PNG using the Read PNG vi. Get the 24 bit 2D array size(s), multiply to get number of pixels. 

Next, get the array size of the Mask. I thought that should be the same, but there are 14 extra mask bits per row.

 

It's really apparent if you view the mask bits in 2D in an Intensity Plot.

Have you seen this too?

 

Jason

 

 

using LV 2009, on Mac 10.7

 

 

0 Kudos
Message 9 of 16
(9,486 Views)

The mask is padded to the nearest multiple of 16 bits.  If you try a 32x32 image you get what you expect (4*32=128 mask elements).  If it were 33x32 you would get 6*32=192 elements in the mask array.  You need to clip to the image size.

0 Kudos
Message 10 of 16
(9,481 Views)