cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
lsamuelso
Level I

Image Conversion from TIFF to JPEG Within JMP?

Is there a way to convert an image type in a jmp script prior to adding it in an image column in a table?  I have a bunch of .tif files which reside in a .zip file.  I can read the data from a specific image into a table using a script like this:

dt = New Table( "test", New Column( "Image", Expression ) );
dt << Add Rows( 1 );

za = Open( "tif_library", "zip" );
dat = za << Read( "tif_file_n.tif", Format( blob ) );
img = New Image( dat, "tiff" );
dt:Image = img;
Close( dt, Save("test.jmp", "jmp");

Problem is that the file test.jmp is huge.  However, if I can convert the image from a tiff to a jpeg, the resulting jmp table is considerably smaller (and I can live with the quality limitations).  But the only way I can see to do this is to save the image as a .jpg file, and then read it back in.  

dt = New Table( "test", New Column( "Image", Expression ) );
dt << Add Rows( 1 );

za = Open( "tif_library", "zip" );
dat = za << Read( "tif_file_n.tif", Format( blob ) );
img = New Image( dat, "tiff" );
img << Save Image( "temp.jpg", "jpeg");
img1 = New Image( "temp.jpg" );
dt:Image = img1;

Close( dt, Save("test.jmp", "jmp");

Is there a simple way to do this in JMP without having to write to file and read it back in?  Thank you for your sage advice!

1 REPLY 1
Craige_Hales
Super User

Re: Image Conversion from TIFF to JPEG Within JMP?

As you've noticed, JMP tries to avoid recompressing image files by keeping the original version of the file. JMP will probably keep a PNG representation rather than a JPG if JMP can't determine the original format. Depending on what the TIFF actually contains, PNG might be what you need, or good enough. You can do this without using an intermediate disk file, like this:

dt = New Table( "test", New Column( "Image", Expression ) );
dt << Add Rows( 1 );

// no tiff handy, but like this:
img = open("C:\Users\chales\Pictures\after.jpg","jpg");

//dt:Image = img;
img<<scale(.25); // reducing size helps too
dt:Image = newimage(img<<getpixels);

Close( dt, Save("$temp\test.jmp", "jmp"));
show(filesize("$temp\test.jmp"));

<<getpixels returns a matrix of pixel colors, and newimage() makes an image from those pixels. The original file type (JPG in this case) is not carried forward.

PNG is a lossless, compressed format that is particulary suited to images like the graphs JMP creates (with hard edges). JPG is a lossy compression suitable for real world camera images with softer edges. TIFF files can hold many formats, including uncompressed raw pixel formats that are huge. In my example above, "after.jpg" was a large camera picture that got much bigger as a png. You may prefer your existing approach.

Craige