cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
d_barnett
Level IV

Crop Image and Insert Crop Into Data Table

I'm currently running a script that inserts a 1Mb image into a data table using the following simple script ( where :link to image is a network drive where the jpg is stored)

Formula( Open( :Link to Image, "jpg" ) ),

Due to the size of the image the data table is getting large ( I have ~1500 images) and have tried the crop function but cannot get the syntax correct

one of the various ways I have tried is the following ( and probably all combinations of this apart from the correct one!).

Formula( Open( :Link to Image, "jpg" ) ) << crop( Left( 190 ), top( 0 ), bottom( 1690 ), Right( 700 ) ),

I feel I'm close but not quite there.

Ideally it would do the following

  1. Open the image ( one at a time to save computer memory?)
  2. crop the image, then save the crop into a central folder. This would then allow for additional image analysis if required.
  3. Insert the crop into the data table
  4. Close the original image.

Regards

David

1 REPLY 1
txnelson
Super User

Re: Crop Image and Insert Crop Into Data Table

Here is an example script that does what you indicated you wanted

Names Default To Here( 1 );

// Get the list of the pictures

filelist = Files In Directory( "$SAMPLE_IMAGES" );

// Loop across all of the pictures, cropping and saving

For( i = 1, i <= N Items( filelist ), i++,

       // Using a Substitute because the extension value needs to be an expression,

       // not a literal

       Eval(

              Substitute(

                           Expr(

                                  img = Open( "$SAMPLE_IMAGES\" || filelist[i], __extension__ )

                           ),

                     Expr( __extension__ ), Parse( Word( -1, filelist[i], "." ) )

              )

       );

       // Allow time for the image to be read

       Wait( 1 );

      

       // Crop the image

       img << Crop( Left( 50 ), Right( 100 ), Top( 60 ), Bottom( 150 ) );

       // Save the image to a new folder

       img << Save Picture( "<path to save folder>" || filelist[i], Word( -1, filelist[i], "." ) );

);

// Create a new table

New Table( "Untitled",

  Add Rows( N Items( filelist ) ),

  New Column( "image", Expression, "None", Set Values( {} ) )

);

// Populate the image column

foreachrow(

  :image = newimage("<path to save folder>" || filelist[row()])

);

Jim