def get_histogram(seq, nbins, bin_min, bin_max):
    """Generate two lists with central values and histogram counts."""
    print('%s, %s, %s' % (nbins, bin_min, bin_max))
    hist = Histogram.compute(seq, nbins, bin_min, bin_max)
    print("hist.getBinWidth(): %s" % hist.getBinWidth())
    hist_list = [[], []]
    for i in xrange(nbins):
        bin = hist.getBin(i)
        val = bin.getCentralValue()
        count = bin.getCount()
        hist_list[0].append(val)
        hist_list[1].append(count)
    return hist_list
Example #2
0
from icy.main import Icy
from plugins.ylemontag.histogram import Histogram

seq = Icy.getMainInterface().getFocusedSequence()

#print dir(seq)
hist = Histogram.compute(seq, 16, 0, 15);
print dir(hist)
for ibin in xrange(hist.getNbBins()):
	bin = hist.getBin(ibin)
	# print dir(bin)
	val = bin.getCentralValue()
	count = bin.getCount()
	print("%i: %i" % (val, count)) 

print "--------------------------------"
# print seq.name
# rois = seq.getROIs()
# for roi in rois:
# 	print dir(roi)
from icy.main import Icy
from icy.util import XLSUtil
from plugins.ylemontag.histogram import Histogram

seq = Icy.getMainInterface().getFocusedSequence()

xls_out = '/tmp/icy_py_excel_test.xls'
wb = XLSUtil.createWorkbook(xls_out)     # create excel document
ws = XLSUtil.createNewPage(wb, "result")     # create new page
XLSUtil.setCellString(ws, 0, 0, "filename")  # set headers
XLSUtil.setCellString(ws, 1, 0, seq.name)

# hist = Histogram.compute(seq, 16, 0, 15)
hist = Histogram.compute(seq, 16, 7, 248)
overall = 0
for i in xrange(hist.getNbBins()):
	bin = hist.getBin(i)
	val = bin.getCentralValue()
	count = bin.getCount()
	print("%i: %i" % (val, count))
	XLSUtil.setCellNumber(ws, 0, i+3, val)
	XLSUtil.setCellNumber(ws, 1, i+3, count)
	overall += count

XLSUtil.saveAndClose(wb)  # close and save the excel file

numpixels = seq.getSizeX() * seq.getSizeY() * seq.getSizeZ()
diff = overall - numpixels
print('Number of pixels: %s x %s x %s = %s' %
	(seq.getSizeX(), seq.getSizeY(), seq.getSizeZ(), numpixels))
print('Overall count from bins: %s' % overall)