def save_shifts(shifts, roi): sd = SaveDialog('please select shift file for saving', 'shifts', '.txt') fp = os.path.join(sd.getDirectory(),sd.getFileName()) f = open(fp, 'w') txt = [] txt.append("ROI zero-based") txt.append("\nx_min\ty_min\tz_min\tx_max\ty_max\tz_max") txt.append("\n"+str(roi[0])+"\t"+str(roi[1])+"\t"+str(roi[2])+"\t"+str(roi[3])+"\t"+str(roi[4])+"\t"+str(roi[5])) txt.append("\nShifts") txt.append("\ndx\tdy\tdz") for shift in shifts: txt.append("\n"+str(shift.x)+"\t"+str(shift.y)+"\t"+str(shift.z)) f.writelines(txt) f.close()
def save_shifts(shifts, roi): sd = SaveDialog('please select shift file for saving', 'shifts', '.txt') fp = os.path.join(sd.getDirectory(),sd.getFileName()) f = open(fp, 'w') txt = [] txt.append("ROI zero-based") txt.append("\nx_min\ty_min\tz_min\tx_max\ty_max\tz_max") txt.append("\n"+str(roi[0])+"\t"+str(roi[1])+"\t"+str(roi[2])+"\t"+str(roi[3])+"\t"+str(roi[4])+"\t"+str(roi[5])) txt.append("\nShifts") txt.append("\ndx\tdy\tdz") for shift in shifts: txt.append("\n"+str(shift.x)+"\t"+str(shift.y)+"\t"+str(shift.z)) f.writelines(txt) f.close()
def doSomething(keyEvent): """ A function to react to key being pressed on an image canvas. """ global iROI, xlist, ylist, zlist, power, profileType, duration, Nturns, hOffset, camTriggerEvery, zStart, zStep, prewait print "clicked keyCode " + str(keyEvent.getKeyCode()) if keyEvent.getKeyCode() == 10: # Enter is pressed! sd = SaveDialog('Save ROIs', '.', 'Eprofile', '.txt') directory = sd.getDirectory() filename = sd.getFileName() filepath = directory + filename print filepath f = open(filepath, 'w') for i in range(len(xlist)): f.write('ENTRY_START\n') f.write('ABLATION(OFF,200.0)\n') f.write('PRE_WAIT(' + str(prewait) + ')\n') f.write('PRE_TRIGGER(OFF,5000,CONTINUE)\n') f.write('COORDINATES(' + str(xlist[i]) + ',' + str(hOffset + ylist[i]) + ',' + str(zStart + (zlist[i] - 1) * zStep) + ')\n') if (profileType == 'point'): f.write('SCAN_TYPE(POINT)\n') if (profileType == 'circle'): f.write('SCAN_TYPE(CIRCLE,' + str(radius) + ',' + str(round(duration / Nturns)) + ')\n') if (profileType == 'spiral'): f.write('SCAN_TYPE(SPIRAL,' + str(radius) + ',' + str(duration) + ',0,' + str(Nturns) + ')\n') f.write('POWER(' + str(power) + ')\n') f.write('DURATION(' + str(duration) + ')\n') f.write('POST_TRIGGER(OFF,0, CONTINUE)\n') f.write('CAMERA_TRIGGER\n') f.write('ENTRY_END\n\n') f.close() manager.runCommand('Save', directory + filename + '.zip') if keyEvent.getKeyCode() == 27: # Esc is pressed! reset() #if keyEvent.getKeyCode() == 127: # DEL is pressed! # killIt = true # return # Prevent further propagation of the key event: keyEvent.consume()
def doSomething(keyEvent): """ A function to react to key being pressed on an image canvas. """ global iROI, xlist, ylist, zlist, power, profileType, duration, Nturns, camTriggerEvery, zStart, zStep, prewait, xOffset, yOffset, tmIndex if keyEvent.getKeyCode() == 10: # Enter is pressed! sd = SaveDialog('Save ROIs', '.', 'Eprofile', '.txt') directory = sd.getDirectory() filename = sd.getFileName() filepath = directory + filename f = open(filepath, 'w') f.write('<zStart units="um">' + str(zStart) + '</zStart>\n') f.write('<zStep units="um">' + str(zStep) + '</zStep>\n') f.write('<xOffset units="px">' + str(xOffset) + '</xOffset>\n') f.write('<yOffset units="px">' + str(yOffset) + '</yOffset>\n') f.write('<radiusROI units="px">' + str(radius) + '</radiusROI>\n\n') for i in range(len(xlist)): f.write('#cell num:' + str(i) + '\n') f.write('ENTRY_START\n') f.write('PRE_WAIT(' + str(prewait) + ')\n') f.write('TM_INDEX(' + str(tmIndex) + ')\n') f.write('COORDINATES(' + str(xOffset + xlist[i]) + ',' + str(yOffset + ylist[i]) + ',' + str(zStart + (zlist[i] - 1) * zStep) + ')\n') if (profileType == 'point'): f.write('SCAN_TYPE(POINT)\n') if (profileType == 'circle'): f.write('SCAN_TYPE(CIRCLE,' + str(radius) + ',' + str(round(duration / Nturns)) + ')\n') if (profileType == 'spiral'): f.write('SCAN_TYPE(SPIRAL,' + str(radius) + ',' + str(duration) + ',0,' + str(Nturns) + ')\n') f.write('POWER(' + str(power) + ')\n') f.write('DURATION(' + str(duration) + ')\n') # f.write('POST_TRIGGER(OFF,0, CONTINUE)\n') #never used f.write('CAMERA_TRIGGER\n') f.write('ENTRY_END\n\n') f.close() manager.runCommand('Save', directory + filename + '.zip') if keyEvent.getKeyCode() == 27: # Esc is pressed! reset() keyEvent.consume()
#run("Save"); #run ("Jpeg..."); from ij.plugin.frame import RoiManager from ij import IJ from ij.io import SaveDialog from ij.io import RoiEncoder from ij.io import RoiDecoder rm = RoiManager.getInstance() imp = IJ.getImage() roi = imp.getRoi() rm.addRoi(roi) sd = SaveDialog("specify", IJ.getDirectory("image"), ".roi") path = sd.getDirectory() + sd.getFileName() RoiEncoder.save(roi, path)
x5x = dialog.getNextNumber(); y5x = dialog.getNextNumber(); w5x = dialog.getNextNumber(); h5x = dialog.getNextNumber(); activation_overlay_data.setRoi((x5x,y5x,w5x,h5x)); offsetx = dialog.getNextNumber(); offsety = dialog.getNextNumber(); activation_overlay_data.setLowMagOffsetXY((offsetx,offsety)); panx = dialog.getNextNumber(); pany = dialog.getNextNumber(); activation_overlay_data.setPanUmXY((panx,pany)); interval = dialog.getNextNumber(); activation_overlay_data.setFrameIntervalS(interval); roi = activation_overlay_data.generateOverlayRoi(imp); imp.setRoi(roi); IJ.run(imp, "RGB Color", ""); IJ.run("Colors...", "foreground=cyan background=white selection=yellow"); IJ.run("Draw", "stack"); sd = SaveDialog("Save as AVI...", os.path.splitext(imp.getTitle())[0], ".avi"); if sd.getFileName is not None: activation_overlay_data.save_to_json(os.path.join(sd.getDirectory(), os.path.splitext(os.path.basename(sd.getFileName()))[0] + " metadata.json")); IJ.saveAs(imp, "Tiff", os.path.join(sd.getDirectory(), os.path.splitext(os.path.basename(sd.getFileName()))[0] + " + ROI, no timestamp.tif")); IJ.run(imp, "Label...", "format=00:00:00 starting=0 interval=" + str(interval) + " x=5 y=20 font=18 text=[] range=1-"+str(imp.getNFrames())); IJ.run(imp, "AVI... ", "compression=None frame=10 save=[" + os.path.join(sd.getDirectory(), sd.getFileName()) + "]"); IJ.saveAs(imp, "Tiff", os.path.join(sd.getDirectory(), os.path.splitext(os.path.basename(sd.getFileName()))[0] + " + ROI.tif"));
def main(): metadatas = [] runagain = True offsetx = 0 offsety = 0 interval = 50.0 IJ.run(imp, "RGB Color", "") IJ.run("Colors...", "foreground=cyan background=white selection=yellow") while runagain: dialog = GenericDialog("Define 5x ROI parameters...") dialog.enableYesNoCancel("Continue and quit", "Continue and add another line") dialog.addNumericField("Line scan position 1 X, Y: ", 0, 0) dialog.addToSameRow() dialog.addNumericField(", ", 0, 0) dialog.addNumericField("Line scan position 2 X, Y: ", 0, 0) dialog.addToSameRow() dialog.addNumericField(", ", 0, 0) dialog.addNumericField("Reference image crop origin X, Y: ", offsetx, 0) dialog.addToSameRow() dialog.addNumericField(", ", offsety, 0) dialog.addNumericField("Frame interval (s): ", interval, 2) dialog.showDialog() p1x = dialog.getNextNumber() p1y = dialog.getNextNumber() p2x = dialog.getNextNumber() p2y = dialog.getNextNumber() offsetx = dialog.getNextNumber() offsety = dialog.getNextNumber() interval = dialog.getNextNumber() linescan_overlay = LineScanOverlayMetadata( (p1x, p1y), (p2x, p2y), (offsetx, offsety), interval) metadatas.append(linescan_overlay) roi = linescan_overlay.generateOverlayRoi() imp.setRoi(roi) IJ.run("Draw", "stack") if dialog.wasOKed(): runagain = False elif dialog.wasCanceled(): return sd = SaveDialog("Save as AVI...", os.path.splitext(imp.getTitle())[0], "line scan overlay.avi") if sd.getFileName is not None: metadatas[0].save_to_json( os.path.join( sd.getDirectory(), os.path.splitext(os.path.basename(sd.getFileName()))[0] + "line scan metadata.json")) if len( metadatas ) > 1: # append: multiple writes=slow, but easiest way based on existing framework for midx in range(1, len(metadatas)): metadatas[midx].save_to_json(os.path.join( sd.getDirectory(), os.path.splitext(os.path.basename(sd.getFileName()))[0] + "line scan metadata.json"), append=True) IJ.saveAs( imp, "Tiff", os.path.join( sd.getDirectory(), os.path.splitext(os.path.basename(sd.getFileName()))[0] + " + line scan ROI, no timestamp.tif")) IJ.run( imp, "Label...", "format=00:00:00 starting=0 interval=" + str(interval) + " x=5 y=20 font=18 text=[] range=1-" + str(imp.getNFrames())) IJ.run( imp, "AVI... ", "compression=None frame=10 save=[" + os.path.join(sd.getDirectory(), (os.path.splitext(sd.getFileName())[0] + " + line scan ROI.avi")) + "]") IJ.saveAs( imp, "Tiff", os.path.join( sd.getDirectory(), os.path.splitext(os.path.basename(sd.getFileName()))[0] + " + line scan ROI.tif"))
#run("Save"); #run ("Jpeg..."); from ij.plugin.frame import RoiManager from ij import IJ from ij.io import SaveDialog from ij.io import RoiEncoder from ij.io import RoiDecoder rm = RoiManager.getInstance() imp = IJ.getImage(); roi = imp.getRoi(); rm.addRoi(roi); sd = SaveDialog("specify", IJ.getDirectory("image"), ".zip"); index = rm.getCount()-1; path = sd.getDirectory() + sd.getFileName(); name = sd.getFileName(); rm.rename(index, name[0:-4]); rm.deselect() ; rm.runCommand("Save", path) #ok = RoiEncoder.save(roi, path);
from ij import IJ from ij.io import SaveDialog from ij.gui import WaitForUserDialog theImage = IJ.getImage() ip = theImage.getProcessor() sd = SaveDialog("Select file to save results","injury",".csv") saveFileName = sd.getFileName() saveFileDir = sd.getDirectory() if (saveFileName is not None): saveFilePath = saveFileDir + saveFileName savefilehandler = open(saveFilePath,"w") waitDialog = WaitForUserDialog("Use freeform tool to outline the piece of tissue") waitDialog.show() roi = theImage.getRoi() if (roi is not None): print type(roi) thePolygon = roi.getPolygon() boundRect = thePolygon.getBounds() for i in range(boundRect.x,boundRect.x+boundRect.width): pos_pixels = 0 tot_pixels = 0 IJ.showProgress(i-boundRect.x,boundRect.width) for j in range(boundRect.y,boundRect.y+boundRect.height): if thePolygon.contains(i,j): value = ip.getPixelValue(i,j) tot_pixels = tot_pixels + 1
gd = NonBlockingGenericDialog("Clone counter...") gd.addNumericField("Clone:",cloneNum,0) gd.setOKLabel("Finalize clone") gd.setCancelLabel("Quit") gd.showDialog() if (gd.wasOKed()): roi = theImage.getRoi() if (not roi is None): cloneNum = int(gd.getNextNumber()) polygon = roi.getFloatPolygon() for i in range(polygon.npoints): pointList.append(CounterPoint(polygon.xpoints[i],polygon.ypoints[i],cloneNum)) IJ.run("Draw","stack") theImage.deleteRoi() cloneNum = cloneNum + 1 else: stayinloop = False sd = SaveDialog("Save counter file...","",".csv") fileDir = sd.getDirectory() fileName = sd.getFileName() if fileName is not None: filePath = fileDir + fileName fileobj = open(filePath,"w") for item in pointList: fileobj.write(str(item.x)+","+str(item.y)+","+str(item.clonenum)+"\n") fileobj.close()
plot.setColor(Color.BLACK) plot.addPoints(x, y, Plot.LINE) plot.addPoints(x, y, PlotWindow.X) plot.setColor(Color.black) plot_window = plot.show() ############################### # Save data as a json file ############################### # Ask for filename savename_temp = os.path.splitext(stack_title)[0] + '_cell_XX' save_file = SaveDialog('Please choose a location to save results', file_dir, savename_temp, '.json') # Prepare data for export file_info = {'source_file': stack_title, 'source_file_dir': file_dir} roi_info = { 'roi_type': roi_type, 'roi_bounds_pixel': roi_bounds_list, 'roi_area': roi_area } calb = {'pixel_size': calibration.pixelHeight, 'unit': calibration.getXUnit()} data_out = { 'file_info': file_info, 'roi_info': roi_info, 'intensities': intensities, 'calibration': calb