我正在从三个频道.svs图像中读取裁剪区域并将作物保存为.tiff图像。目前,图像使用单独的RGB通道进行保存。
我以这种方式裁剪图像:
var path = currentFolder + "images" + File.separator + imageName;
var options = new ImporterOptions();
options.setId(path);
options.setAutoscale(true);
options.setCrop(true);
options.setCropRegion(0, new Region(X, Y, deltaX, deltaY));
options.setColorMode(ImporterOptions.COLOR_MODE_COMPOSITE);
var croppedImage= new ImagePlus();
croppedImage= BF.openImagePlus(options);
print("cropped image class: " + croppedImage.getClass());
给出
cropped image class: class [Lij.ImagePlus;
然后我保存图像:
IJ.saveAs(cropedImage, "tif", outputFileName);
我最终获得了三个频道图像。
我想合并频道。
我发现了两种可能的方法:
http://javadoc.imagej.net/ImageJ1/ij/plugin/RGBStackMerge.html
http://rsb.info.nih.gov/ij/developer/api/ij/ImagePlus.html#flatten--
我尝试了croppedImage.flatten()
并得到了:
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Java class "[Lij.ImagePlus;" has no public instance field or method named "flatten".
我也尝试导入RGBStackMerge
类:
importClass(Packages.ij.plugin.RGBStackMerge);
并且正在做
finalImage = new ImagePlus();
finalImage = RGBStackMerge.mergeChannels(croppedImage, false);
print ("final image class: " + finalImage.getClass() + " length: " + finalImage.length);
但是这给了:
Started svs_to_cropped_tiffs.js at Fri Jan 22 22:58:10 PST 2016 javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: TypeError: Cannot call method "getClass" of null
答案 0 :(得分:2)
static ImagePlus[] openImagePlus(ImporterOptions options)
BF.openImagePlus()
会返回ImagePlus
个[L
个对象的数组(由getClass()
输出中的croppedImage[0]
表示)。
您应该通过访问返回数组的第一个元素来访问您的图像:finalImage = croppedImage[0].flatten();
您建议的两种方法都应该适用:
finalImage = RGBStackMerge.mergeChannels(croppedImage[0], false);
或
procedure RunFileAsAdminWait(hWnd: hWnd; aFile, aParameters: string);
var
sei: TShellExecuteInfo;
msg: tagmsg;
begin
FillChar(sei, SizeOf(sei), 0);
sei.cbSize := SizeOf(sei);
sei.Wnd := hWnd;
sei.fMask := SEE_MASK_FLAG_NO_UI or SEE_MASK_NOCLOSEPROCESS;
sei.lpVerb := 'runas';
sei.lpFile := PChar(aFile);
sei.lpParameters := PChar(aParameters);
sei.nShow := SW_SHOWNORMAL;
if ShellExecuteEx(@sei) then
begin
while MsgWaitForMultipleObjects(1, sei.hProcess, False, INFINITE, QS_ALLINPUT) <> WAIT_OBJECT_0 do
while PeekMessage(msg, 0, 0, 0, PM_REMOVE) do
DispatchMessage(msg);
CloseHandle(sei.hProcess);
end;
end;
您可以在ImageJ wiki的Scripting toolbox页面上找到示例如何使用Bio-Formats打开图像。