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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Name issues regarding img2m

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
MDiez Posted - 09/06/2016 : 02:19:21 AM
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
5   L A T E S T    R E P L I E S    (Newest First)
yuki_wu Posted - 09/08/2016 : 04:57:38 AM
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
MDiez Posted - 09/08/2016 : 02:40:18 AM
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
yuki_wu Posted - 09/06/2016 : 10:39:28 PM
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
MDiez Posted - 09/06/2016 : 07:05:52 AM
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
yuki_wu Posted - 09/06/2016 : 03:34:11 AM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000