Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

how to overlay a binary image on top of a grayscale image?

here is what i want to achieve.

i have a gray scale image that i will do a thresholding followed by blob extraction and labeling. when displaying this image with pallet option set to binary, i can see each blob labeled by a different color and the rest of the image black.

what i want to show is the original grayscale image with the colored binary blobs on top of it, e.g. if the original image has two blobs, i would like to still show the original image in grayscale, but with its pixels that correspond to blobs replaced by the colored blob in binary.

i'm hoping to do real-time display, so is there a fast trick to do this?
0 Kudos
Message 1 of 8
(8,461 Views)
Thank you for contacting National Instruments. There are a few things that you can do to achieve this results, but depending on what you mean by "real-time" then they may require too much processing to achieve the results. First, if you have a grayscale image, then you either need to use an overlay to display color on top of the image or convert the image to RGB (color) if you want to actually modify the image to include color. The easiest way would be to apply overlays to your images over the areas where you have identified the particles through your binary analysis. Using the particle analysis reports you can get the coordinates, size, etc.. of the objects and then use that information to add the necessary overlays to your image.

The other option could be to create a mask out of your binary image and then use IMAQ FillImage to add in colors to those regions on the original image. Again, you will probably have to convert the image to color in order to use this function and have color represented on the image.

Regards,
Michael
Applications Engineer
National Instruments
Message 2 of 8
(8,443 Views)

Hi Michael,

Can you give me way to get the coordinates of all pixels in the particle. Is it possible through Particle annalysis report ?

 

Thanks 

0 Kudos
Message 3 of 8
(7,973 Views)

Hi,

 

In general the are two possibilities how to do this.

 

Method 1 - overlay your labeled image over gray image as bitmap overlay:

 

Method1.png

Advantage - you will still see true gray values (also under overlay). Otherwise, this is not fastest way.

 

Method 2 - embed labeled image into gray image (resulting image will be RGB, of course):

 

Method2.png 

This method probably will be faster (especially if you will put this code into DLL). 

 

 Result will be the same in both cases:

 

Result.png

 

Example (modified NI example) in attachment. LV 8.6 + Vision 8.6.

 

Andrey.

 

Message 4 of 8
(7,965 Views)

I could imagine that you might want to see some structure in your labeled and colored particles. Then I would suggest to dim the gray image so that it just uses the gray level range from roughly 0 to 192. and convert it to RGB. The binary image need to be converted to RGB as well. Here adjust maximum intensity to 255-192=63. Now separate both images in colorplanes and add repective planes. Now convert the colorplanes back to an RGB image.

 

I did this once using LV 7.2 to overlay a fluorescence signal to a real time video image from an endoscope. I could get a frame rate of about 15 frames per second. But I haven't investigated what was the limitation.

 

Regards, Jörn

0 Kudos
Message 5 of 8
(7,932 Views)

Jörn,

 

Well, if you follow this method where display splitted with two ranges, then you don't need to display RGB image and play with color planes.

You can display gray image with indexed colors with user-defined palette, something like that:

 

Method3.png

 

The result looks same as above (take a note - here 8 bit image displayed, not RGB):

 

Method3Res.png

 

This is probably fastest way (especially if ImageToArray / ArrayToImage will be placed in DLL).

 

Andrey.

 

Message 6 of 8
(7,920 Views)
Right, but In your approach the particles are plain colored with an opaque color. You don't see any structure in the marked areas (like e. g. cell cores). The intention of my suggestion is to have a transparent colouring of the marked particles which also appear brighter than the rest of the image.
0 Kudos
Message 7 of 8
(7,917 Views)

Ah so, now understand. Yes, if you need "transparency" effect, then you need algorithm like you have described above.

 

Message 8 of 8
(7,915 Views)