11-23-2012 09:42 AM
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?
11-23-2012 09:57 AM - edited 11-23-2012 09:58 AM
You iterate through the 2D array with one FOR loop inside another FOR loop.
11-23-2012 11:50 AM - edited 11-23-2012 11:52 AM
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!
11-23-2012 07:02 PM - edited 11-23-2012 07:34 PM
@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!
11-24-2012 04:12 AM
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
11-24-2012 04:12 AM - edited 11-24-2012 04:16 AM
--
11-24-2012 04:49 AM - edited 11-24-2012 04:50 AM
woohoo...an opportunity to use auto-concatenation.
11-24-2012 10:11 AM
@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.
11-24-2012 10:14 AM - edited 11-24-2012 10:18 AM
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.
11-24-2012 10:37 AM - edited 11-24-2012 10:37 AM
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).