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
 Name issues regarding img2m
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

MDiez

Germany
3 Posts

Posted - 09/06/2016 :  02:19:21 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 2016G (32-Bit)
Operating System: Windows 7 Enterprise x64

Hi everybody,

I have some matrix name issues regarding the img2m X-Function in Labtalk. My project is about importing and editing several images and exporting their Greyscale pixel values as a .csv file.
However I am loosing the image's shortname by using the img2m function.
Is there any way to keep the shortname in the output matrix?

I am looking forwart to your reply.

Thanks and Best Regards,

Max

yuki_wu

896 Posts

Posted - 09/06/2016 :  03:34:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Max,

As I know, the image only has a file name in Windows. I don’t know whether the short name of image you mentioned is the file name of image.

If yes, I supposed that you want to rename the matrix with the file name of image. I think you can try this example:

impImage fname:="C:\Program Files\OriginLab\Origin2017\Samples\Image Processing and Analysis\myocyte1.tif" options.names.FNameToSht:=1 options.names.FNameToBk:=0;



You can find more examples of importing image here:
http://www.originlab.com/doc/LabTalk/guide/Importing-Images

If not, please post more details, such as your script here.

Regards,
Yuki
OriginLab

Edited by - yuki_wu on 09/06/2016 03:36:02 AM
Go to Top of Page

MDiez

Germany
3 Posts

Posted - 09/06/2016 :  07:05:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Yuri,

thanks for your reply! You're right the shortname should be the filename of the image. Somehow I loose the filename in the output matrix of my img2m command (third line from below). As far as there I can't find any issues with my code.
Please find my script enclosed:


pe_mkdir Folder path:=aa$;
pe_cd aa$;
string pth1$ = "…\Analyzing pictures\";
string fns, path$ = pth1$;
findfiles fname:=fns$ ext:="*.jpg";   
int n = fns.GetNumTokens(CRLF);            
string bkName$;
string fname$;
int m=n+1;
newbook name:="Matrices" sheet:=1;
newbook name:="Calibration" mat:=1;
impImage fname:="…\Analyzing pictures\Calibration\Calibration.jpg”;
imgResize lock:=1 unit:=pixel w:=400 h:=402 interpolate:=normal;
imgBinary t1:=11 t2:=160;
img2m;
m2w method:=direct xy:=noxy ow:=[Matrices]<Calibration>;
for(int ii = 1; ii<=n; ii++)               
{
    fname$ = fns.GetToken(ii, CRLF)$;
    newbook s:=0 mat:=1 result:=bkName$;   
     impimage orng:=[bkName$]msheet1;       
    matrix -pg DIM nCol1 nRow1;matrix -pg DIM nCol1 nRow1;
    imgResize lock:=1 unit:=pixel w:=400 h:=402 interpolate:=normal;
    imgC2gray;
    img2m;
    expMatASC type:=csv path:"…\Excel Export\%H_.csv"
}


Thanks and Regards,
Max
Go to Top of Page

yuki_wu

896 Posts

Posted - 09/06/2016 :  10:39:28 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Max,

The impimage X-function supports renaming the matrix sheet and matrix book by default, while the img2m X-function does not.

If you want to keep the name, you’d better specify the output range by the file name. I think you can change your img2m to:

img2m om:=[<new>]fname$!1

More details can be found here:
http://www.originlab.com/doc/X-Function/ref/img2m

Hope it helps.

Yuki
OriginLab
Go to Top of Page

MDiez

Germany
3 Posts

Posted - 09/08/2016 :  02:40:18 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Yuki,

thanks for your proposal, it was really helpful.
With your code, I now get the imported image's path as long name for the output matrix. Is there a way to extract the long name from the output matrix, cut off n letters from left and right and set the changed string as short name of the output matrix?

Thanks and Regards,

Max
Go to Top of Page

yuki_wu

896 Posts

Posted - 09/08/2016 :  04:57:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Max,

If you want to rename your matrix only with the file name, you can modify your code:

fname$ = fns.GetToken(ii, CRLF)$;
strFname$ = fname. GetFileName(1)$; //if 1, the file name without extension; if 0, file extension is kept

and then

img2m om:=[<new>]strFname$!1;


You can find more details about function GetFileName on this page:
http://www.originlab.com/doc/LabTalk/ref/GetFileName-cmd

Hope it helps!
Yuki
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