cancel
Showing results for 
Search instead for 
Did you mean: 

Change array/ image

Alice12
Member

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?

Tags (1)
11 REPLIES 11
Trusted Enthusiast

Re: Change array/ image

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

 

 

Ray.R
Knight of NI

Re: Change array/ image

Message contains an image Message contains an attachment

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!

altenbach
Knight of NI

Re: Change array/ image


@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. Smiley Very Happy

 

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!

 

Alice12
Member

Re: Change array/ image

Message contains an attachment

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

Alice12
Member

Re: Change array/ image

--

BillMe
Active Participant

Re: Change array/ image

Message contains an image

replaceintensityvalues.png

 

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

altenbach
Knight of NI

Re: Change array/ image


@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. Smiley Wink

 

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.

altenbach
Knight of NI

Re: Change array/ image

Message contains an attachment

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.

Highlighted
altenbach
Knight of NI

Re: Change array/ image

Message contains an image Message contains an attachment

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).