示例#1
0
文件: fijipytools.py 项目: soyers/OAD
    def savedata(imp, savepath, extension='ome.tiff', replace=False):

        # general function for saving image data in different formats

        # check if file already exists and delete if replace is true
        if os.path.exists(savepath):
            if replace:
                os.remove(savepath)
            if not replace:
                return None

        # general safety check
        # if not extension:
        #    extension = 'ome.tiff'

        # check extension
        if extension in ['tiff', 'tif', 'ome.tiff', 'ome.tif', 'png', 'jpeg']:

            fs = FileSaver(imp)
            nslices = imp.getStack().getSize()  # get the number of slices

            # in case of TIFF
            if extension == ('tiff' or 'tif' or 'TIFF' or 'TIF'):
                if nslices > 1:
                    fs.saveAsTiffStack(savepath)
                if nslices == 1:
                    fs.saveAsTiff(savepath)

            # in case of OME-TIFF
            elif extension == 'ome.tiff' or extension == 'ome.tif':
                pstr = ExportTools.bfexporter(imp, savepath, useLOCI=True)
                print('BioFormats Paramstring : ', pstr)

            # in case of PNG
            elif extension == ('png' or 'PNG'):
                fs.saveAsPng(savepath)

            # in case
            elif extension == ('jpeg' or 'jpg' or 'JPEG' or 'JPG'):
                fs.saveAsJpeg(savepath)

        else:
            extension = 'ome.tiff'
            print("save as OME-TIFF: ")  # savepath
            pstr = ExportTools.bfexporter(imp, savepath, useLOCI=True)
            print('BioFormats Paramstring : ', pstr)

        return savepath
示例#2
0
def autoProcAZtecImage(fwMicrons, wrkDir, barWid=0.1, barHt=9, barFnt=24, barCol="Black", barLoc="Lower Right"):
	imp = IJ.getImage()
	fName = imp.getShortTitle()
	wid = imp.getWidth()
	argThree = "distance=%g known=%f pixel=1 unit=um" % (wid, fwMicrons)
	IJ.run(imp, "Set Scale...", argThree)
	IJ.run(imp, "Enhance Contrast", "saturated=0.35")
	fs = FileSaver(imp) 
	if path.exists(wrkDir) and path.isdir(wrkDir):
		print "folder exists:", wrkDir
		tifName = fName + ".tif"
		tifPath = path.join(wrkDir, tifName)
		print(tifPath)
		if fs.saveAsTiff(tifPath):
			print "Tif saved successfully at ", tifPath  
				
	IJ.run(imp, "RGB Color", "")
	# dummy to get things set
	foo = imp.duplicate()
	s2 = "width=%g height=%g font=%g color=%s location=[%s] bold" % (barWid, barHt, barFnt, barCol, barLoc)
	IJ.run(foo, "Add Scale Bar", s2)
	# explicitly save preferences
	Prefs.savePreferences()
	foo.changes = False
	foo.close()
	IJ.run(imp, "Add Scale Bar", s2)
	fs = FileSaver(imp) 
	pngName = fName + ".png"
	pngPath = path.join(wrkDir, pngName)
	if fs.saveAsPng(pngPath):
		print "png saved successfully at ", pngPath  
示例#3
0
文件: Utils.py 项目: aryehw/83411
def saveFile(imp, format, outputDirPath):
    fs = FileSaver(imp)
    saveDict = {
        'tif': lambda: fs.saveAsTiff(outputDirPath + imp.getTitle() + ".tif"),
        'zip': lambda: fs.saveAsZip(outputDirPath + imp.getTitle() + ".zip"),
        'png': lambda: fs.saveAsPng(outputDirPath + imp.getTitle() + '.png'),
        'txt': lambda: fs.saveAsTxt(outputDirPath + imp.getTitle() + '.txt'),
        'jpg': lambda: fs.saveAsJpg(outputDirPath + imp.getTitle() + '.jpg')
    }

    saveDict[format]()
    return
import sys
sys.path.append("/Users/berthola/Desktop/Fiji Scripts")
from matrixoperator import Matrix
from javax.media.j3d import Transform3D
from javax.vecmath import Point3d
from ij.io import FileSaver
from profilingFixedCoordinates import getDendriticProfiles
from profilingFixedCoordinates import getNodeCoordinates
from machine_ import featureVector



good = featureVector(72481, 99481, 50)
bad =  featureVector(83160, 99481, 50)





plot = Plot("histogram", "y-coordinates", "count",range(0, 50), good)
plot.setLimits(0.0, 50.0, 0, 60000000.0) 
plot.show()
fs=FileSaver(plot.getImagePlus())
fs.saveAsPng(System.getProperty("user.home") + "/Desktop/Histotest/y" + "good.png")

plot = Plot("histogram", "y-coordinates", "count",range(0, 50), bad)
plot.setLimits(0.0, 50.0, 0, 60000000.0) 
plot.show()
fs=FileSaver(plot.getImagePlus())
fs.saveAsPng(System.getProperty("user.home") + "/Desktop/Histotest/y" + "bad.png")
IJ.open(imgPath);
IJ.run("Properties...", "channels=1 slices=1 frames=1 unit=um pixel_width=0.03143555 pixel_height=0.03144531 voxel_depth=1.0000000");
orig = IJ.getImage();

ti = orig.getShortTitle();
pngPath = homDir + relDir + "/" + ti + ".png"

strBar = "width=%g height=%g font=%g color=%s location=[%s] bold" % (barW, barH, barF, barC, barL)
# a hack to get the scale bars to work reliably
IJ.run(orig, "RGB Color", "")

# dummy to get things set
foo = orig.duplicate()
IJ.run(foo, "Add Scale Bar", strBar)
# explicitly save preferences
Prefs.savePreferences()
foo.changes = False
foo.close()

IJ.run(orig, "Add Scale Bar", strBar)
print(pngPath)

fs = FileSaver(orig)
if fs.saveAsPng(pngPath):
	print "png saved successfully at ", pngPath  

time.sleep(sleepTime)

orig.close()
  for i in range(0, len(pca)):
    if pca[i] <= binright and pca[i] >= binleft:
      counter += 1    
  histovector.append(counter)
  counter=0
  binleft+=length
  binright+=length

#histomirror=histovector.reverse()
print "The histogram vector is:", histovector


"""
#Plot center

from java.awt import Color
from ini.trakem2.display import Display3D
Display3D.addFatPoint("eigen center", tree.getLayerSet(), center.get(0, 0), center.get(0, 1), center.get(0, 2), 10, Color.red)
"""

plot = Plot("histogram", "bins", "count", range(iterations), histovector)
plot.show()
fs=FileSaver(plot.getImagePlus())
fs.saveAsPng(System.getProperty("user.home") + "/Desktop/Histotest/pcaleft" + str(ID) + ".png")

histovector.reverse()
plot = Plot("histogram", "bins", "count", range(iterations), histovector)
plot.show()
fs=FileSaver(plot.getImagePlus())
fs.saveAsPng(System.getProperty("user.home") + "/Desktop/Histotest/pcaright" + str(ID) + ".png")
	strBar = "width=%g height=%g font=%g color=%s location=[%s] bold" % (barW, barH, barF, barC, barL)
	# a hack to get the scale bars to work reliably
	if (bSetMinMax==True):
		orig.show()
		IJ.setMinAndMax(gMin, gMax)
	else:
		IJ.run(orig, "Enhance Contrast", sSat)
		
	if(bDoTiltCorrect == True):
		orig = jmg.correctForeshortening(orig, tiltDeg)
	IJ.run(orig, "RGB Color", "")
	IJ.run(orig, "Add Scale Bar", strBar)
	orig.show()

	outPth = sPngPath + strWrk + ".png"
	fs = FileSaver(orig)
	if fs.saveAsPng(outPth):
		print "png saved successfully at ", outPth  

	time.sleep(1)
	# orig.close()
	IJ.run("Close All")

toc = time.time()

elapsed = toc - tic

print("analyzed %g images" % i)
print("completed in %g sec" % elapsed )

示例#8
0
from ij import IJ
import os
from ij import WindowManager as WM
import re

from ij.io import FileSaver

path1 = 'I:\\image_process_msi\\KR_data\\CRC_KR_TEST_MSIMUT\\MSIMUT'
save_path = 'I:\\image_process_msi\\KR_data\\KR_adjust\\KR_test_msi'

for filename in os.listdir(path1)[0:2]:
    if filename.endswith(".png"):
        imp = IJ.openImage(os.path.join(path1, filename))
        #这里就可以用插件啦
        IJ.run(imp, "Colour Deconvolution", "vectors=H&E")
        images = map(WM.getImage, WM.getIDList())
        for img in images:
            print('title is ', img.title)
            if (re.search(r'Colour\_1', img.title) is not None):
                fs = FileSaver(img)
                fs.saveAsPng(os.path.join(save_path, filename))
                print(img.title, 'have saved')
            img.close()