LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Change array/ image

I have an image (an array of size 600 by 792 pixels) whose pixels value ranges from 0 to 255. I want to change the pixels with value 255 to a particular value (say 0). 

How do I do this in labview?

0 Kudos
Message 1 of 12
(3,327 Views)

You iterate through the 2D array with one FOR loop inside another FOR loop.

 

 

0 Kudos
Message 2 of 12
(3,322 Views)

Let's try without the use of any For Loops:

 

 

 

This method is r-e-a-l-l-y fast.  You flatten your array to string, search and replace ALL matching values (see TRUE wired at top?), then unflatten back to the 2D array.  VOILA!

0 Kudos
Message 3 of 12
(3,306 Views)

@Ray.R wrote:

This method is r-e-a-l-l-y fast.



I would think it would be significantly faster if you would use U8 representation. Matching a single character is easier than matching ~4x more possible sets of four bytes. 😄

 

Unless used exclusively with U8, your algorithm also will produce incorrect results. For example if two adjacent values are e.g. x00000000 and 00FF0000 and we replace x000000FF with xCCCCCCCC in 32bit integers, you'll end up with both values changed ( x0000CCCC, xCCCC0000). The string search is not quantized to the data size!

 

Message 4 of 12
(3,291 Views)

Thanks for your help.

I tried to implement your program but it doesn't seem to work (attached file).

Please point out the mistake.

 

Regards

0 Kudos
Message 5 of 12
(3,276 Views)

--

0 Kudos
Message 6 of 12
(3,276 Views)

replaceintensityvalues.png

 

woohoo...an opportunity to use auto-concatenation.

0 Kudos
Message 7 of 12
(3,263 Views)

@Bill@NGC wrote:

woohoo...an opportunity to use auto-concatenation.


Why? "Boolean to 0,1" and "Add array elements" works equally well with 2D arrays. No concatenation needed. 😉

 

Also note that boolean to 0,1 outputs I16, so if the array is large, you might run out of headroom. I would convert to I32 before summing.

(In fact, since you only need a scalar count, it might be more memory efficient to maintain a running sum in a shift register. No second array needed.

 

I would also recommend to make the diagram constants U8 to (1) avoide coercion and (2) use 4x less memory.

0 Kudos
Message 8 of 12
(3,250 Views)

Alice12 wrote:

I tried to implement your program but it doesn't seem to work (attached file).

Please point out the mistake.


Your two blue diagram constants are I32, they need to be U8. I8 will gemerate four bytes and you are trying to match four consecutive U8 elements, which is rare.

 

Solution: right-click the two blue diagram constants and select representation...U8.

0 Kudos
Message 9 of 12
(3,249 Views)

Here's a code skeleton that can easily be adapted to other datatypes if needed. (AS mentioned, the flattened string version only works well for U8).

 

 

Download All
Message 10 of 12
(3,246 Views)