# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution
Highlighted

## Build/ assign value to array elements

I have an array of size 600 by 600 pixels. In a circle of given radius (say 50 pixels) and given origin (given ith row and jth column), I want to plot gaussian distribution, i.e., give the pixels

the value of a 2-D gaussian distribution with peak at the origin. How do I do this in labview ?

Thanks.

Message 1 of 12
(1,260 Views)
Solution
Accepted by topic author Alice12

## Re: Build/ assign value to array elements

You would run your x and y values through the 2D Gaussian function but making the origin 300,300 (for your given 600x600 pixel array). Here's what I get on an intensity chart given an amplitude of 10 and sigma = 100 pixels:

Here's the example (quick and dirty) code:

Message 2 of 12
(1,241 Views)

--

Message 3 of 12
(1,221 Views)

## Re: Build/ assign value to array elements

How do I convert this intensity distribution into a greyscale (uint8) image (a matrix with all elements between 0 and 255) ?

I used "To Unsigned Byte Integer" function but it doesn't seem to solve the problem ?

Message 4 of 12
(1,213 Views)

## Re: Build/ assign value to array elements

Just change the amplitude on the output of the exponential to 255 (instead of the 10 in my code example) and then convert to U8. Like this (after changing the marker colors in the intensity chart):

Message 5 of 12
(1,199 Views)

## Re: Build/ assign value to array elements

I tried to follow your hints but didn't succeed. May be I'm missing something silly.

Attached is my program. Please change it to obtain the desired pattern.

Thanks.

Message 6 of 12
(1,177 Views)

## Re: Build/ assign value to array elements

You used the wrong exponential...Use "exp(x)" instead of "exp(x) - 1".

Message 7 of 12
(1,167 Views)

## Re: Build/ assign value to array elements

Thank you for pointing out the mistake.

It works.

Regards.

Message 8 of 12
(1,162 Views)

## Re: Build/ assign value to array elements

Here's a one-loop version. It is sufficient to calculate a singe 1D gaussan once, then use the outer product to generate the 2D array.

This means we only need to evaluate only 600 exponential functions instead of 360000! (You could reduce it again by 50% taking advantage of symmetry. Try it!)

LabVIEW Champion Do more with less code and in less time
Message 9 of 12
(1,161 Views)

## Re: Build/ assign value to array elements

Thanks.

It's definitely a better approach.

Regards.

Message 10 of 12
(1,148 Views)