Jump to content

PNG Read strangeness


Recommended Posts

Hi All,

 

I am getting some strange behaviour when using LV to read a PNG file.

 

For reasons I cannot explain I get coloured pixels where I do not expect them. The attachment shows what I expect versus what LV is giving me. I have tried playing around with the transparency threshold input as a last resort but this does not seem to have too much effect.

 

Any ideas? Any other tricks for reading a PNG file?

 

 

post-7375-0-86560800-1456938088.png

Edited by Neil Pate
Link to comment

I think I know this one but I could be wrong.  LabVIEW can't handle alpha layer information, so I suspect those pixels are something like 1% opacity which doesn't show up in a viewer as easily.

 

I've seen this where I had a pixel that was black but at a low opacity.  When you use the native LabVIEW read it just bumps that up to 100% and then there are black pixels when there wasn't before.  I remember seeing some code a while ago that would actually set a threshold and set the pixels to the background color if they were below this level.  I just tested this on some PNGs with alpha layers and I didn't quite get the output I expected so maybe this isn't your issue.

 

Still you might want to load up the PNG in an image control that does support alpha layers better.  Here is some code I did a while ago to demonstrate alpha layers, and native zooming using the picture box.

 

http://forums.ni.com/t5/LabVIEW/NET-picturebox-convert-to-LabView-image/m-p/3125944#M897890

 

Is it possible to post the PNG image by the way?

Link to comment

Chris, both images are the same size, the picture from the left is from paint .net, the one on the right are just the pixels represented by colourboxes.

 

hooovahh, I think you are right. I actually found code on my PC very similar to what you linked to, and I tried this and it works perfectly.

 

By the way, I also give credit and thanks to the author of the VI I found on my PC that I downloaded from lavag some time ago, it is called GDI Resize.vi

 

So my conclusion is that something strange is happening in the PNG Read VI. I think I have peeked into it before and it is just a LabVIEW.exe function call wrapped?

Link to comment

Yeah much of what I learned about .Net picture boxes, image resizing, z-layering, and transparencies in LabVIEW, stems from that one GDI Resize VI that I think started from here.

 

http://forums.ni.com/t5/LabVIEW/Net-image-resize-how-to-convert-to-format-labview-can-use/m-p/2199022#M704093

 

That spiked my curiosity and I've written several image library tools since then, which have been used in a few tools like my ribbon interface, that I never completed.

 

Say one other thing I didn't think about, is that there is a vi.lib tool for turning a PNG stream of data, into LabVIEW data.  I think it is just a DLL call in the background but it might load the PNG in a slightly different way.  It is found at this path.

 

<vi.lib>\wsapi\VIs\PNG Data to LV Image.vi"

Link to comment

Yeah much of what I learned about .Net picture boxes, image resizing, z-layering, and transparencies in LabVIEW, stems from that one GDI Resize VI that I think started from here.

 

http://forums.ni.com/t5/LabVIEW/Net-image-resize-how-to-convert-to-format-labview-can-use/m-p/2199022#M704093

 

That spiked my curiosity and I've written several image library tools since then, which have been used in a few tools like my ribbon interface, that I never completed.

 

Say one other thing I didn't think about, is that there is a vi.lib tool for turning a PNG stream of data, into LabVIEW data.  I think it is just a DLL call in the background but it might load the PNG in a slightly different way.  It is found at this path.

 

<vi.lib>\wsapi\VIs\PNG Data to LV Image.vi"

 

Ah yes, that is the same VI "GDI Resize" I am using now (Thanks Darin.K). Internally that VI does use the PNG Data to Lv Image.

 

That solution works perfectly, I get a pixel perfect representation of my PNG file. 

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.