Jump to content

U16 Grayscale onto U32 RGB


Recommended Posts

I have a U32 RGB image streaming in from a webcam, and I want to overlay/merge (whatever is faster) a U16 grayscale image over the top of it. The grayscale image has 0-value pixels that I do not want to include in this "merge". Any non-zero intensity value should be included.

What would the proper IMAQ tools be to merge these together? I've tried to cast the U16 to a U32 RGB which works (loses some intensity resolution due to bringing 16bit down to 8bit color, but I can live with it). Where I'm stuck is I can't seem to find anything that would efficiently overlay/merge *just* the non-zero pixels of this casted image onto my background U32 RGB image. I know this is something silly I'm not thinking of...

I am capturing both images at 30fps and need to perform this operation in realtime. Can someone point me in the right direction of the NI-Vision palletes...or an example perhaps that will push my "ah ha!" button? :)

Link to comment

Thanks for the prompt replies!

Neville, unless I'm mistaken, adding a 32bit-casted grayscale image to the color RGB will give me darker/lighter colors in the areas that I want to totally replace (with the actual grayscale intensity value). I wish it were that easy :)

JD, I took your and Neville's advice and tried to apply a mask to the color RGB image using the grayscale image casted down to an U8 grayscale image as the mask. It didn't do what I expected, instead the grayscale RGB image is replacing all of the pixels in the color RGB image. Can you take a look and see where I'm going wrong here?

Download File:post-3266-1236298441.vi (LV 8.6)

post-3266-1236298404.png?width=400

Link to comment

It looks to me like you have your Source and Destination images backwards in the IMAQ Mask function. If you do wire a destination, it will be overwritten by the operation. Since you never put any data into the source, all you see is a copy of the mask in the output. For most of the IMAQ functions, you don't need to wire the Image Dst at all, and you just modify the source image.

Link to comment

QUOTE (jdunham @ Mar 5 2009, 09:18 PM)

It looks to me like you have your Source and Destination images backwards in the IMAQ Mask function. If you do wire a destination, it will be overwritten by the operation. Since you never put any data into the source, all you see is a copy of the mask in the output. For most of the IMAQ functions, you don't need to wire the Image Dst at all, and you just modify the source image.

I guess I was confused about the nature of the mask VI itself. Reading the docs, I thought it was supposed to copy the Source *into* the Destination, but only in the pixels defined by the mask as non-zero. I think what you're saying is that the function instead makes a *new* copy of the source with the mask non-zero defined pixels...and replaces anything that was in the Destination memory location with this copy.

So if I'm understanding this correctly... how then would I replace the pixels in the RGB image with the non-masked out pixels in this new Masked image? Man, I know this is a very basic question, but the "ah ha!" switch is not quite closed yet...

Thanks for all your help.

Link to comment

QUOTE (orko @ Mar 5 2009, 10:21 PM)

Well remember, all the IMAQ stuff is by-reference (this confused the hell out of me the first time), and images are big and copying is relatively slow, so the whole system is designed never to copy an image unless you force it to. Just about all the functions operate in-place by default. So the idea is that you wire your image to manipulate into the Source input, and leave the Destination unwired, and the routine modifies your source. Sometimes you want to preserve your original image, so you create a second image and wire it into the Dest, and then you have the before and after, but it's pretty rare to need this.

QUOTE (orko @ Mar 5 2009, 10:21 PM)

So if I'm understanding this correctly... how then would I replace the pixels in the RGB image with the non-masked out pixels in this new Masked image? Man, I know this is a very basic question, but the "ah ha!" switch is not quite closed yet...

So the normal thing is to put your original RGB image into Source, and your 16bit image into Mask, and the result should be an altered version of your RGB image with some pixels preserved and others zeroed out.

OK, I think what you want is a bit more complex that the normal mask. Let's see...

Do I have it right that the only part of the RGB image to preserve is places where the mask is zero, and everywhere else, you want the to keep the grayscale values in the 'mask'?

I think you could invert your mask with the IMAQ Compare, and then that is your mask you apply to the RGB image. At that point you should just be able to IMAQ Add that to the grayscale image, since no pixel would be non-zero in both images.

Link to comment

Make a mask such that

U16 pixels non-zero => mask pix=1 (pixel of interest)

U16 pixels zero => mask pix =0 (not interested)

Apply this mask to the U16 image. Now merge this resultant masked image with your U32 image. Hopefully both images are the same size? (What does merge mean in your case?) Do you want the U16 to display over top of your image (hiding the original)? Displaying with varying amounts of transparency is quite complex (see attached examples) and may not be very fast.

Other approaches:

Overlays will work faster than merges (which involves actually manipulating pixels). You could transform your U16 image to a bitmap and just overlay the bitmap.

ROI tools are very powerful (though not very well documented). If you can define a ROI, you can manipulate those a lot faster. For example you can go from a ROI to a mask and back. You can combine ROI's as well.

Why is it U16? Won't U8 do? Does this overlay change or is it constant from image to image (like a logo for example)? If constant change to bmp at first then just overlay this bmp. Thats what I do with displaying our logo over the processed image on a monitor.

Attached are two interesting examples of merging with transparency. One displays an image of a brain with a tumour overlayed on that image. Its fairly complex, but works. I don't remember where I downloaded them from.

Neville.

Link to comment

QUOTE (jdunham @ Mar 5 2009, 10:44 PM)

Thank you for this. It helps to clear up some confusion I had of what Source and Destination actually are.

QUOTE (jdunham @ Mar 5 2009, 10:44 PM)

OK, I think what you want is a bit more complex that the normal mask. Let's see...

Do I have it right that the only part of the RGB image to preserve is places where the mask is zero, and everywhere else, you want the to keep the grayscale values in the 'mask'?

Yes, that is absolutely correct.

QUOTE (jdunham @ Mar 5 2009, 10:44 PM)

I think you could invert your mask with the IMAQ Compare, and then that is your mask you apply to the RGB image. At that point you should just be able to IMAQ Add that to the grayscale image, since no pixel would be non-zero in both images.

HEY! That sounds doable! I'll try that!

Link to comment

QUOTE (orko @ Mar 6 2009, 02:53 PM)

Yes

QUOTE (orko @ Mar 6 2009, 02:53 PM)

I'm not sure what you mean by combining ROI's and how that would apply here. My U16 image is always going to be the same size as my RGB, so I'm thinking that I probably won't be able to benefit from cordoning off an ROI.

Say for example:

you had a 3 rectangles that you wanted to keep in an image, ignoring the rest of the image (i.e a mask).

You can define each of these as a ROI using Rectangle to ROI, make an array of ROIs, then use Group ROI's to get one composite ROI.

Next use ROI to Mask to transform it into a mask. Its very fast. You don't touch the pixels in the image until the very last step and that too for a relatively small number of pixels.

N.

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.