LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to retrieve mask info from picture? (also Doom)

I recently came across this very cool Doom WAD file viewer in the code exchange. It uses IMAQ functions for all its image handling, so requires NI Vision to be installed. I wanted a more pure LabVIEW version, so set about replacing all the IMAQ functions with LabVIEW's picture functions.

 

Pictures are created using Draw Unflattened Pixmap.vi in 8-bit mode from a combination of image data, mask data, and a 256-color palette from the WAD file. The replacement code works and, after adding a little programmatically generated fire, the mask provides a nice 'demon floating over a pit of flames' aesthetic:

labwad.gif

 

The viewer also allows for saving an image as a PNG. I wanted to use the picture mask as the alpha channel for the PNG, and found Darin.K's Mask to PNG Alpha VIs. These work with pixmaps, so the picture (with mask) is converted using Picture to Pixmap.vi. The problem is this VI doesn't extract the mask info from the picture, and a look inside that VI shows a DLL call (PictToPix) doing the conversion, and an empty array constant wired to the pixmap's mask element. So the mask info is lost at this point.

 

If during the pixmap conversion the background is set to a unique color not in the original picture palette, a new mask can be created from the pixmap based on that color using Create Mask.vi. This works and is the method currently implemented, but it feels a bit hacky.

Save Picture To PNG.png

 

Does a VI or DLL function exist for extracting the mask information directly from a picture?

Message 1 of 12
(3,615 Views)

Of course after posting this I found a similar issue, and the suggestion is to use the same (re)create mask method. If there are alternate methods others have used to retrieve the mask I'd be interested to hear them.

0 Kudos
Message 2 of 12
(3,606 Views)

@Dataflow_G wrote:

Of course after posting this I found a similar issue, and the suggestion is to use the same (re)create mask method. If there are alternate methods others have used to retrieve the mask I'd be interested to hear them.


I lost track. Do you want to get the binary mask of the pixmap, or the alpha channel of the png?

0 Kudos
Message 3 of 12
(3,562 Views)

Oof, must resist the urge to start creating my own DOOM Level editor....

 

I used the old tools so much in the past. Loved correcting community maps whose segments were terribly inefficiently mapped and lead to the node builder not being able to do its work properly.

 

What was the name of the doom editor I used..... can't remember. I think it was DEU.

edit: Nope, it was DETH, an editor written on the basis of DEU 5.2.1 IIRC.

Message 4 of 12
(3,543 Views)

wiebe@CARYA wrote:

I lost track. Do you want to get the binary mask of the pixmap, or the alpha channel of the png?


I'm trying to get the binary mask from the picture, to be added to the pixmap (cluster). The mask in the picture is lost during conversion to pixmap, but can be recreated using the method in the snippet. I was hoping to find a way to retain the mask from the picture during the pixmap conversion, or extract it from the picture somehow.

 

The problem with the current method is if the background color used isn't unique, some of the image pixels may get masked. The WAD format allows custom color palettes (PLAYPAL), so that cyan background color may not be unique for different WADs. I guess I could add a function to generate a background color not in the palette, but was looking for a more general solution.

 

@Intaris wrote:

Oof, must resist the urge to start creating my own DOOM Level editor....

 

I used the old tools so much in the past. Loved correcting community maps whose segments were terribly inefficiently mapped and lead to the node builder not being able to do its work properly.

 

What was the name of the doom editor I used..... can't remember. I think it was DEU.

edit: Nope, it was DETH, an editor written on the basis of DEU 5.2.1 IIRC.


A LabVIEW based level editor would be awesome! I created some (terrible) PWADs with a demo version of DeePsea (the demo limited the total linedefs IIRC), but DEU rings a bell. I also remember using MIDI2MUS to replace the level music with a MIDI version of Master of Puppets 🤘

Message 5 of 12
(3,519 Views)

@Dataflow_G wrote:

wiebe@CARYA wrote:

I lost track. Do you want to get the binary mask of the pixmap, or the alpha channel of the png?


I'm trying to get the binary mask from the picture, to be added to the pixmap (cluster). The mask in the picture is lost during conversion to pixmap, but can be recreated using the method in the snippet. I was hoping to find a way to retain the mask from the picture during the pixmap conversion, or extract it from the picture somehow.

 

The problem with the current method is if the background color used isn't unique, some of the image pixels may get masked. The WAD format allows custom color palettes (PLAYPAL), so that cyan background color may not be unique for different WADs. I guess I could add a function to generate a background color not in the palette, but was looking for a more general solution.

The current image might not have a binary mask. PNGs can have an alpha channel. That means the image is 32 bit. LabVIEW 'supports' 24 bits, not really 32 bits. But you still get the alpha channel when you read the png, IIRC. The pixmap from Read PNG is 32 bit.

 

If you unload an image, I could have a look.

 

The problem lays in Unflatten Pixmap. If you open that VI, the 32 bit case actually says "remove alpha channel", to convert it to 24 bit. You need to make a copy that doesn't remove it, but actually uses it.

 

A quick fix is to unbundle the image, and decimate the image data (I hope the first channel is indeed the alpha channel):

Alpha channel.PNG

However, that doesn't set a mask. You'll need to bit pack the thresholded alpha value (>0). Modifying Create Mask would be the way to go.

Message 6 of 12
(3,505 Views)

wiebe@CARYA wrote:

However, that doesn't set a mask. You'll need to bit pack the thresholded alpha value (>0). Modifying Create Mask would be the way to go.


Bit-array To Byte-array.vi pretty much does this:

Alpha channel to mask.png

Message 7 of 12
(3,501 Views)

wiebe@CARYA wrote:

I hope the first channel is indeed the alpha channel

 


I suppose that's right:

alpha-byte.PNG

0 Kudos
Message 8 of 12
(3,497 Views)

well, that was tricky:

 

32-bit_png.png

 

Message 9 of 12
(3,458 Views)

slighty more polished version attached.

 

so the point is to replace:

1.PNG

 

with this:

0.PNG

Message 10 of 12
(3,433 Views)