profile = roi.getPixels() c.assign("prof", profile) # pks = c.eval("SpectrumSearch(prof, sigma=3, threshold=25, background=TRUE, iterations=20, markov=TRUE, window=5)").asList() pks = c.eval("SpectrumSearch(prof, sigma=2, threshold=10, background=TRUE, iterations=20, markov=TRUE, window=2)").asList() pksY = pks[0].asIntegers() #for i in pksX: # print roi.x1, i # rois.append(PointRoi(roi.x1, roi.y1 + i)) #ol = Overlay() #for aroi in rois: # ol.add(aroi) #imp.setOverlay(ol) return pksY c = RConnection() x = c.eval("R.version.string") print x.asString() print c.eval("library(Peaks)").asString() imp = IJ.getImage() roi = imp.getRoi() alldata = [] maxlen = 0 totallen = 0 if roi.getType() == Roi.LINE: #print "a line roi" for i in range(imp.getStackSize()): imp.setSlice(i+1) peakYs = getPeaks(roi, c) peakTs = [i+1 for j in range(len(peakYs))]
from org.rosuda.REngine.Rserve import RConnection from ij.gui import Roi, Overlay c = RConnection() x = c.eval("R.version.string") print x.asString() print "Loaded Package:", c.eval("library(Peaks)").asString() imp = IJ.getImage() roi = imp.getRoi() if roi.getType() == Roi.LINE: print "a line roi found" profile = roi.getPixels() c.assign("prof", profile) # pks = c.eval("SpectrumSearch(prof, sigma=1, threshold=25, background=TRUE, iterations=20, markov=TRUE, window=5)").asList() # pks = c.eval("SpectrumSearch(prof, sigma=3, threshold=25, background=TRUE, iterations=20, markov=TRUE, window=5)").asList() # pks = c.eval("SpectrumSearch(prof, sigma=3, threshold=2, background=TRUE, iterations=20, markov=TRUE, window=2)").asList() pks = c.eval("SpectrumSearch(prof, sigma=2, threshold=2, background=TRUE, iterations=20, markov=FALSE, window=2)").asList() pksX = pks[0].asIntegers() rois = [] print "Number of Peaks:", len(pksX) for i in pksX: #print "\t", roi.x1, i rois.append(PointRoi(roi.x1, roi.y1 + i)) ol = Overlay() for aroi in rois: ol.add(aroi) imp.setOverlay(ol) c.close()
# RServeExample.py # Try out RServe # examples available here: http://www.rforge.net/Rserve/example.html # get needed files here: http://rforge.net/Rserve/files/ # # Modifications # Date Who Ver What # ---------- --- ------ ------------------------------------------------- # 2014-11-20 JRM 0.1.00 A test from org.rosuda.REngine.Rserve import RConnection from ij import IJ from ij.gui import Roi, Overlay, Line c = RConnection() x = c.eval("R.version.string") print x.asString() imp = IJ.openImage("C:/Data/images/test/blobs.gif") if imp == None: print("Error getting image") else: myLine = Line(116, 204, 91, 226) imp.setRoi(myLine) imp.show() print c.eval("library(Peaks)").asString() roi = imp.getRoi() if roi.getType() == Roi.LINE: print("a line roi") profile = roi.getPixels() c.assign("prof", profile) lMin = c.eval("min(prof)").asDouble() print(lMin)