-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathELN_Saver.ijm
69 lines (68 loc) · 2.33 KB
/
ELN_Saver.ijm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
* Macro to save a "small" version of the top window to
* the desktop for use in an electronic lab notebook.
* This is the first version - expect bugs!
*/
macro "Make Version For ELN" {
if (nImages < 1) exit ("I need an image to do this.");
setBatchMode(true);
title1 = getTitle();
dir1 = getDirectory("image");
id1 = getImageID();
dir2 = getDirectory("home")+"Desktop"+File.separator+"ELNoutput"+File.separator;
// make this directory on the desktop if it doesn't already exist
File.makeDirectory(dir2);
// width, height, channels, slices, frames
getDimensions(ww, hh, cc, ss, ff);
slice1 = getSliceNumber();
TimeString = getTimeDate();
// duplicate window
if(ss > 1 || ff > 1) {
//run("Duplicate...", "title=elnout duplicate range=1-" + ff); // possibility to add movie option here
run("Duplicate...", "title=elnout");
} else {
run("Duplicate...", "title=elnout");
}
id2 = getImageID();
// do something about size
if(ww > 2000 || hh > 2000) {
wFactor = -floor(-ww / 2000);
hFactor = -floor(-hh / 2000);
allFactor = maxOf(2,maxOf(wFactor,hFactor)); // at least do 50%
run("Size...", "width=" + round(ww / allFactor) + " height=" + round(hh / allFactor) + " depth=1 constrain average interpolation=Bilinear");
}
// downsample if necessary
if (bitDepth==24)
run("8-bit Color", "number=256");
else
run("8-bit");
newName = TimeString + ".png";
saveAs("png",dir2+newName);
close();
// record what happened
print("\\Clear");
print(title1 + " from " + dir1 + "\rexported as " + TimeString);
selectWindow("Log");
saveAs("text", dir2+newName+"_note.txt");
setBatchMode(false);
}
function getTimeDate() {
// Make unique filename.
// ISO 8601 with no special characters is
// YYYYMMDDTHHMMSSZ e.g. 20170630T193338Z
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec);
TimeString = "UTC"+year;
if (month<10) {TimeString = TimeString+"0";}
TimeString = TimeString+month;
if (dayOfMonth<10) {TimeString = TimeString+"0";}
TimeString = TimeString+dayOfMonth;
if (hour<10) {TimeString = TimeString+"0";}
TimeString = TimeString+"T"+hour;
if (minute<10) {TimeString = TimeString+"0";}
TimeString = TimeString+minute;
if (second<10) {TimeString = TimeString+"0";}
TimeString = TimeString+second+"Z";
TimeString = replace(TimeString,"UTC","");
//showMessage(TimeString);
return TimeString;
}