The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Remove Duplicates from a matrix
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Pls_help_me

8 Posts

Posted - 07/04/2014 :  03:28:26 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hello,
I try to find all unique values in a Matrix (ranged from a minimum of 2 to a maximum of 15)filled with RGB values.
As a second step i try to count how often which of these values is present in the matrix.
Is there a possibility to do this?
I fear that i don't even have any suggestion in order how to start working on this problem since I am new to LabTalk and just starting to work with it.

Thanks for your replies in advance.
Greetings
Raphael


Origin Ver. and Service Release (Select Help-->About Origin): 9.1.0G Sr2
Operating System: Win7

Just my signature...

Kathy_Wang

China
159 Posts

Posted - 07/07/2014 :  03:05:17 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I think you could try this approach, that is first convert the matrix into XYZ worksheet data using m2w x-function, and then use the "Discrete Frequency" tool (discfreqs x-function) to calculate the count on Z column (will be the RGB values presented in matrix)

So an example of the script would be:


// Need to activate the matrix book
m2w method:=xyz;
// Need to make sure the converted worksheet data is activated
discfreqs irng:=[%H]1!3


Kathy
Originlab
Go to Top of Page

Pls_help_me

8 Posts

Posted - 07/07/2014 :  10:41:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello and thanks a lot for your reply.
Your suggsted method works perfectly except for the problem that the conversion from matrix to workbook messes with my RGB values. So in the end i get my unique numbers with the correct count.
So i have to find out which RGB-value belongs to which converted number.
Is there a way to find out how the conversion works exactly so i can figure out how to calculate the original RGB-value based on the converted values?

Best regards and thank you for your time
Raphael



Just my signature...
Go to Top of Page

Kathy_Wang

China
159 Posts

Posted - 07/07/2014 :  11:42:09 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The conversion from RGB to the numeric data is done following this relationship:

converted value = R + 256 * G + 256 * 256 * B

Based on this relationship it is possible to convert the numeric data back to R, G, B. So the script sample could be extended to something like:


// Need to activate the matrix book
m2w method:=xyz;
// Need to make sure the converted worksheet data is activated
discfreqs -r 1 irng:=[%H]1!3

// Add three new columns to result sheet
wks.addcol();
wks.addcol();
wks.addcol();

// Set the column long names
col(3)[L]$ = "R";
col(4)[L]$ = "G";
col(5)[L]$ = "B";

// Apply equation to each column to calculate R/G/B value respectively
csetvalue col:=col(5) formula:="int(col(1)/(256*256))" recalculate:=1;
csetvalue col:=col(4) formula:="int((col(1) - 256 * 256 * col(5))/256)" recalculate:=1;
csetvalue col:=col(3) formula:="col(1)-256*col(4)-256*256*col(5)" recalculate:=1;


Note that the csetvalue x-function<http://www.originlab.com/doc/X-Function/ref/csetvalue> is used to set a formula for a column, and the int() function<http://www.originlab.com/doc/LabTalk/ref/Int-func> is used to get the integer part of a float number.

Kathy
Originlab
Go to Top of Page

Pls_help_me

8 Posts

Posted - 07/08/2014 :  04:48:58 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hello Kathy, your method works perfectly for my problem thanks a lot.
The final step for me would be to import multiple images at once and analyse them all at once to get the results in seperat result sheets.
I thought of something like the following but it does not work properly yet. Can you tell me what my mistakes are and how to solve them? I believe that the problem is that in my case I da have several matrix objects. Which is why my method can not work?


newbook mat:=1; //new matrix
impimage; //import of images
matrix -ii 0; //switch to data mode


//loop over all files
for(int iFile = 1; iFile <= fname.GetNumTokens(CRLF); iFile++)
{
m2w method:=xyz; //converting to worksheet
discfreqs -r 1 irng:=[%H]1!3; //Counts of the seperate values

// three new columns
wks.addcol();
wks.addcol();
wks.addcol();

// set names
col(3)[L]$ = "R";
col(4)[L]$ = "G";
col(5)[L]$ = "B";

// backconversion of worksheet values
csetvalue col:=col(5) formula:="int(col(1)/(256*256))" recalculate:=1;
csetvalue col:=col(4) formula:="int((col(1) - 256 * 256 * col(5))/256)" recalculate:=1;
csetvalue col:=col(3) formula:="col(1)-256*col(4)-256*256*col(5)" recalculate:=1;
}

Best regards and thank you for your help so far.
Raphael

Just my signature...

Edited by - Pls_help_me on 07/08/2014 04:54:15 AM
Go to Top of Page

Kathy_Wang

China
159 Posts

Posted - 07/08/2014 :  05:53:26 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You should first loop over all the image files and import into separate matrix books, and then loop over all matrix books to do the calculation.

Here is an example to Import Multiple Images to Matrix Book <http://www.originlab.com/doc/LabTalk/guide/Importing-Images#Import_Multiple_Images_to_Matrix_Book>.

And after that, you will have several matrix books in your Origin project file, and then you could use "doc -e M" to loop over all matrix books (see the help file http://www.originlab.com/doc/LabTalk/ref/Document-cmd#-e_object_.7Bscript.7D.3B_Execute_the_given_script_for_all_objects)

So would be something like:


doc -e M
{
    // put the script you want to execute for every matrix here
}


Kathy
Originlab
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000