Author |
Topic  |
|
cgoerner
Germany
7 Posts |
Posted - 05/02/2022 : 08:01:52 AM
|
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 2022, 9.9.0.225 Operating System: Win10
Hi there!
I'm trying to import several JPG images from a folder and embed them in a graph layer. I know the X-function insertImg2g exists, however the images need to be cropped and resized before I can add them to the graph (imgCrop, imgResize). If I use insertImg2g first, then the inserted image is not set as active, there I can't crop/resize it anymore. If I use impImage and imgResize/Crop first, I can't use insertImg2g since it can only import an image directly from a file.
Are there any other ways I could try to do this? I'm probably not seeing the easy answer right now.
Thank you in advance!
|
|
cpyang
USA
1406 Posts |
Posted - 05/02/2022 : 12:02:18 PM
|
Usually one will need to crop an image by looking at it, so you are saying you will do this in code, and know how to crop from code?
With Origin 2022, once you inserted an image into a graph, you can double-click to open it in the image window and you can then choose to crop it, or clip it. Clipping it will not modify the image, only to modify what is showing in the graph so you can adjust it easily.
CP
|
 |
|
cgoerner
Germany
7 Posts |
Posted - 05/03/2022 : 08:15:25 AM
|
Hi CP!
Specifically, I need to import about 30 pictures of OLEDs (which my company manufactures). They produce 30 new OLEDs a day on a silicon wafer and a measuring instrument takes precise pictures of them:
- the pictures have a uniform layout, so what I need to crop/resize always stays the same - this need to be automated in a Labtalk script, it takes too long otherwise
So I am asking: How can I import, edit and insert several JPG images at the right position in a graph layer with Labtalk? Each image needs to be at a different postion.
I have tried insertImg2g and image.import.object(Graph1,MyObject,0) before, however they do not allow editing the image beforehand. Functions like insertImg2g or image.import.object() do not let me choose a custom position.
How else can I do this with Labtalk?
|
Edited by - cgoerner on 05/03/2022 09:07:12 AM |
 |
|
cpyang
USA
1406 Posts |
Posted - 05/03/2022 : 2:59:48 PM
|
We can add the needed command, but can you let us know how do you plan to position the post-cropped image? A graph page has two kinds of unit, the page unit (pixels), or the layer XY coordinates.
We will be releasing 2022b in a couple of weeks, so we can hopefully squeeze this in.
CP
|
 |
|
cgoerner
Germany
7 Posts |
Posted - 05/04/2022 : 07:27:08 AM
|
Hi CP!
It is very kind of you to consider our problem as a new feature.
So far we import the images that need to be inserted into the graph into a matrix book using imgImage. That way we can easily manipulate it (imgCrop,imgResize works well). From there, they should be inserted into a graph layer at the chosen position.
The desired function would need to a) Take an input matrix book (default:active) b) Take an output graph c) Specify the unit of position coordinates (f.ex. unit:=pixel or unit:=page etc. like in other X-functions) d) Take the x and y coordinate of maybe the upper left corner of the graph page If only one of the units, so either pixels or layer coordinates can be implemented, it is not a big deal.
If anything is unclear, just let me know! |
 |
|
cpyang
USA
1406 Posts |
Posted - 05/04/2022 : 1:37:09 PM
|
We would prefer that you use Image window, as you can easily crop and resize the image in Image window. Your original request was to directly crop the image in the graph, so we have made needed changes in the upcoming version, which you can try with a beta right now. Code will look like the following, to import a bunch of images from disk and crop and arrange them in a graph.
win -t plot;
string strInitPath$=system.path.program$+"Samples\Image Processing and Analysis";
dlgfile g:="*.jpg" m:=1 init:=strInitPath$;
int nn=fname.GetNumTokens(CRLF);
int cleft=50, ctop=30, cright=150, cbottom=130;
for(int ii = 1; ii <= nn; ii++) {
string strf$ = fname.GetToken(ii, CRLF)$;
string strGr$;
insertImg2g fname:= strf$ type:=IMG xyp:=page oname:=strGr$;
GObject gr = strGr$;
if(gr.Crop($(cleft) $(ctop) $(cright) $(cbottom)) == 0) {
int nx = ii*page.width/5;
int ny = 1000;
gr.PageRect$="$(nx) $(ny) $(nx+600) $(ny + 600)";
}
}
So the above assumes you know the exact coordinates to crop the images in code. New LT commands added are Crop() and PageRect$
You can also not to actually crop the images, but clip them with the Crop$ property, like
win -t plot;
string strInitPath$=system.path.program$+"Samples\Image Processing and Analysis";
dlgfile g:="*.jpg" m:=1 init:=strInitPath$;
int nn=fname.GetNumTokens(CRLF);
int cleft=50, ctop=30, cright=150, cbottom=130;
for(int ii = 1; ii <= nn; ii++) {
string strf$ = fname.GetToken(ii, CRLF)$;
string strGr$;
insertImg2g fname:= strf$ type:=IMG xyp:=page oname:=strGr$;
GObject gr = strGr$;
gr.Crop$="$(cleft) $(ctop) $(cright) $(cbottom)";
int nx = ii*page.width/5;
int ny = 1000;
gr.PageRect$="$(nx) $(ny) $(nx+600) $(ny + 600)";
}
Which is better since you can double-click an image and it will open in the Image Window and you can see exactly how it was clipped.
CP |
 |
|
snowli
USA
1426 Posts |
|
Karsten8
Germany
26 Posts |
Posted - 05/30/2022 : 04:25:58 AM
|
Dear Snow and Cpyan,
I am a coworker of Cgoerner - and I will keep on working on this Topic.
First of all - thanks for the implementation of the new function. We upgraded our software to 2022b and it works well.
Using the new function I have some questions working with the integrated jpg's:
1) does the crop-function still work in 2022b? Using your example Code - gr.Crop$="$(cleft) $(ctop) $(cright) $(cbottom)"; It seems that our jpg's are not cropped independed what number we use for cleft,... There is no error code nor the program does not stop - thus I do not see the root cause why cropping does not work. Is there a documentation to this crop-function? I could not find any hint on how to use it.
2) pef_pptslide can not transfer a graph with jpg's to PowerPoint We use the new function to insert 20 jpg's into a graph and want to transfer this graph as Picture into a PowerPoint slide. Using this code we get an error message:
{pef_pptslide export:=page mode:=lname slide:=4 insert:=pic keepratio:=1 left:=5 right:=20 top:=9 bottom:=10 slidemode:=insert srcf:=folder$;}
The ppt document opens and imports all graphs but only the graph with jpg's gives the error code. If I delete the jpg's from the graph then the import of the graph works.
error message: Origin C error (24) in X-Function code. #Command Error!
If I try to use the send-to-ppt-app it seems to have the same problem (without error code - he simply does not transfer the graph with pictures without an error message).
Did I miss to use an option within the pef_pptslide or is this a bug?
3) Copy a graph with implemented jpg's and insert it as Picture into a new graph or layout window
In one usage scenario we import several hundred of jpgs and this slows the program. Thus we thought to make after importing a copy of the graph with all the Pictures and insert a Picture of this graph+jpg's into a new graph or layout field (then delete the graph with all jpg's).
Using the option {copypic type:=0 res:=600} we can make a picture and move it to clipboard. But we could not find a command how to paste this picture from clipboard into a new graph window. Do you have an idea how to solve this task?
4) Delete import-data from RAM to speed up Origin? After importing several hundred of jpg's Origin is quite slow. Is there an option to delete the import-data from RAM since we do not need it anymore. After restart of Origin it seems that these data is deleted and the software is fast as usual.
Thanks for your help.
Karsten8.
|
 |
|
cpyang
USA
1406 Posts |
Posted - 05/30/2022 : 09:56:04 AM
|
So with 2022b, it works with the gr.Crop() function but clipping with gr.Crop$ did not work for you?
I tried again with the code I posted before
win -t plot;
string strInitPath$=system.path.program$+"Samples\Image Processing and Analysis";
dlgfile g:="*.jpg" m:=1 init:=strInitPath$;
int nn=fname.GetNumTokens(CRLF);
int cleft=50, ctop=30, cright=150, cbottom=130;
for(int ii = 1; ii <= nn; ii++) {
string strf$ = fname.GetToken(ii, CRLF)$;
string strGr$;
insertImg2g fname:= strf$ type:=IMG xyp:=page oname:=strGr$;
GObject gr = strGr$;
gr.Crop$="$(cleft) $(ctop) $(cright) $(cbottom)";
int nx = ii*page.width/5;
int ny = 1000;
gr.PageRect$="$(nx) $(ny) $(nx+600) $(ny + 600)";
}
and it worked for me with official 2022b. gr.Crop$ is kind of a confusing name, unfortunately, and we will check with doc update, and next version we will add gr.clip$ alias to make it clear.
gr.Crop(left,rgiht,top,bottom) -- this crop the image gr.Crop$=, this is actually not doing cropping but clipping the image, so it appeared to be cropped on the graph but if you double-click to open in the image window, you can see the full image.
CP
|
 |
|
Karsten8
Germany
26 Posts |
Posted - 06/03/2022 : 03:25:21 AM
|
Dear CP,
thanks for you answer. I misunderstood the cropping command. It works as you propose.
Best regards,
Karsten8. |
 |
|
|
Topic  |
|
|
|