Jump to content

Delete 0 value from 2D array


Recommended Posts

Hi all,

pic000021.jpg

edgedetection.jpg

I attach here my vi. Basically, what it does are:

1. read an image (in this case, an image of a strip)

2. use IMAQ rake to scan the image (from left to right direction) and detect all edges

3. calculate the midpoint of the strip

  • if found 2 edges: there is only 1 midpoint
  • if found 4 edges: there are 2 midpoint

4. put into array and display the minimum and maximum x-value in the array

The problem I've got are:

1. The minimum x-value is wrong because it display 0 - this is because when I merge the 2 arrays (outside loop), there will be 0 value to be placed in the array

2. how should I insert elements from array A2 just after inserting elements from array A1. For example:

  • In the case if 4 edges are detected, let say the points are (i) 55,100 (ii) 60,100 (iii) 150,100 (iv) 155,100
  • the midpoints are (example) 57.5,100 and 152.5,100
  • in the A3, how should I place these two midpoints one after another?

Hope all of you can give me a hand on this.

I'm using Labview 8.5.1

Many thanks.

Amila

Link to comment

QUOTE (amila @ May 8 2009, 05:52 AM)

  • if found 2 edges: there is only 1 midpoint
  • if found 4 edges: there are 2 midpoint

The problem I've got are:

1. The minimum x-value is wrong because it display 0 - this is because when I merge the 2 arrays (outside loop), there will be 0 value to be placed in the array

2. how should I insert elements from array A2 just after inserting elements from array A1. For example:

  • In the case if 4 edges are detected, let say the points are (i) 55,100 (ii) 60,100 (iii) 150,100 (iv) 155,100
  • the midpoints are (example) 57.5,100 and 152.5,100
  • in the A3, how should I place these two midpoints one after another?

Well, just check first if you have 2 or 4 edges. Use a case structure to selectively build the arrays based on each case (with the build arrays inside).

Or Make a cluster for each edge: {Pt1[x,y], Pt2[x,y], Mid-pt[x,y]} and output the cluster at every iteration where an edge is found. Then you have an array of clusters with the solutions inside.

N.

Link to comment

QUOTE (Neville D @ May 8 2009, 07:42 PM)

Well, just check first if you have 2 or 4 edges. Use a case structure to selectively build the arrays based on each case (with the build arrays inside).

Or Make a cluster for each edge: {Pt1[x,y], Pt2[x,y], Mid-pt[x,y]} and output the cluster at every iteration where an edge is found. Then you have an array of clusters with the solutions inside.

N.

Hi Neville,

Thanks for your reply. I want to know

1. for case of 4 edges, should I build 2 arrays in the case structure or only 1 array?

2. how would I merge the array from both cases without having any 0,0 value in the merged array?

Thanks.

Link to comment

QUOTE (amila @ May 8 2009, 02:08 PM)

1. for case of 4 edges, should I build 2 arrays in the case structure or only 1 array?

2. how would I merge the array from both cases without having any 0,0 value in the merged array?

Build the arrays any way you want. Run through the arrays with a FOR loop and discard any pts that you don't want.

Link to comment

QUOTE (Neville D @ May 8 2009, 10:15 PM)

Build the arrays any way you want. Run through the arrays with a FOR loop and discard any pts that you don't want.

I tried to build 2 arrays in case of 4 edges and the combined both of them to form 1 array. But when I looked to the save file, the array of these midpoints have 4 columns. And for the case of 2 edges, value '0' will be placed in the array. How can I turn it into 2 column for x and y only?

Link to comment

QUOTE (amila @ May 8 2009, 11:08 PM)

Hi Ton,

Unfortunately I cannot install OpenG's because I'm using university's computer and we couldn't install anything without authorization.

And actually I need a center point of every pair of edges of this strip.

Just for clearity these VIs are allready present inside your vi.lib, have a look at:

vi.lib\picture\picturesupport.llb

Ton

Link to comment

QUOTE (Neville D @ May 8 2009, 07:42 PM)

Well, just check first if you have 2 or 4 edges. Use a case structure to selectively build the arrays based on each case (with the build arrays inside).

Or Make a cluster for each edge: {Pt1[x,y], Pt2[x,y], Mid-pt[x,y]} and output the cluster at every iteration where an edge is found. Then you have an array of clusters with the solutions inside.

N.

Hi Neville,

I've tried the second suggestion: make a cluster for each edge. I have the results that I want. But the problem is how to save all of them in a file?

Many thanks.

Amila

Link to comment

QUOTE (amila @ May 12 2009, 05:58 AM)

I've tried the second suggestion: make a cluster for each edge. I have the results that I want. But the problem is how to save all of them in a file?

You can't use the Express VI's to do anything but very simple tasks. Look at examples of writing data to file. You already have the strings, write a simple VI to put that stuff into a file.

You can also right-click and convert an ExpressVI to a regular VI to look at the code inside to see if you can modify/re-use any of it. But from the level of questions you are asking, that might just further confuse you.

I would look at the file write examples and go from there. Maybe you can write data line by line (within the loop) instead of collecting it outside the loop and writing everything at once. But the file header (column names) would have to be written prior to loop start.

N.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.