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
 Forum for Origin C
 open bitmap (.bmp)
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

hydrix

Posts

Posted - 10/31/2008 :  03:48:30 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
hello,
how can i open a .bmp file pixel by pixel in an origin matrix?
best would be the color code as an integer or binary.
thanks for your help...
hydrix

Deanna

China
Posts

Posted - 10/31/2008 :  9:39:48 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi, would you please tell us the version of Origin you are using?

If you are using Origin 8, which provides the impImage X-Function, it is easy to import an image file into a matrix because you can call that X-Function in your Origin C code. Of course, the importing can be done in other versions, too. But the code may be different. So please tell us the version of Origin you are using before we can help you.

Deanna
OriginLab Technical Services
Go to Top of Page

hydrix

Posts

Posted - 11/01/2008 :  06:53:51 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
hi deanna,

at the moment i am using 7.5 but in a few weeks i will have the new version 8.0. as i'd like to start my programming project now i would prefer the code for the older version. however i would be glad if you could send me the code for the 8.0 version too.
thank you very much.

hydrix
Go to Top of Page

Deanna

China
Posts

Posted - 11/03/2008 :  8:56:07 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Hydrix,

You can try the following function:


void import_image_into_matrix(string strMatrixName, string strImagePath)
{
	string strCMD;
	strCMD.Format("image.fileName$ = %s;", strImagePath);
	LT_execute(strCMD);
	
	strCMD.Format("image.import.matrix(%s);", strMatrixName);
	LT_execute(strCMD);
	
}


This should work in both Origin 7.5 and Origin 8.0. After compiling the function, you can use it. Suppose you have a matrix named "matrix2" and the file you wished to import is "c:\test\car.bmp". Execute the following LabTalk script in the Script Window:
import_image_into_matrix("Matrix2", "c:\test\car.bmp");



Deanna
OriginLab Technical Services
Go to Top of Page

hydrix

Posts

Posted - 11/05/2008 :  01:01:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
hi deanna,
thanks the import works well. however, to the code

void import_image_matrix(string strMatrixName, string strImagePath)
{
string strCMD;
strCMD.Format("image.fileName$ = %s;", strImagePath);
LT_execute(strCMD);

strCMD.Format("image.import.matrix(%s);", strMatrixName);
LT_execute(strCMD);
Matrix matA;
matA.Attach("Matrix2");
double dMean;
dMean = matA.GetMean(); // Use matrixbase::GetMean function
printf("Mean of Matrix2: %g\n", dMean ); // Print out mean

}
i get the error: "Calling members of unattached wrapper class".
How can i attach the imported matrix to the matrix in the code correctly?
and i have one further question.
how can i display the matrix not as an image but as a matrix of numbers. (the color code as an integer, binary or hex)?
thanks a lot.
by the way: i am using origin 8 now, so i have acces to the x-functions.

hydrix
Go to Top of Page

eparent

118 Posts

Posted - 11/06/2008 :  2:11:23 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by hydrix
void import_image_matrix(string strMatrixName, string strImagePath)
{
string strCMD;
strCMD.Format("image.fileName$ = %s;", strImagePath);
LT_execute(strCMD);

strCMD.Format("image.import.matrix(%s);", strMatrixName);
LT_execute(strCMD);
Matrix matA;
matA.Attach("Matrix2");
double dMean;
dMean = matA.GetMean(); // Use matrixbase::GetMean function
printf("Mean of Matrix2: %g\n", dMean ); // Print out mean

}
i get the error: "Calling members of unattached wrapper class".
How can i attach the imported matrix to the matrix in the code correctly?
and i have one further question.
how can i display the matrix not as an image but as a matrix of numbers. (the color code as an integer, binary or hex)?
thanks a lot.
by the way: i am using origin 8 now, so i have acces to the x-functions.

hydrix



Hello,

I have created the following wiki page to provide examples of how to import an image into a matrix and access the matrix data afterwards.

http://ocwiki.originlab.com/index.php?title=OriginC:Image_Import#Import_a_BMP_File

Let me know if you have any questions regarding the code on this wiki page.

Thanks,
Eric
Go to Top of Page

hydrix

Posts

Posted - 11/07/2008 :  02:43:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
hi eric,
i have problems finding the oimg_image_info funktion.
could you please specify where i can find it?
thanks!
hydrix
Go to Top of Page

eparent

118 Posts

Posted - 11/07/2008 :  09:39:36 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by hydrix

hi eric,
i have problems finding the oimg_image_info funktion.
could you please specify where i can find it?
thanks!
hydrix



Sorry, I forgot to say that the oimg functions are delcared in import_image.h. I have updated the wiki page.

Add the following to the top of your c/cpp file:
#include <import_image.h>


Thanks,
Eric
Go to Top of Page

hydrix

Posts

Posted - 11/07/2008 :  11:42:35 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
hey eric,
all right, "import_image_to_matrix_data"
is now compiling. in the function MyTest that is listed below you have to replace "strImagePath" by "strFileName" else the example is not working.

MyTest then works well with no parameters (it then puts the data of the sample image "Car.bmp" into the matrix "MBook1")
however i have problems to execute

MyTest(MyMatrixName,C:\Data\MyBitmap.bmp)

from the Labtalk window.

where is my mistake?

and: by which additional code in MyTest could i access single matrix entries?

thanks in advance

hydrix
Go to Top of Page

eparent

118 Posts

Posted - 11/07/2008 :  3:15:02 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
quote:
Originally posted by hydrix

hey eric,
all right, "import_image_to_matrix_data"
is now compiling. in the function MyTest that is listed below you have to replace "strImagePath" by "strFileName" else the example is not working.

MyTest then works well with no parameters (it then puts the data of the sample image "Car.bmp" into the matrix "MBook1")
however i have problems to execute

MyTest(MyMatrixName,C:\Data\MyBitmap.bmp)

from the Labtalk window.

where is my mistake?

and: by which additional code in MyTest could i access single matrix entries?

thanks in advance

hydrix



Hello,

Your syntax looks correct. Is your first argument a book name or a sheet name. The MyTest function is expecting a book name for the first argument. Not a sheet name. You can also use the following syntax to call an Origin C function from LabTalk:

MyTest MyMatrixName C:\Data\MyBitmap.bmp

Notice the arguments are separated with a space.

Also, since you are now using 8.0 you can also call X-Functions from LabTalk. The following shows how to call the X-Function for importing an image into a specified sheet of a specified book.

impImage C:\Data\MyBitmap.bmp orng:=[MBook1]MSheet1;


Access to the matrix values can be done using the Origin C Matrix class. This class has a GetCellValue member function. Another way is to assign the Matrix instance to a pointer as shown below:

int index = 0;
Matrix<WORD> mm("MBook1"); // matrix with 16-bit data
if( mm.IsValid() )
{
	WORD* pw = (WORD*)mm;
	printf("%d\n", pw[index]);
}


I hope this helps.

Thanks,
Eric
Go to Top of Page

hydrix

Posts

Posted - 11/11/2008 :  11:21:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you!
Works!
Hydrix
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