09-02-2008 11:39 AM
I need a code Matlab in code LabView. The code Matlab is this:
k = 1;
for i = 1:m
for j = 1:n
if(imageGray(i,j)==255)
Vec1(k,:) = [i j];
k = k + 1;
end
end
end
For this i need create a local variable "k" andI do not know. Help me please.
09-02-2008 11:47 AM - edited 09-02-2008 11:50 AM
In LabVIEW the wire is the variable.
It looks like you want to build a 1D array (Vec1) with all values of an array (Gray) which are 255.
(note all values in the output array are 255, so the code could be a lot simpler. do an =255 on the array, count the numbers of true and build a new array.
Ton
09-02-2008 12:00 PM
09-03-2008 03:47 PM
Hi Chilywiliyx,
Firstly, in order to look at image attributes, unless you are importing the picture as an array you will need the NI-Vision module. If you are importing the picture as a 2D array, then you can create a 2D array on the front panel. Your nested for loops can be converted to nested for loops in LabView and your if condition is a case structure. I hope that answers your question?
Ipshita C.
09-03-2008 04:02 PM
chiliwilyx wrote:
so so, i need to build a 2D(Vec1) array with the position in the image array of all values of this array wich are 255.
OK, you need to tell us more about the desired 2D array output.
Also remember that in LabVIEW the array indices start with zero, while in matlab they start with one.
Lets assume you have the following 2D array input:
255 126 245 053
234 255 255 110
255 080 048 255
102 002 255 255
What should the desired output array look like?
09-04-2008 01:54 PM
For this matrix...
255 126 245 053
234 255 255 110
255 080 048 255
102 002 255 255
the desired output array is...
0 0
1 1
1 2
2 0
2 3
3 2
3 3
you understand me?
09-04-2008 02:08 PM
It looks like you want to search a 2D array for a specified value and return the locations of where this value appears. Try using the attached VI. It was written in LV 8.2.
09-04-2008 03:01 PM - edited 09-04-2008 03:05 PM
Here's a quick draft. One loop ought to be enough! 😉
09-04-2008 03:02 PM
yes you are right but this example to searh only one location of a row, for exmple you have this matrix...
255 255 1
2 255 0
0 255 255
The out is ...
0 0
1 2
2 1
and the out desirable is...
0 0
0 1
1 2
2 1
2 2
09-04-2008 03:10 PM - edited 09-04-2008 03:16 PM
Do you want the VI to find all occurances of 255 or just the first occurance of 255 on each row?
edit: You're right my VI doesnt work correctly. Just use the one that was posted after mine.