From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Vision Pixel-by-Pixel Calculation

Solved!
Go to solution

Hi Vision cracks 😉

It would be great if you could help me!

I've worked with the NI Vision Development Toolkit for a long time. So far I have only used the build in filter functions.
I now have a special problem and I still have no idea how I could solve it, or whether it is even possible with vision.
I have an initial image from which I want to create a new filtered image.

The results of the calculations with the center pixel on image A should be written into the pixel at the same position in the new image.

Pixel by Pixel Processing:

  1. Calculation of the mean value from the center pixel and the surrounding 8 pixels (green 3x3 area in the attached image).
  2. Calculation of the mean value from the 16 surrounding pixels (orange area around the green 3x3 area)
  3. Dividing the mean value from 1. by the mean value from 2.
    (In the attached picture I call it A divided by B)
  4. Write the result in a new picture

The calculation should run pixel by pixel like a sliding window, calculate all pixels in the image and create a new image from the results.
Is that possible?

Pix-By-Pix-Calculation.jpg

Best

Peter

0 Kudos
Message 1 of 12
(2,074 Views)

Sure it is possible.  Have you started it?

 

Think of a set of loops where you act on the original array pixel by pixel, and put the results in a new array.

0 Kudos
Message 2 of 12
(2,050 Views)
Solution
Accepted by PietH

NIVision does support a custom kernel operation, although IIRC it's hidden and hard to use. Probably documented here: Convolution Kernels - NI Vision 2019 for LabVIEW Help 

 

A kernel of all 1's, divided by the number of 1's should give the average.

 

I'm pretty sure running two build-in kernel operations and then dividing the results will be faster than any DIY solution. But maybe not... Less work for sure.

 

DIY (performant) kernel operations are much trickier than you'd think.

 

Message 3 of 12
(2,019 Views)

Thanks for your answer.

That it works with array operations is clear.

But I wanted to avoid that. However, this is time-consuming and is not as precise as when I do it directly with Vison. Do you still have an idea how to solve it with vision?

Best

Peter

0 Kudos
Message 4 of 12
(2,012 Views)

Thanks for your help.

I know the document about convolution kernels. I use them very often.

It is also very easy to use an average  filter.

The problem here, however, is to average two different areas around the center pixel in the image, to divide the 2 mean values and to write the result in a new image and that in one work step, from one pixel to the next.

Maybe you have an example how to do it?

Best

Peter

0 Kudos
Message 5 of 12
(2,008 Views)
Solution
Accepted by PietH

Calculate the 2 kernels in 2 images. Then use the IMAQ Divide VI to divide the two.

 

Of course care should be taken to use the correct data types.

 

I can't make an example, I don't have IMAQ installed at the moment.

0 Kudos
Message 6 of 12
(1,991 Views)
Solution
Accepted by PietH

Something like this should work. Be careful with divisions by zero with SGL images, the image indicator can slow down LabVIEW.

 

*Edit: reading your reply you want to create a new image so a new buffer should be connected to the Image DST input for IMAQ Divide vi.

 

snip.png

Message 7 of 12
(1,986 Views)

Thanks a lot. I will try it out!

0 Kudos
Message 8 of 12
(1,946 Views)

Hi Ramon,

thanks a lot.

It works good and its fast!

Peter

 

 

 

 

0 Kudos
Message 9 of 12
(1,924 Views)

Thank you all for your help!

I learned a lot. Kernels are very powerful and versatile.

Creating a convoltion kernel for averaging is easy!

But what about the maximum value?

If I want to calculate a maximum value from the 9 pixels and the 16 surrounding pixels.

Is that possible with vision?

 

Pixel by Pixel Processing:

  1. Calculation of the max value from the center pixel and the surrounding 8 pixels (green 3x3 area in the attached image).
  2. Calculation of the max value from the 16 surrounding pixels (orange area around the green 3x3 area)
  3. Dividing the mean value from 1. by the mean value from 2.
    (In the attached picture I call it A divided by B)
  4. Write the result in a new picture
0 Kudos
Message 10 of 12
(1,912 Views)