def copyMatrixToImage2D(matrix,imageName,sizeX = -1,sizeY = -1): if sizeX == -1: sizeX = len(matrix) if sizeY == -1: sizeY = len(matrix[0]) imp = ImageStack.create(sizeX, sizeY, 1,16) processor = imp.getProcessor(1) for indexX in range(sizeX): for indexY in range(sizeY): processor.set(indexX,indexY,int(matrix[indexX][indexY])) ImagePlus(imageName, imp).show()
def run(imagefile, verbose=False): # open image file and get a specific series log.log(LogLevel.INFO, 'Opening Image: ' + imagefile) imp, MetaInfo = ImportTools.openfile(imagefile) # output of image metadata in log window if verbose: for k, v in MetaInfo.items(): log.log(LogLevel.INFO, str(k) + ' : ' + str(v)) log.log(LogLevel.INFO, 'File Extension : ' + MetaInfo['Extension']) if 'ResolutionCount' in MetaInfo: log.log(LogLevel.INFO, 'Resolution Count : ' + str(MetaInfo['ResolutionCount'])) if 'SeriesCount' in MetaInfo: log.log(LogLevel.INFO, 'SeriesCount : ' + str(MetaInfo['SeriesCount'])) if 'SizeC' in MetaInfo: log.log(LogLevel.INFO, 'Channel Count : ' + str(MetaInfo['SizeC'])) # do the processing log.log(LogLevel.INFO, 'Start Processing ...') # create empty image list imglist_t_c = [] imglist_t = [] numch = imp.getNChannels() # do the processing for t in range(MetaInfo['SizeT']): # get the timepoint imp_t = getstackfrom5d(imp, MetaInfo, firstC=1, lastC=MetaInfo['SizeC'], firstZ=1, lastZ=MetaInfo['SizeZ'], firstT=t + 1, lastT=t + 1) # calc the focus values for the different channels for ch in range(numch): # get a stack for a channel imp_t_c = getstackfrom5d(imp_t, MetaInfo, firstC=ch + 1, lastC=ch + 1, firstZ=1, lastZ=MetaInfo['SizeZ'], firstT=1, lastT=1) # create a name for the plane #name = os.path.basename(imagefile) + 'T=' + str(t+1) + '_CH=' + str(ch+1) name = 'T=' + str(t + 1) + '_CH=' + str(ch + 1) # get the plane with the bst focus to the current timepoint and current channel sp_c, fv, fv_max, fv_max_index = calc_focus(imp_t_c, name) log.log(LogLevel.INFO, 'Processing TimePoint : ' + str(t + 1)) log.log(LogLevel.INFO, 'Processing Channel : ' + str(ch + 1)) log.log(LogLevel.INFO, 'Max. Value : ' + str(fv_max)) log.log(LogLevel.INFO, 'Max. Value Slice : ' + str(fv_max_index)) # set correct image properties sp_c = MiscTools.setproperties(sp_c, scaleX=MetaInfo['ScaleX'], scaleY=MetaInfo['ScaleY'], scaleZ=MetaInfo['ScaleZ'], unit='micron', sizeC=1, sizeZ=1, sizeT=1) imglist_t_c.append(sp_c) print 'List CH Stacks :', len(imglist_t_c) for i in range(len(imglist_t_c)): print str(i) + ' : ', type(imglist_t_c[i]) # in case of more than one channel use an jarray if numch > 1: # create an array imgarray_c = jarray.array(imglist_t_c, ImagePlus) # create an ImageStack from the array print 'Type imgarray_c : ', type(imgarray_c) for i in range(numch): print type(imgarray_c[i]) imgstack_c = ImageStack.create(imgarray_c) # create an ImagePlus object from the jarray new_name = os.path.splitext(os.path.basename(imagefile))[0] imp_sp_c = ImagePlus(new_name + '_SHARPEST_C', imgstack_c) # in case of exactly one channel directly use the ImgPlus if numch == 1: imp_sp_c = imglist_t_c[0] # set correct image properties for the final image imp_sp_c = MiscTools.setproperties(imp_sp_c, scaleX=MetaInfo['ScaleX'], scaleY=MetaInfo['ScaleY'], scaleZ=MetaInfo['ScaleZ'], unit='micron', sizeC=numch, sizeZ=1, sizeT=1) # concatenate the timepoints imglist_t.append(imp_sp_c) if numch > 1: # create an array imgarray = jarray.array(imglist_t, ImagePlus) # create an ImageStack from the array imgstack = ImageStack.create(imgarray) # create an ImagePlus object from the jarray new_name = os.path.splitext(os.path.basename(imagefile))[0] imp_sp_t = ImagePlus(new_name + '_SHARPEST_CT', imgstack) # in case of exactly one channel directly use the ImgPlus if numch == 1: imp_sp_t = imglist_t[0] return imp_sp_t
nucIp, cmIp = openStitched(group, rowNo, colNo) if stitched else openUnstitched(group) if nucIp is None or cmIp is None: continue nucStack, cmStack = nucIp.getStack(), cmIp.getStack() nucIpMedian = calcMedian(nucIp) IJ.run(nucIp, "Subtract...", "value=" + str(nucIpMedian) + " stack") nucIpForMeasure = nucIp.duplicate() nucMaskIp = generateNucleusMask(nucIp, nucMethod, analyzeNucStack, nucMinSize) cmIp, cmMaskIp = generateCardiomyocyteMask(cmIp, cmMethod, analyzeCmStack, cmMinSize, brightfield) nucMaskIp.show() nucIpForMeasure.show() rm = RoiManager.getRoiManager() rm.runCommand("Associate", "true") rm.runCommand("Show All without labels") #This fits ellipses to the nuclear mask IJ.run(nucMaskIp, "Ellipse Split", "binary=[Use standard watershed] add_to_manager add_to_results_table merge_when_relativ_overlap_larger_than_threshold overlap=95 major=0-Infinity minor=0-Infinity aspect=1-Infinity stack") nucMaskStack2 = ImageStack.create(nucIp.width, nucIp.height, nucStack.size(), cmStack.getProcessor(1).getBitDepth()) rois = rm.getRoisAsArray() #This loop is used to setup an image for the voronoi diagram nucelar splitting, setting pixels which #are contested between two neighboring nuclei to 0 for roi in rois: z = roi.getZPosition()- 1 try: for p in roi.getContainedPoints(): try: val = nucMaskStack2.getVoxel(p.x, p.y, z) if val == 1: pass elif val == 2: nucMaskStack2.setVoxel(p.x, p.y, z, 1) else: nucMaskStack2.setVoxel(p.x, p.y, z, 2) except: pass except: pass
def run(imagefile, verbose=False): # open image file and get a specific series log.log(LogLevel.INFO, 'Opening Image: ' + imagefile) imp, MetaInfo = ImportTools.openfile(imagefile) # output of image metadata in log window if verbose: for k, v in MetaInfo.items(): log.log(LogLevel.INFO, str(k) + ' : ' + str(v)) log.log(LogLevel.INFO, 'File Extension : ' + MetaInfo['Extension']) if 'ResolutionCount' in MetaInfo: log.log(LogLevel.INFO, 'Resolution Count : ' + str(MetaInfo['ResolutionCount'])) if 'SeriesCount' in MetaInfo: log.log(LogLevel.INFO, 'SeriesCount : ' + str(MetaInfo['SeriesCount'])) if 'SizeC' in MetaInfo: log.log(LogLevel.INFO, 'Channel Count : ' + str(MetaInfo['SizeC'])) # do the processing log.log(LogLevel.INFO, 'Start Processing ...') # create empty image list imglist = [] numch = imp.getNChannels() # do the processing for ch in range(numch): # get a channel imp_c = MiscTools.splitchannel(imp, ch) name = os.path.basename(imagefile) + '_CH=' + str(ch) sp, fv, fv_max, fv_max_index = calc_focus(imp_c, name) log.log(LogLevel.INFO, 'Processing Channel : ' + str(ch)) log.log(LogLevel.INFO, 'Max. Value : ' + str(fv_max)) log.log(LogLevel.INFO, 'Max. Value Slice : ' + str(fv_max_index)) # set correct image properties sp = MiscTools.setproperties(sp, scaleX=MetaInfo['ScaleX'], scaleY=MetaInfo['ScaleY'], scaleZ=MetaInfo['ScaleZ'], unit='micron', sizeC=1, sizeZ=1, sizeT=1) imglist.append(sp) # in case of more than one channel use an jarray if numch > 1: # create an array imgarray = jarray.array(imglist, ImagePlus) # create an ImageStack from the array imgstack = ImageStack.create(imgarray) # create an ImagePlus object from the jarray new_name = os.path.splitext(os.path.basename(imagefile))[0] imp_sp = ImagePlus(new_name + '_SHARPEST', imgstack) # ic case of exactly one channel directly use the ImgPlus if numch == 1: imp_sp = imglist[0] # set correct image properties for the final image imp_sp = MiscTools.setproperties(imp_sp, scaleX=MetaInfo['ScaleX'], scaleY=MetaInfo['ScaleY'], scaleZ=MetaInfo['ScaleZ'], unit='micron', sizeC=numch, sizeZ=1, sizeT=1) return imp_sp
num_window_x = int(round(width/width_sub)) #int(width-width_sub+1) num_window_y = int(round(height/width_sub)) #int(height-width_sub+1) center_px = int(round(width_sub/2)) new_rois = [] for i in range(0,num_window_x): for j in range(0,num_window_y): new_roi = Roi(i*width_sub, j*width_sub, width_sub, width_sub) new_rois.append(new_roi) for new_roi in new_rois: rm.addRoi(new_roi) #new_img = IJ.createHyperStack("Time Correlation",width,height,1,1,num_frames, 32) result_stack = ImageStack.create(width,height, max_cycle_length, 32) #empty = imp2.getProcessor().createProcessor(width, height) #for i in range(max_cycle_length): #result_stack.addSlice("",empty) for i, roi in enumerate(rm.getRoisAsArray()): assert roi.getTypeAsString() == 'Rectangle', "ROI needs to be a rectangle" x_pos = roi.getPolygon().xpoints[0] + int(round(width_sub/2)) y_pos = roi.getPolygon().ypoints[0] + int(round(width_sub/2)) imp3 = imp2.duplicate() imp3.show() #imp3 = IJ.getImage() imp3.setRoi(roi) IJ.run(imp3, "Crop", "")