Login  Register

Re: Importing SEM images with scale

Posted by Pablo Manuel Jais on Dec 29, 2009; 10:50pm
URL: http://imagej.273.s1.nabble.com/Importing-SEM-images-with-scale-tp3689900p3689901.html

Well, thanks Wayne and Gabriel for your answers!
I put together a macro that sets the scale automatically using the
tiff_dumper plugin. In case it's of any use, I'm pasting it here.
  Happy holidays!
    Pablo

//This very simple macro sets the scale for SEM images taken with the Carl
//Zeiss SmartSEM program. It requires the tiff_tags plugin written by
//Joachim Wesner. It can be downloaded from
// http://rsbweb.nih.gov/ij/plugins/tiff-tags.html

//This is the number of the VERY long tag that stores
//all the SEM information
tagnum=34118;

//Gets the path+name of the active image
path = getDirectory("image");
if (path=="") exit ("path not available");
name = getInfo("image.filename");
if (name=="") exit ("name not available");
path = path + name;

//Gets the tag, and parses it to get the pixel size information
tag = call("TIFF_Tags.getTag", path, tagnum);
i0 = indexOf(tag, "Image Pixel Size = ");
if (i0==-1) exit ("Scale information not found");
i1 = indexOf(tag, "=", i0);
i2 = indexOf(tag, "AP", i1);
if (i1==-1 || i2==-1 || i2 <= i1+4)
    exit ("Parsing error! Maybe the file structure changed?");
text = substring(tag,i1+2,i2-2);

//Splits the pixel size in number+unit
//and sets the scale of the active image
tokens=split(text);
run("Set Scale...", "distance=1 known="+tokens[0]+" pixel=1
unit="+tokens[1]);


> Hi Pablo,
>
> Extracting metadata is something the Bio-Formats plugin is usually good at
> but your sample TIFF causes it to crash. You should probably send the
> Bio-Formats group a copy of the file so they can fix the bug.
> Surprisingly, the TIFF_Dumper plugin
> (http://rsbweb.nih.gov/ij/plugins/tiff-dumper.html), which uses the
> Bio-Formats plugin as a library, is able to read the contents of the 34118
> TIFF tag that seems to contain the metadata (attached).
>
> Best regards,
>
> -wayne
>
>
> On Dec 28, 2009, at 12:12 PM, Pablo Manuel Jais wrote:
>
>> Hi everyone!
>>
>> This might have been asked already, but I couldn't find anything in the
>> list archives. I have several images from a Carl Zeiss SEM, that I have
>> to
>> import to process. The images have the scale information embedded so I'd
>> like to know what's the easiest way to automatically set the scale when
>> loading the images.
>>
>> I know they have the scale because I can do
>> $ grep -ai pixel Q30_cm4937.tif
>> DP_PIXEL_SIZE
>> AP_PIXEL_SIZE
>> Pixel Size = 1.5 nm
>> AP_IMAGE_PIXEL_SIZE
>> Image Pixel Size = 1.5 nm
>>
>> Is there a plugin/macro that I can tweak to do that? I checked the
>> Bioformats format list, but I didn't see this one there. Any tips are
>> welcome! In case it's useful, you can download a sample image from
>> http://ib.cnea.gov.ar/~jaisp/sample.tif
>>
>> Thank you very much,
>>  Pablo
>
>