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)
XLSUtil.setCellString(ws, col, row, val) else: XLSUtil.setCellNumber(ws, col, row, val) col += 1 row += 1 print('Sequence name: "%s"' % seq.name) num_c = seq.getSizeC() val_min, val_max = seq.getChannelsGlobalBounds() bwh = (val_max - val_min + 1) / (NUM_BINS * 2) # bin width half print('Bin width calculated from min/max and NUM_BINS: %s' % (bwh*2)) wb = XLSUtil.createWorkbook(XLS_FILE) # create a new excel document ws = XLSUtil.createNewPage(wb, "Histogram") # create a new worksheet # set excel headers row = 0 new_xls_row(ws, ["File name", seq.name]) row += 1 new_xls_row(ws, ['Number of channels', num_c]) new_xls_row(ws, ['X Dimension', seq.getSizeX()]) new_xls_row(ws, ['Y Dimension', seq.getSizeY()]) new_xls_row(ws, ['Z Dimension', seq.getSizeZ()]) numpixels = seq.getSizeX() * seq.getSizeY() * seq.getSizeZ() new_xls_row(ws, ['Total number of pixels', numpixels]) print('Total number of pixels: %s' % numpixels) new_xls_row(ws, ['Global min', val_min]) new_xls_row(ws, ['Global max', val_max]) row += 1