02-20-2025 11:17 AM
Hi there,
I am doing some script to process some Greyscale image to find out the "Void" and calculate the percentage of "Void" compared with the whole area.
Attached is the partial of the image. From the image, you can see underneath it has a lot of bubbles, we called them "void".
I was initially using IMAQ threshold by selecting a range of Pixels which it is defined as "Void" and use IMAQ histogram to calculate the void percentage.
But the way I use, choosing a "Range of Pixels", are not really working well.
Because some of the Void Pixels are so close or similar to non-Void area.
It is either overlapped too much of non-Void area or covered too less of Void area.
I am literally new to VDM. I wonder is there any good feature can help with my image processing?
Thanks and looking forward on the response.
Regards,
VZ
02-20-2025 12:38 PM
Hi,
By quickly testing your capture with some filters in Vision Assistant (which comes with the Vision Development Module), I couldn't have conclusive results either.
Before doing any processing, it is always better to try having the best quality as possible for the source image.
For example:
1. Your image is a bit blurry, noisy and not well contrasted. Try adjusting the lens focus and aperture. There are also software parameters such as gain and exposition time that can be configured from NI-MAX and/or with the IMAQdx VIs / property nodes.
2. There are some black stripes covering your bubbles. Try to remove them physically, if possible of course.
3. It seems your illumination is not homogeneous. You have vertical bands on the left and on the right that are slightly darker. Having a constant source of light pointed at your inspection area (provided that it does not add reflections) can also make the background more homogeneous.
For item 3, another idea could be to take an image of reference with a test subject with no bubble, so you would just have the background, then subtract this reference from the real test images. It should globally homogenize your image brightness and make the task easier for contour analysis.
Regards,
Raphaël.
02-20-2025 03:08 PM
Thanks for the response!
Unfortunately, this is the image captured from a X-ray machine.
This image is part of the inside of a small semiconductor component, it is enclosed and seal.
The Quality of image will be roughly around this and any stripes can't be removed.
Is there a way that can process the image layer by layer?
Like lighter part visually we can tell is top layer. Then, darker part visually is lower layer and so on.
02-21-2025 05:07 AM - edited 02-21-2025 05:13 AM
@chngveez wrote:
Thanks for the response!
Unfortunately, this is the image captured from a X-ray machine.
Well, if you have an X-ray image, the usual Signal to Noise Ratio is typically low. To improve the SNR, I would recommend acquiring multiple images and averaging them together using IMAQ Compute Average Image. This is a common approach.
For image processing point of view, modern machine learning methods are very applicable nowadays, but they require a large number of pre-segmented images to train the model. Below, I'll describe a more or less "classical" approach.
You shared a PNG file with an RGB image, but in fact, this is a grayscale image. Typically, X-ray images are 16-bit, and I would recommend keeping them as 16-bit to utilize the full dynamic range.
For now, I will extract the intensity plane to convert the RGB image to an 8-bit grayscale image:
Now it's time to remove the annoying black lines, otherwise you will get holes and stripes in the thresholded image:
Here is a pretty simple trick — because your stripes are strictly horizontal and vertical, you can apply a linear (single line) Median Filter twice horizontally and vertically, something like this:
I will use 19 for both dimensions. Now, your image looks like this (this action will remove some very small particles, and I’m not sure if you need them. In any case, they will be processed separately later):
However, you still have vertical shadows. Since they are strictly vertical, you can compute the linear average horizontally along X-Axis and then apply Flat Field Correction using this as a bright image. Something like that:
This will give you this image, which is suitable for Flat Field Correction:
Then you can use this image in IMAQ Flat Field Correction (keeping the dark image disconnected). The corrected image will look like this:
And with such image you can proceed with thresholding. The single 'fixed value' threshold will not work well, so you will need to use local thresholding instead. Assuming you need to segment both large and small voids, thresholding can be performed twice: once for each. For small voids, you can use the original (non-median filtered) image, because after median filtering, some small voids may disappear along with the black lines. Both combined together with IMAQ Or.
To get better contours, you might need some morphological post-processing:
With a simple trick, you can turn these into IMAQ overlay:
Now, put everything together:
And the result:
For experiments, I would like to recommend using the NI Vision Assistant, which is delivered together with the Vision Development Module. Additionally, to get a deeper understanding of image processing, I suggest reading the book 'Digital Image Processing' written by Rafael Gonzalez and Richard Woods.
The code in the attachment (has been downgraded to LV2018). Feel free to use it as a starting point (it is just a quick and dirty "breakfast exercise" some voids are not or only partially detected, and there is still a lot of work and "fine tuning" ahead to make it stable for every image you have).
02-21-2025 12:19 PM
Hi Andrey,
Wonderful, thanks for your hard work! This is exactly something I am looking for.
I will try it out and let you know the outcome.
The image is actually from a snipping tool (always use RGB image), I can't share the actual image due to some reason especially in this public forum. The actual image will be in 8 bit bmp.
02-21-2025 11:18 PM
@chngveez wrote:
Hi Andrey,
Wonderful, thanks for your hard work! This is exactly something I am looking for.
I will try it out and let you know the outcome.
Glad to see it was helpful for you. I'm not sure about your particular setup, but classically in X-ray image processing, the Flat Field correction is the very first step. You should acquire and average a couple of dark images (typically 30-50) taken in the absence of X-rays, then bright «air» images (stay close to saturation level, but avoid overexposure), with X-rays but without an object. Sometimes these images are also known as «offset» and «gain», save these images. Then, after Flat Field correction of the each shot (the number of images to average depends on performance requirements), you will get a perfectly «flat» image without gradients. If these shadows and marks are always in exactly the same place, they will be removed by Flat Field Correction as well. Your final goal is to get an image as flat as possible, gradient-free, so that even a trivial threshold will catch all voids. Good luck!