def convertStackToRGB(img): """ Convert individual color layers to a single RGB composite """ try: RGBStackConverter.convertToRGB(img) except: pass return img
def save_qc_image(imp, rois, output_path): """save rois overlaid on imp to output_path""" imp.killRoi() roim = RoiManager(False) for roi in rois: roim.addRoi(roi) roim.runCommand("Show All with labels") RGBStackConverter.convertToRGB(imp) roim.moveRoisToOverlay(imp) FileSaver(imp).saveAsTiff(output_path) roim.runCommand("Show None") roim.close()
def GenerateRGB(imp): channels1 = imp.getNChannels(); slices1 = slices2 = imp.getNSlices(); frames1 = frames2 = imp.getNFrames(); c1 = imp.getChannel(); z1 = imp.getSlice(); t2 = imp.getFrame(); imp2 = imp.createHyperStack("title2", 1, slices2, frames2, 24) RGBStackConverter().convertHyperstack(imp, imp2); # imp2.show() return imp2
impCircles.setDisplayRange(0, 1); IJ.run(impSphereProjection, "8-bit", ""); IJ.run(impCircles, "8-bit", ""); stack = ImageStack(impSphereProjection.getWidth(), impSphereProjection.getHeight()); stack.addSlice(impSphereProjection.getProcessor()); stack.addSlice(impCircles.getProcessor()); tempImp = ImagePlus("Cylinder Maximum Projection + spots", stack); tempImp = HyperStackConverter.toHyperStack(tempImp, 2, 1, 1); if (tempImp.getNChannels() == 2): tempImp.setC(1); IJ.run(tempImp, "Magenta", ""); tempImp.setC(2); tempImp.setDisplayRange(0, 1); RGBStackConverter.convertToRGB(tempImp); if (resultCylinderMaxProjection is None): resultCylinderMaxProjection = tempImp; else: resultCylinderMaxProjection.setProcessor(tempImp.getProcessor()); resultCylinderMaxProjection.show(); resultCylinderMaxProjection.updateAndDraw(); # MIP impMaxProjection = clijx.pull(maxProjection); IJ.run(impMaxProjection, "Enhance Contrast", "saturated=0.35"); if (resultMaxProjection is None): resultMaxProjection = impMaxProjection; resultMaxProjection.setTitle("Maximum Z projection");
_filtered = [threshold(p) for p in chpx[i]] # filtered pixels filtered.append(FloatProcessor(ip.width, ip.height, _filtered, None)) # save each channels for i in range(3): IJ.save(ImagePlus("filtered_%d" % i, filtered[i]), dstpath[:-4] + '_%d' % i) # add slices to new stack stack_new = ImageStack(imp.width, imp.height) for i in range(3): stack_new.addSlice(None, filtered[i]) # new image (stack) imp_new = ImagePlus("new", stack_new) imp_new.show() IJ.save(imp_new, dstpath[:-4] + '_stack.tif') # new image (color) mergeimp = RGBStackMerge.mergeChannels([ ImagePlus(None, filtered[0]), ImagePlus(None, filtered[1]), ImagePlus(None, filtered[2]), None, None, None, None ], False) mergeimp.title = "filtered" RGBStackConverter.convertToRGB(mergeimp) mergeimp.show() IJ.save(mergeimp, dstpath)
# open EM image as ImagePlus for merging channel EM = ImagePlus(saveEMfilepath) # split rLM image in different channels saverLMpath = os.path.join(transformation_output, "rLM.tif") rLM = IJ.openImage(saverLMpath) R, G, B = ChannelSplitter.split(rLM) # Merge channels overlay = RGBStackMerge.mergeChannels( [None, None, B, EM, None, None, None], True) # Change R,G, B if the chromatin channel is a different one. # If you want a different color for the chromatin in the overlay image, change the position of the letter R,G,B, # e.g. [B, None, None, EM, None, None, None] for displaying chromatin in the red channel. RGBStackConverter.convertToRGB(overlay) # save overlay saveoverlaypath = os.path.join(workdir, "overlay_EM_Chromatin.tif") fs = FileSaver(overlay) fs.saveAsTiff(saveoverlaypath) print("(----- )overlay EM and rLM image done") ############################################ clean up # copy important files into the working directory os.remove(os.path.join(workdir, "EM.tif")) shutil.move(os.path.join(transformation_output, "EM.tif"), os.path.join(workdir, "SEM.tif")) shutil.move(os.path.join(transformation_output, "rLM.tif"),
# imRed.show() # imTL.show() # stack=ij.ImageStack(imRed.width, imRed.height) # stack.addSlice("red", imRed.getProcessor()) # stack.addSlice("green", imGreen.getProcessor()) # stack.addSlice("tl", imTL.getProcessor()) # imstack=ij.ImagePlus("Stack", stack) imMerge=RGBStackMerge.mergeChannels([imRed, imGreen, None, imTL], True) #The merged image is a composite with three seperate channels. For now, we just want to convert the thing to RGB and save it out. RGBStackConverter.convertToRGB(imMerge) saveFn=os.path.join(analysisPath, tlFn[-9:-7], 'Merge.jpg' #imMerge.show() if stack==None: stack=Stack("MergedChannels", imMerge) else:fiji stack+=imMerge FileSaver(imMerge).saveAsJpeg(saveFn) stack.show()
---------- --- ---------------------------------------------------- 2019-06-16 JRM Initial adaptation. Use the GIT_HOME environment variable to get the start of the path """ import os from ij import IJ, ImagePlus from ij.plugin import RGBStackMerge, RGBStackConverter # use a path relative to the GIT_HOME environment variable git_home = os.getenv("GIT_HOME") print(git_home) # start clean IJ.run("Close All") # Load the R, G, and B color separation images. These were created # using make_mandrill_256.py impc1 = ImagePlus(git_home + "/tips/ImageJ/tif/mandrill_256_red.tif") impc2 = ImagePlus(git_home + "/tips/ImageJ/tif/mandrill_256_green.tif") impc3 = ImagePlus(git_home + "/tips/ImageJ/tif/mandrill_256_blue.tif") # merge my three images imp_merge = RGBStackMerge.mergeChannels([impc1, impc2, impc3], True) # convert the composite image to the RGB image RGBStackConverter.convertToRGB(imp_merge) imp_merge.show()