问题描述
使用菜单中的“另存显示为”功能可以轻松地将假彩色图像保存为BMP或JPG。但它无法将图像堆栈保存为具有显示颜色的分离图像。 “另存显示为”仅保存堆栈的正面图像。我无法点击数百次来保存整个堆栈!但是我在dm手册中没有找到对应的脚本函数。如何实现?
解决方法
您要查找的命令是 ImageDisplayGetExportImage()
并且实际上有一个
最新 GMS 的 F1 帮助文档中的示例脚本:
但是命令 - 与菜单项相同 - 只会作用于实际显示,因此您仍然需要使用 ImageDisplaySetDisplayedLayers()
因此您的脚本将类似于以下示例:
image test:=RealImage("Stack",4,100,10)
test=sin(icol/iwidth*Pi()*2) * cos(itheta*iplane)
test.ShowImage()
imagedisplay disp = test.ImageGetImageDisplay(0)
disp.ImageDisplaySetColorTableByName("Rainbow")
number nz = test.ImageGetDimensionSize(2)
for( number z=0; z<nz; z++){
disp.ImageDisplaySetDisplayedLayers(z,z)
imageDisplay newdisp
image asDisplayedRGB := disp.ImageDisplayGetExportImage( 7,newdisp )
asDisplayedRGB.SetName( test.GetName() + "_" + z )
asDisplayedRGB.ShowImage()
}
EGUPerformActionWithAllShownImages("arrange")
,
我希望这就是你要找的。显示的脚本允许您将当前工作区中的所有图像保存到一个目录中。您可以指定格式、目录和名称模式。 (它比我预期的要长一点):
TagGroup formats = NewTagGroup();
formats.TagGroupSetTagAsString("Gatan Format","dm4");
formats.TagGroupSetTagAsString("Gatan 3 Format","dm3");
formats.TagGroupSetTagAsString("GIF Format","gif");
formats.TagGroupSetTagAsString("BMP Format","bmp");
formats.TagGroupSetTagAsString("JPEG/JFIF Format","jpg");
formats.TagGroupSetTagAsString("Enhanced Metafile Format","emf");
formats.TagGroupSetTagAsString("TIFF Format","tif");
formats.TagGroupSetTagAsString("PCX Format","pcx");
class FormatDialog : UIFrame{
TagGroup format_select;
number FormatDialogGetSelectedFormat(object self){
if(format_select.TagGroupIsValid()){
return format_select.DLGGetValue();
}
else{
return -1;
}
}
object init(object self){
TagGroup dlg,dlg_items;
dlg = DLGCreateDialog("Select the format",dlg_items);
dlg_items.DLGAddElement(DLGCreateLabel("Please select the export format"));
format_select = DLGCreateChoice(0);
format_select.DLGIdentifier("format_select");
for(number i = 0; i < formats.TagGroupCountTags(); i++){
string text;
formats.TagGroupGetIndexedTagAsString(i,text);
text = formats.TagGroupGetTagLabel(i) + " (" + text + ")";
format_select.DLGAddChoiceItemEntry(text);
}
dlg_items.DLGAddElement(format_select);
self.super.init(dlg);
return self;
}
}
object format_dialog = alloc(FormatDialog).init();
if(format_dialog.pose()){
number format = format_dialog.FormatDialogGetSelectedFormat();
if(format < 0 || format >= formats.TagGroupCountTags()){
throw("Invalid format is selected");
}
string save_format = formats.TagGroupGetTagLabel(format);
string save_extension;
formats.TagGroupGetIndexedTagAsString(format,save_extension);
string save_dir;
if(GetDirectoryDialog("Please select the path to save to",GetApplicationDirectory("open_save",1),save_dir)){
string save_name;
if(GetString("Please set the file name (without extension). A number will be added to the end automatically.","file_",save_name)){
for(number i = 0; i < CountImageDocuments(); i++){
ImageDocument doc = GetImageDocument(i);
doc.ImageDocumentSaveToFile(save_format,PathConcatenate(save_dir,save_name + i + "." + save_extension));
}
OKDialog("Saved " + CountImageDocuments() + " files.");
}
}
}
请注意,您可以将其添加到 DigitalMicrograph 的菜单中。将发布的代码保存为文件,然后使用 File > Install Script File 并将脚本添加到任何现有菜单或新菜单中。