def show(): import numpy as np import sys , h5py ; from numpy import float32 , uint8 from vigra.filters import hessianOfGaussianEigenvalues , gaussianSmoothing from vigra.analysis import watersheds from vigra.analysis import labelVolumeWithBackground, extendedLocalMinima3D from PyQt4.QtCore import QTimer ; from PyQt4 . QtGui import QApplication app = QApplication ( sys.argv ) from volumina.api import Viewer v = Viewer () v . title = " Volumina Demo " v . showMaximized () print "blubb" print a data = np.random.random((50,50,50)) v . addGrayscaleLayer ( data , name =" raw data ") t = QTimer () t.setInterval (200) app.exec_ ()
def view(data, labels=None, layer_types=None): """ """ if labels is not None: assert len(labels) == len(data) if layer_types is not None: assert len(layer_types) == len(data) assert all(ltype in ('Grayscale', 'RandomColors', 'Red', 'Green', 'Blue') for ltype in layer_types) app = QApplication(sys.argv) from volumina.api import Viewer v = Viewer() v.title = "Volumina Viewer" v.showMaximized() for i, d in enumerate(data): layer_name = layer_name = "layer_" + str(i) if labels is None else labels[i] if layer_types is None: _dtype_to_layer(v, d, layer_name) else: _name_to_layer(v, d, layer_types[i], layer_name) app.exec_()
def volumina_n_layer(data, labels = None): app = QApplication(sys.argv) import volumina from volumina.api import Viewer v = Viewer () v.title = " Volumina Demo " v.showMaximized () for ind, d in enumerate(data): layer_name = "layer_" + str(ind) if labels is not None: layer_name = labels[ind] # get data type of the elements d, to determine # if we use a grayscale overlay (float32) or a randomcolors overlay (uint) for labels data_type = d.dtype if data_type == np.float32 or data_type == np.float64: v.addGrayscaleLayer(d , name = layer_name) else: v.addRandomColorsLayer(d.astype(np.uint32), name = layer_name) app.exec_()
def streaming_n_layer(files, keys, labels=None, block_shape=[100, 100, 100]): from volumina.api import Viewer from volumina.pixelpipeline.datasources import LazyflowSource from lazyflow.graph import Graph from lazyflow.operators.ioOperators.opStreamingHdf5Reader import OpStreamingHdf5Reader from lazyflow.operators import OpCompressedCache app = QApplication(sys.argv) v = Viewer() graph = Graph() def mkH5source(fname, gname): h5file = h5py.File(fname) dtype = h5file[gname].dtype source = OpStreamingHdf5Reader(graph=graph) source.Hdf5File.setValue(h5file) source.InternalPath.setValue(gname) op = OpCompressedCache(parent=None, graph=graph) op.BlockShape.setValue(block_shape) op.Input.connect(source.OutputImage) return op.Output, dtype #rawSource = mkH5source(data[0], keys[0]) #v.addGrayscaleLayer(rawSource, name = 'raw') for i, f in enumerate(files): if labels is not None: layer_name = labels[i] else: layer_name = "layer_%i" % (i) source, dtype = mkH5source(f, keys[i]) if np.dtype(dtype) in (np.dtype('uint8'), np.dtype('float32'), np.dtype('float64')): v.addGrayscaleLayer(source, name=layer_name) else: v.addRandomColorsLayer(source, name=layer_name) v.setWindowTitle("Streaming Viewer") v.showNormal() app.exec_()
def volumina_viewer(): app = QApplication(sys.argv) v = Viewer() v.editor.setInteractionMode("navigation") yield v try: signal.signal(signal.SIGINT, lambda *_: app.quit()) app.exec_() finally: app.quit()
def view(dset): from volumina.api import Viewer from PyQt4.QtGui import QApplication app = QApplication([]) v = Viewer() if isinstance(dset, str): f = h5py.File(dset, 'r') d = f["volume/data"].value f.close() v.setWindowTitle(dset) v.addGrayscaleLayer(d, name="raw") elif isinstance(dset, numpy.ndarray): v.addGrayscaleLayer(dset, name="raw") else: raise RuntimeError("%r" % dset) v.showMaximized() app.exec_()
def volumina_single_layer(data): app = QApplication (sys.argv) from volumina.api import Viewer v = Viewer () v.title = " Volumina Demo " v.showMaximized () v.addGrayscaleLayer (data , name =" raw data ") app . exec_ ()
def view_HDF5(inpaths): app = QApplication(sys.argv) v = Viewer() for inpath in inpaths: if "n_1_" in inpath: prefix = "n_1_" elif "n_2_" in inpath: prefix = "n_2_" else: prefix = "" if "h5" in inpath: #data = vigra.readHDF5(inpath, "data") print print "inpath", inpath data = read_h5(inpath) file = inpath.split("/")[-1] name = prefix + file.split(".")[0] if "prob_files" in inpath or "seeds" in inpath or "trimap" in inpath: data = binarize_predict(data) file = inpath.split("/")[-2] + "_" + inpath.split("/")[-1] name = prefix + file.split(".")[0] print "type", type(data) if "test_data" in inpath or "prob_files" in inpath or "seeds" in inpath or "trimap" in inpath: v.addGrayscaleLayer(data, name=name) # if "trimaps" in inpath or "dense" in inpath or "sup_maps" in inpath or "seg_maps" in inpath: # v.addRandomColorsLayer(255*data, name=name+"_color") else: v.addRandomColorsLayer(255*data, name=name+"_color") if "png" in inpath: img = vigra.impex.readImage(inpath) img = np.asarray(img) file = inpath.split("/")[-1] name = file.split(".")[0] print "type",type(img) v.addGrayscaleLayer(img, name=name) #v.addRandomColorsLayer(255*img, name=name+"color") v.showMaximized() app.exec_()
def showStuff(raw_name, pred_viewer1, pred_viewer2, cutout_name, one_extra=None): # display the raw and annotations for cremi challenge data raw = vigra.impex.readHDF5(indir + datasets[raw_name], "data", order='C') # raw_old = vigra.readHDF5(indir+datasets["raw_bad"], "data", order = 'C') defect_prediction_128 = vigra.impex.readHDF5(indir + datasets[pred_viewer2], "data", order='C') defect_prediction_150 = vigra.impex.readHDF5(indir + datasets[pred_viewer1], "data", order='C') cutout_from_150_pred = vigra.impex.readHDF5(indir + datasets[cutout_name], "data", order='C') #################################################################################################################### # only used for fast testing stuff #change_one = vigra.readHDF5(indir+datasets["segmentation_on_equalized_image"], "data", order = 'C') #pdb.set_trace() #defect_prediction_150[1,:,:] = change_one[0,:,:,0] #################################################################################################################### # defect_prediction_150 = gt[..., 0] cutout = numpy.asarray(cutout_from_150_pred) rawdata = numpy.asarray(raw) # rawdata_old = numpy.asarray(raw_old) # op5ify # shape5d = rawdata.shape shape5d = (1, ) + rawdata.shape + (1, ) print shape5d, rawdata.shape, rawdata.dtype app = QApplication([]) v = Viewer() direct = False # layer for raw data rawdata = numpy.reshape(rawdata, shape5d) rawsource = ArraySource(rawdata) v.dataShape = shape5d lraw = GrayscaleLayer(rawsource, direct=direct) lraw.visible = True lraw.name = "raw" v.layerstack.append(lraw) # layer for cutout regions from raw data cutout = numpy.reshape(cutout, shape5d) cutoutsource = ArraySource(cutout) lcutout = GrayscaleLayer(cutoutsource, direct=direct) lcutout.visible = False lcutout.name = "cut_out" v.layerstack.append(lcutout) # layer for first prediction result defect_prediction_128 = numpy.reshape(defect_prediction_128, shape5d) synsource = ArraySource(defect_prediction_128) ct = create_random_16bit() ct[0] = 0 lsyn = ColortableLayer(synsource, ct) lsyn.name = pred_viewer2 lsyn.visible = False v.layerstack.append(lsyn) # layer for second prediction result segm = numpy.reshape(defect_prediction_150, shape5d) segsource = ArraySource(segm) ct = create_random_16bit() ct[0] = 0 lseg = ColortableLayer(segsource, ct) lseg.name = pred_viewer1 lseg.visible = False v.layerstack.append(lseg) if one_extra is None: v.showMaximized() app.exec_() if one_extra is not None: # layer for third prediction result extra_prediction = vigra.readHDF5(indir + datasets[one_extra], "data", order='C') extra_pred_reshaped = numpy.reshape(extra_prediction, shape5d) segsource = ArraySource(extra_pred_reshaped) ct = create_random_16bit() ct[0] = 0 # ct = create_default_16bit() lseg = ColortableLayer(segsource, ct) lseg.name = one_extra lseg.visible = False v.layerstack.append(lseg) v.showMaximized() app.exec_()
a = np.zeros(500 * 500).reshape(500, 500).astype(np.uint8) ii = np.random.randint(0, 500, 1) jj = np.random.randint(0, 500, 1) a[ii, jj] = 1 a = vigra.filters.discDilation(a, radius=20) array[:] = a.reshape(shape).view(np.ndarray) * 255 op.Input.setDirty() do() cron.timeout.connect(do) ds = createDataSource(op.Output) layer = ColortableLayer(ds, jet()) mainwin = Viewer() mainwin.layerstack.append(layer) mainwin.dataShape = (1, h, w, 1, 1) print(mainwin.centralWidget()) BoxContr = BoxController(mainwin.editor, op.Output, boxListModel) BoxInt = BoxInterpreter(mainwin.editor.navInterpret, mainwin.editor.posModel, BoxContr, mainwin.centralWidget()) mainwin.editor.setNavigationInterpreter(BoxInt) # boxListModel.boxRemoved.connect(BoxContr.deleteItem) LV.show() mainwin.show() app.exec_()
nlm2 = vigra.readHDF5(pnlm2, 'data') tvbi2 = vigra.readHDF5(ptvbi2, 'data') tvbai20 = vigra.readHDF5(ptvbai20, 'data') tvc5 = vigra.readHDF5(ptvc5, 'data') m1 = vigra.readHDF5(pm1, 'data') m2 = vigra.readHDF5(pm2, 'data') m3 = vigra.readHDF5(pm3, 'data') g1 = vigra.readHDF5(pg1, 'data') gf5 = vigra.readHDF5(pgf5, 'data') gm3 = vigra.readHDF5(pgm3, 'data') diff = gf5-data app = QApplication(sys.argv) v = Viewer() print "add layers" v.addGrayscaleLayer(data, name="raw") v.addGrayscaleLayer(nlm, name="non local mean") v.addGrayscaleLayer(nlm2, name="non local mean (on presmoothed)") v.addGrayscaleLayer(tvbi2, name="tv bregman 2.0 isotropic") v.addGrayscaleLayer(tvbai20, name="tv bregman 20.0 anisotropic") v.addGrayscaleLayer(tvc5, name="tv Chambolle 2.0") v.addGrayscaleLayer(m1, name="median 1") v.addGrayscaleLayer(m2, name="median 2") v.addGrayscaleLayer(m3, name="median 3") v.addGrayscaleLayer(g1.view(numpy.ndarray), name="gauss 1") v.addGrayscaleLayer(gf5.view(numpy.ndarray), name="gauss guided filter 5") v.addGrayscaleLayer(gm3.view(numpy.ndarray), name="median guided filter 3")
x = args[0].find(".h5") fname = args[0][:x+3] gname = args[0][x+4:] #load data try: f = h5py.File(fname, 'r') except: raise RuntimeError("Could not load '%s'" % fname) raw = f[gname].value.squeeze() assert raw.ndim == 3 assert raw.dtype == numpy.uint8 f.close() app = QApplication([]) v = Viewer() direct = True raw.shape = (1,)+raw.shape+(1,) l1 = v.addGrayscaleLayer(raw, name="raw", direct=True) ####################################################################################################################### skeletons = Skeletons() e = SkeletonInterpreter(v.editor, skeletons, v) v.editor.eventSwitch.interpreter = e v.show() app.exec_()
x = args[0].find(".h5") fname = args[0][: x + 3] gname = args[0][x + 4 :] # load data try: f = h5py.File(fname, "r") except: raise RuntimeError("Could not load '%s'" % fname) raw = f[gname][()].squeeze() assert raw.ndim == 3 assert raw.dtype == numpy.uint8 f.close() app = QApplication([]) v = Viewer() direct = True raw.shape = (1,) + raw.shape + (1,) l1 = v.addGrayscaleLayer(raw, name="raw", direct=True) ####################################################################################################################### skeletons = Skeletons() e = SkeletonInterpreter(v.editor, skeletons, v) v.editor.eventSwitch.interpreter = e v.show() v.raise_()
#array[:] = np.random.randint(0,255,500*500).reshape(shape).astype(np.uint8) a = np.zeros(500*500).reshape(500,500).astype(np.uint8) ii=np.random.randint(0,500,1) jj=np.random.randint(0,500,1) a[ii,jj]=1 a=vigra.filters.discDilation(a,radius=20) array[:]=a.reshape(shape).view(np.ndarray)*255 op.Input.setDirty() do() cron.connect(cron, SIGNAL('timeout()'), do) ds = LazyflowSource( op.Output ) layer = ColortableLayer(ds,jet()) mainwin=Viewer() def _addNewLabel(): """ Add a new label to the label list GUI control. Return the new number of labels in the control. """ erase=Label( "Dummy",QColor(255,255,255)) label = Label( "Foreground",QColor(255,0,0)) back = Label( "Background",QColor(0,255,0)) newRow = labelListModel.rowCount() labelListModel.insertRow( newRow, erase ) newRow = labelListModel.rowCount()
import skneuro import vigra from volumina.api import Viewer from PyQt4.QtGui import QApplication import skneuro.denoising as dn p = '/home/tbeier/Desktop/blocks/data_sub_3.h5' data = vigra.impex.readHDF5(p,'data')[0:200,:,0:200].astype('uint8').squeeze() app = QApplication(sys.argv) v = Viewer() v.addGrayscaleLayer(data, name="raw") with vigra.Timer("get ranks 8*2"): a = dn.ballRankOrder(data, radius=12, takeNth=2, ranks=(0.01,0.1, 0.5, 0.9, 0.99), useHistogram=True, minVal=0.0, maxVal=255.0, nBins=256)
if event.type() == QEvent.GraphicsSceneMousePress: if event.button() == QtCore.Qt.LeftButton: # print "MyPathItem left click event detected!" pen = QPen(QColor(0, 255, 255)) self.visiblePath.setPen(pen) if event.button() == Qt.RightButton: # print "MyPathItem right click event detected!" pen = QPen(QColor(255, 255, 0)) self.visiblePath.setPen(pen) app = QtGui.QApplication([]) v = Viewer() c_x = numpy.array([10, 20, 40, 80]) c_y = numpy.array([80, 90, 100, 110]) item1 = ClickablePathItem(v.editor.imageScenes[2], clickable_width=11) item1.set_path_from_coordinates(c_x, c_y) # Create images back = (numpy.ones((100, 200, 300)) * 0).astype(numpy.uint8) back[0:60, 0:60, 0:60] = 255 back[40:80, 40:80, 40:80] = 120 back[40:100, 40:100, 0:40] = 80 back[0:45, 50:100, 0:100] = 200 ol = (numpy.zeros((100, 200, 300))).astype(numpy.uint8) # ol[0:99, 0:99, 0:99] = 120 # ol[0:99, 120:140, 0:99] = 255
for n, arr in enumerate(imgs): arr = arr.squeeze() f.add_subplot(1, len(imgs), n) pylab.imshow(arr.swapaxes(0,1)) pylab.show() else: if False: pmapSmooth2 = dn.diffusion3d(p.copy()*255.0, param) vigra.impex.writeHDF5(pmapSmooth2, "sub.h5", "dc_1.00_2.50") if True : pmapSmooth1 = vigra.impex.readHDF5("sub.h5", "dc_0.75_2") pmapSmooth2 = vigra.impex.readHDF5("sub.h5", "dc_1.00_2.50") app = QApplication(sys.argv) v = Viewer() v.addGrayscaleLayer(pmapSmooth1, name="pmapSmooth_0.75_2.00") v.addGrayscaleLayer(pmapSmooth2, name="pmapSmooth_1.00_2.50") v.addGrayscaleLayer(p, name="pmap") v.addGrayscaleLayer(d, name="raw") #v.addGrayscaleLayer(bf.grayscaleErosion(data,sigma=2.5), name="e") #v.addGrayscaleLayer(dt, name="dt") v.setWindowTitle("data") v.showMaximized()
from PyQt5.QtWidgets import QApplication f = h5py.File("raw.h5", "w") d = (255 * numpy.random.random((100, 200, 300))).astype(numpy.uint8) f.create_dataset("raw", data=d) f.close() f = h5py.File("seg.h5", "w") d = (10 * numpy.random.random((100, 200, 300))).astype(numpy.uint32) f.create_dataset("seg", data=d) f.close() ##----- app = QApplication(sys.argv) v = Viewer() graph = Graph() def mkH5source(fname, gname): h5file = h5py.File(fname) source = OpStreamingH5N5Reader(graph=graph) source.H5N5File.setValue(h5file) source.InternalPath.setValue(gname) op = OpCompressedCache(parent=None, graph=graph) op.BlockShape.setValue([100, 100, 100]) op.Input.connect(source.OutputImage) return op.Output
import numpy import skneuro import vigra from volumina.api import Viewer from PyQt4.QtGui import QApplication import skneuro.denoising as dn p = '/home/tbeier/Desktop/blocks/data_sub_3.h5' data = vigra.impex.readHDF5(p, 'data')[0:200, :, 0:200].astype('uint8').squeeze() app = QApplication(sys.argv) v = Viewer() v.addGrayscaleLayer(data, name="raw") with vigra.Timer("get ranks 8*2"): a = dn.ballRankOrder(data, radius=12, takeNth=2, ranks=(0.01, 0.1, 0.5, 0.9, 0.99), useHistogram=True, minVal=0.0, maxVal=255.0, nBins=256) v.addGrayscaleLayer(a, name="0.5 8* 2") v.setWindowTitle("data") v.showMaximized() app.exec_()
from volumina.api import Viewer from volumina.colortables import default16_new from volumina.pixelpipeline.datasources import ArraySinkSource, ArraySource from volumina.layer import ColortableLayer, GrayscaleLayer from PyQt5.QtWidgets import QApplication SHAPE = (1, 600, 800, 1, 1) # volumina expects 5d txyzc data_arr = (255 * numpy.random.random(SHAPE)).astype(numpy.uint8) label_arr = numpy.zeros(SHAPE, dtype=numpy.uint8) ##----- app = QApplication(sys.argv) v = Viewer() data_src = ArraySource(data_arr) data_layer = GrayscaleLayer(data_src) data_layer.name = "Raw" data_layer.numberOfChannels = 1 label_src = ArraySinkSource(label_arr) label_layer = ColortableLayer(label_src, colorTable=default16_new, direct=False) label_layer.name = "Labels" label_layer.ref_object = None assert SHAPE == label_arr.shape == data_arr.shape v.dataShape = SHAPE
def addHocViewer(grayData=None, segData=None, title="viewer", visu=True): if visu: app = QApp.Instance().app v = Viewer() if grayData is not None: for name in grayData.keys(): data = grayData[name] if _hasVigra: if isinstance(data, vigra.arraytypes.VigraArray): v.addGrayscaleLayer(data.view(numpy.ndarray), name=name) else: v.addGrayscaleLayer(data, name=name) else: v.addGrayscaleLayer(data, name=name) if segData is not None: for name in segData.keys(): data = segData[name] if _hasVigra: if isinstance(data, vigra.arraytypes.VigraArray): v.addColorTableLayer(data.view(numpy.ndarray), name=name) else: v.addColorTableLayer(data, name=name) else: v.addGrayscaleLayer(data, name=name) v.setWindowTitle(title) v.showMaximized() app.exec_()
def eventFilter(self, QObject, QEvent): if (QEvent.type() == QtCore.QEvent.MouseButtonRelease and QObject is self): pos = QEvent.pos() print('mouse button release: (%d, %d)' % (pos.x(), pos.y())) return Viewer.eventFilter(self, QObject, QEvent)
#array[:] = np.random.randint(0,255,500*500).reshape(shape).astype(np.uint8) a = np.zeros(500 * 500).reshape(500, 500).astype(np.uint8) ii = np.random.randint(0, 500, 1) jj = np.random.randint(0, 500, 1) a[ii, jj] = 1 a = vigra.filters.discDilation(a, radius=20) array[:] = a.reshape(shape).view(np.ndarray) * 255 op.Input.setDirty() do() cron.timeout.connect(do) ds = createDataSource(op.Output) layer = ColortableLayer(ds, jet()) mainwin = Viewer() def _addNewLabel(): """ Add a new label to the label list GUI control. Return the new number of labels in the control. """ erase = Label("Dummy", QColor(255, 255, 255)) label = Label("Foreground", QColor(255, 0, 0)) back = Label("Background", QColor(0, 255, 0)) newRow = labelListModel.rowCount() labelListModel.insertRow(newRow, erase) newRow = labelListModel.rowCount() labelListModel.insertRow(newRow, label)
print "seg " labels = vigra.readHDF5(lPath, 'data') labelsS = vigra.readHDF5(lsPath, 'data') #labelsSS = vigra.readHDF5(lssPath, 'data') labelsPS = vigra.readHDF5("/mnt/CLAWS1/tbeier/data/stack_with_holes/lps.h5", 'data') print ew.shape print "datashape",data.shape print "resshape",smoothedT.shape app = QApplication(sys.argv) v = Viewer() v.addGrayscaleLayer(data, name="raw") v.addGrayscaleLayer(smoothedT, name="smoothedT") v.addGrayscaleLayer(ew, name="hessian ew") v.addGrayscaleLayer(ews, name="hessian ews") v.addGrayscaleLayer(ewss, name="hessian ewss") v.addGrayscaleLayer(pEws, name="hessian p80ews") #v.addGrayscaleLayer(dd, name="diff ews") v.addColorTableLayer(labels, name="labels") v.addColorTableLayer(labelsS, name="labelsS") #v.addColorTableLayer(labelsSS, name="labelsSS") v.addColorTableLayer(labelsPS, name="labelsPS") v.setWindowTitle("stack with holes") v.showMaximized()
if len(args) != 1: parser.error("no hdf5 dataset supplied") x = args[0].find(".h5") fname = args[0][:x+3] gname = args[0][x+4:] #load data f = h5py.File(fname, 'r') raw = f[gname].value.squeeze() assert raw.ndim == 3 assert raw.dtype == numpy.uint8 f.close() app = QApplication([]) v = Viewer() direct = True raw.shape = (1,)+raw.shape+(1,) def addLayers(v, direct): l1 = v.addGrayscaleLayer(raw, name="raw direct=%r" % direct, direct=direct) l1.visible = direct colortable = [QColor(0,0,0,0).rgba(), QColor(255,0,0).rgba()] l2 = v.addColorTableLayer((raw>128).astype(numpy.uint8), name="thresh direct=%r" % direct, colortable=colortable, direct=direct) l2.visible = direct return (l1, l2) directLayers = addLayers(v, True) indirectLayers = addLayers(v, False)
if len(args) != 1: parser.error("no hdf5 dataset supplied") x = args[0].find(".h5") fname = args[0][:x+3] gname = args[0][x+4:] #load data f = h5py.File(fname, 'r') raw = f[gname].value assert raw.ndim == 3 assert raw.dtype == numpy.uint8 f.close() app = QApplication([]) v = Viewer() direct = True raw.shape = (1,)+raw.shape+(1,) l1 = v.addGrayscaleLayer(raw, name="raw", direct=True) l1.visible = direct colortable = [QColor(0,0,0,0).rgba(), QColor(255,0,0).rgba(), QColor(0,255,0).rgba(), QColor(0,0,255).rgba()] s = ((raw/64)).astype(numpy.uint8) def onClick(layer, pos5D, pos): print "here i am: ", pos5D, s[pos5D] l2 = v.addColorTableLayer(s, clickFunctor=onClick, name="thresh", colortable=colortable, direct=direct) l2.colortableIsRandom = True l2.zeroIsTransparent = True
# This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software Foundation, # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # # Copyright 2011-2014, the ilastik developers from volumina.api import Viewer from PyQt4.QtGui import QApplication import numpy app = QApplication([]) v = Viewer() a = (255*numpy.random.random((1, 50,60,70,10) )).astype(numpy.uint8) v.addGrayscaleLayer(a, name="raw") v.showMaximized() app.exec_()
f = pylab.figure() for n, arr in enumerate(imgs): arr = arr.squeeze() f.add_subplot(1, len(imgs), n) pylab.imshow(arr.swapaxes(0, 1)) pylab.show() else: if False: pmapSmooth2 = dn.diffusion3d(p.copy() * 255.0, param) vigra.impex.writeHDF5(pmapSmooth2, "sub.h5", "dc_1.00_2.50") if True: pmapSmooth1 = vigra.impex.readHDF5("sub.h5", "dc_0.75_2") pmapSmooth2 = vigra.impex.readHDF5("sub.h5", "dc_1.00_2.50") app = QApplication(sys.argv) v = Viewer() v.addGrayscaleLayer(pmapSmooth1, name="pmapSmooth_0.75_2.00") v.addGrayscaleLayer(pmapSmooth2, name="pmapSmooth_1.00_2.50") v.addGrayscaleLayer(p, name="pmap") v.addGrayscaleLayer(d, name="raw") #v.addGrayscaleLayer(bf.grayscaleErosion(data,sigma=2.5), name="e") #v.addGrayscaleLayer(dt, name="dt") v.setWindowTitle("data") v.showMaximized() app.exec_() sys.exit()
from volumina.api import Viewer from PyQt4.QtGui import QApplication import numpy app = QApplication([]) v = Viewer() a = (255*numpy.random.random((1, 50,60,70,10) )).astype(numpy.uint8) v.addGrayscaleLayer(a, name="raw") v.showMaximized() app.exec_()
if event.button() == QtCore.Qt.LeftButton: # print "MyPathItem left click event detected!" pen = QPen(QColor(0, 255, 255)) pen.setWidth(5) self.setPen(pen) if event.button() == Qt.RightButton: # print "MyPathItem right click event detected!" pen = QPen(QColor(255, 255, 0)) pen.setWidth(5) self.setPen(pen) app = QtGui.QApplication([]) v = Viewer() xFwd = numpy.array([10, 20, 40, 80]) xRev = xFwd[::-1] x = numpy.concatenate([xFwd, xRev]) yFwd = numpy.array([80, 90, 100, 110]) yRev = yFwd[::-1] y = numpy.concatenate([yFwd, yRev]) path1 = arrayToQPath(x, y) item1 = ClickablePathItem() item1.setPath(path1) # Create images back = (numpy.ones((100, 200, 300)) * 0).astype(numpy.uint8) back[0:60, 0:60, 0:60] = 255
a = np.zeros(500*500).reshape(500,500).astype(np.uint8) ii=np.random.randint(0,500,1) jj=np.random.randint(0,500,1) a[ii,jj]=1 a=vigra.filters.discDilation(a,radius=20) array[:]=a.reshape(shape).view(np.ndarray)*255 op.Input.setDirty() do() cron.connect(cron, SIGNAL('timeout()'), do) ds = LazyflowSource( op.Output ) layer = ColortableLayer(ds,jet()) mainwin=Viewer() mainwin.layerstack.append(layer) mainwin.dataShape=(1,h,w,1,1) print mainwin.centralWidget() BoxContr=BoxController(mainwin.editor,op.Output,boxListModel) BoxInt=BoxInterpreter(mainwin.editor.navInterpret,mainwin.editor.posModel,BoxContr,mainwin.centralWidget()) mainwin.editor.setNavigationInterpreter(BoxInt) # boxListModel.boxRemoved.connect(BoxContr.deleteItem) LV.show() mainwin.show()
def addHocViewer(grayData=None, segData=None, title="viewer", visu=True): if visu: app = QApp.Instance().app v = Viewer() if grayData is not None: for data, name in grayData: if isinstance(data, vigra.arraytypes.VigraArray): v.addGrayscaleLayer(data.view(numpy.ndarray), name=name) else: v.addGrayscaleLayer(data, name=name) if segData is not None: for data, name in segData: if isinstance(data, vigra.arraytypes.VigraArray): v.addColorTableLayer(data.view(numpy.ndarray), name=name) else: v.addColorTableLayer(data, name=name) v.setWindowTitle(title) v.showMaximized() app.exec_()
def showStuff(raw_name, pred_viewer1, pred_viewer2, cutout_name, one_extra = None): # display the raw and annotations for cremi challenge data raw = vigra.impex.readHDF5(indir+datasets[raw_name], "data", order = 'C') # raw_old = vigra.readHDF5(indir+datasets["raw_bad"], "data", order = 'C') defect_prediction_128 = vigra.impex.readHDF5(indir+datasets[pred_viewer2], "data", order = 'C') defect_prediction_150 = vigra.impex.readHDF5(indir+datasets[pred_viewer1], "data", order = 'C') cutout_from_150_pred = vigra.impex.readHDF5(indir+datasets[cutout_name], "data", order = 'C') #################################################################################################################### # only used for fast testing stuff #change_one = vigra.readHDF5(indir+datasets["segmentation_on_equalized_image"], "data", order = 'C') #pdb.set_trace() #defect_prediction_150[1,:,:] = change_one[0,:,:,0] #################################################################################################################### # defect_prediction_150 = gt[..., 0] cutout = numpy.asarray(cutout_from_150_pred) rawdata = numpy.asarray(raw) # rawdata_old = numpy.asarray(raw_old) # op5ify # shape5d = rawdata.shape shape5d = (1,)+rawdata.shape+(1,) print shape5d, rawdata.shape, rawdata.dtype app = QApplication([]) v = Viewer() direct = False # layer for raw data rawdata = numpy.reshape(rawdata, shape5d) rawsource = ArraySource(rawdata) v.dataShape = shape5d lraw = GrayscaleLayer(rawsource, direct=direct) lraw.visible = True lraw.name = "raw" v.layerstack.append(lraw) # layer for cutout regions from raw data cutout = numpy.reshape(cutout, shape5d) cutoutsource = ArraySource(cutout) lcutout = GrayscaleLayer(cutoutsource, direct = direct) lcutout.visible = False lcutout.name = "cut_out" v.layerstack.append(lcutout) # layer for first prediction result defect_prediction_128 = numpy.reshape(defect_prediction_128, shape5d) synsource = ArraySource(defect_prediction_128) ct = create_random_16bit() ct[0] = 0 lsyn = ColortableLayer(synsource, ct) lsyn.name = pred_viewer2 lsyn.visible = False v.layerstack.append(lsyn) # layer for second prediction result segm = numpy.reshape(defect_prediction_150, shape5d) segsource = ArraySource(segm) ct = create_random_16bit() ct[0] = 0 lseg = ColortableLayer(segsource, ct) lseg.name = pred_viewer1 lseg.visible = False v.layerstack.append(lseg) if one_extra is None: v.showMaximized() app.exec_() if one_extra is not None: # layer for third prediction result extra_prediction = vigra.readHDF5(indir+datasets[one_extra], "data", order = 'C') extra_pred_reshaped = numpy.reshape(extra_prediction, shape5d) segsource = ArraySource(extra_pred_reshaped) ct = create_random_16bit() ct[0] = 0 # ct = create_default_16bit() lseg = ColortableLayer(segsource, ct) lseg.name = one_extra lseg.visible = False v.layerstack.append(lseg) v.showMaximized() app.exec_()
# array[:] = np.random.randint(0,255,500*500).reshape(shape).astype(np.uint8) a = np.zeros(500 * 500).reshape(500, 500).astype(np.uint8) ii = np.random.randint(0, 500, 1) jj = np.random.randint(0, 500, 1) a[ii, jj] = 1 a = vigra.filters.discDilation(a, radius=20) array[:] = a.reshape(shape).view(np.ndarray) * 255 op.Input.setDirty() do() cron.connect(cron, SIGNAL("timeout()"), do) ds = LazyflowSource(op.Output) layer = ColortableLayer(ds, jet()) mainwin = Viewer() def _addNewLabel(): """ Add a new label to the label list GUI control. Return the new number of labels in the control. """ erase = Label("Dummy", QColor(255, 255, 255)) label = Label("Foreground", QColor(255, 0, 0)) back = Label("Background", QColor(0, 255, 0)) newRow = labelListModel.rowCount() labelListModel.insertRow(newRow, erase) newRow = labelListModel.rowCount() labelListModel.insertRow(newRow, label)
def volumina_double_layer(data, overlay): # get data type of the elements of overlay, to determine # if we use a grayscale overlay (float32) or a randomcolors overlay (uint) for labels mask = [] for i in range( len(overlay.shape) ): mask.append(0) mask = tuple(mask) data_type = type(overlay[mask]) app = QApplication (sys.argv) from volumina.api import Viewer v = Viewer () v.title = " Volumina Demo " v.showMaximized () v.addGrayscaleLayer(data , name = " raw data ") if data_type == np.float32: v.addGrayscaleLayer(overlay , name = " overlay ") else: v.addRandomColorsLayer(overlay, name = " overlay ") app . exec_ ()
sigma = float(sigma) return (-1.0 / sigma) * gauss(x, mean, sigma) + (( (-x + mean) / sigma)**2) * gauss(x, mean, sigma) for x in range(patchSize[0]): for y in range(patchSize[1]): for z in range(patchSize[2]): dgx = gauss2d(x, radius[0], sigma[0]) gy = gauss(y, radius[1], sigma[1]) gz = gauss(z, radius[2], sigma[2]) kernel[x, y, z] = dgx * gy * gz return kernel kernel = makeFilter(radius, sigma) kernel /= numpy.sum(kernel) kernel -= kernel.min() kernel /= kernel.max() app = QApplication(sys.argv) v = Viewer() v.addGrayscaleLayer(kernel, name="raw") v.setWindowTitle("kernel") v.showMaximized() app.exec_()
def volumina_flexible_layer(data, layer_types, labels=None): assert len(layer_types) == len(data) app = QApplication (sys.argv) import volumina from volumina.api import Viewer v = Viewer () v.title = " Volumina Demo " v.showMaximized () for i, d in enumerate(data): layer_name = "layer_" + str(i) if labels is not None: layer_name = labels[i] # get data type of the elements d, to determine # if we use a grayscale overlay (float32) or a randomcolors overlay (uint) for labels data_type = d.dtype if layer_types[i] == 'Grayscale': v.addGrayscaleLayer(d , name = layer_name) elif layer_types[i] == 'RandomColors': v.addRandomColorsLayer(d.astype(np.uint32), name=layer_name) elif layer_types[i] == 'Red': v.addAlphaModulatedLayer(d , name=layer_name, tintColor=QColor(255,0,0)) elif layer_types[i] == 'Green': v.addAlphaModulatedLayer(d , name=layer_name, tintColor=QColor(0,255,0)) elif layer_types[i] == 'Blue': v.addAlphaModulatedLayer(d , name=layer_name, tintColor=QColor(0,0,255)) else: raise KeyError("Invalid Layer Type, %s!" % layer_types[i]) app.exec_()
a = np.zeros(500 * 500).reshape(500, 500).astype(np.uint8) ii = np.random.randint(0, 500, 1) jj = np.random.randint(0, 500, 1) a[ii, jj] = 1 a = vigra.filters.discDilation(a, radius=20) array[:] = a.reshape(shape).view(np.ndarray) * 255 op.Input.setDirty() do() cron.timeout.connect(do) ds = LazyflowSource(op.Output) layer = ColortableLayer(ds, jet()) mainwin = Viewer() mainwin.layerstack.append(layer) mainwin.dataShape = (1, h, w, 1, 1) print(mainwin.centralWidget()) BoxContr = BoxController(mainwin.editor, op.Output, boxListModel) BoxInt = BoxInterpreter(mainwin.editor.navInterpret, mainwin.editor.posModel, BoxContr, mainwin.centralWidget()) mainwin.editor.setNavigationInterpreter(BoxInt) # boxListModel.boxRemoved.connect(BoxContr.deleteItem) LV.show() mainwin.show()
from PyQt4.QtGui import QApplication f = h5py.File("raw.h5", 'w') d = (255 * numpy.random.random((100, 200, 300))).astype(numpy.uint8) f.create_dataset("raw", data=d) f.close() f = h5py.File("seg.h5", 'w') d = (10 * numpy.random.random((100, 200, 300))).astype(numpy.uint32) f.create_dataset("seg", data=d) f.close() ##----- app = QApplication(sys.argv) v = Viewer() graph = Graph() def mkH5source(fname, gname): h5file = h5py.File(fname) source = OpStreamingHdf5Reader(graph=graph) source.Hdf5File.setValue(h5file) source.InternalPath.setValue(gname) op = OpCompressedCache(parent=None, graph=graph) op.BlockShape.setValue([100, 100, 100]) op.Input.connect(source.OutputImage) return op.Output
#dd = ew-ews print "seg " labels = vigra.readHDF5(lPath, 'data') labelsS = vigra.readHDF5(lsPath, 'data') #labelsSS = vigra.readHDF5(lssPath, 'data') labelsPS = vigra.readHDF5( "/mnt/CLAWS1/tbeier/data/stack_with_holes/lps.h5", 'data') print ew.shape print "datashape", data.shape print "resshape", smoothedT.shape app = QApplication(sys.argv) v = Viewer() v.addGrayscaleLayer(data, name="raw") v.addGrayscaleLayer(smoothedT, name="smoothedT") v.addGrayscaleLayer(ew, name="hessian ew") v.addGrayscaleLayer(ews, name="hessian ews") v.addGrayscaleLayer(ewss, name="hessian ewss") v.addGrayscaleLayer(pEws, name="hessian p80ews") #v.addGrayscaleLayer(dd, name="diff ews") v.addColorTableLayer(labels, name="labels") v.addColorTableLayer(labelsS, name="labelsS") #v.addColorTableLayer(labelsSS, name="labelsSS") v.addColorTableLayer(labelsPS, name="labelsPS") v.setWindowTitle("stack with holes") v.showMaximized()
#array[:] = np.random.randint(0,255,500*500).reshape(shape).astype(np.uint8) a = np.zeros(500 * 500).reshape(500, 500).astype(np.uint8) ii = np.random.randint(0, 500, 1) jj = np.random.randint(0, 500, 1) a[ii, jj] = 1 a = vigra.filters.discDilation(a, radius=20) array[:] = a.reshape(shape).view(np.ndarray) * 255 op.Input.setDirty() do() cron.connect(cron, SIGNAL('timeout()'), do) ds = LazyflowSource(op.Output) layer = ColortableLayer(ds, jet()) mainwin = Viewer() mainwin.layerstack.append(layer) mainwin.dataShape = (1, 500, 500, 1, 1) print mainwin.centralWidget() BoxContr = BoxController(mainwin.editor.imageScenes[2], op.Output, boxListModel) BoxInt = BoxInterpreter(mainwin.editor.navInterpret, mainwin.editor._posModel, BoxContr, mainwin.centralWidget()) mainwin.editor.setNavigationInterpreter(BoxInt) # boxListModel.boxRemoved.connect(BoxContr.deleteItem) LV.show() mainwin.show()
if len(args) != 1: parser.error("no hdf5 dataset supplied") x = args[0].find(".h5") fname = args[0][:x + 3] gname = args[0][x + 4:] # load data f = h5py.File(fname, "r") raw = f[gname].value.squeeze() assert raw.ndim == 3 assert raw.dtype == numpy.uint8 f.close() app = QApplication([]) v = Viewer() direct = True raw.shape = (1, ) + raw.shape + (1, ) def addLayers(v, direct): l1 = v.addGrayscaleLayer(raw, name="raw direct=%r" % direct, direct=direct) l1.visible = direct colortable = [QColor(0, 0, 0, 0).rgba(), QColor(255, 0, 0).rgba()] l2 = v.addColorTableLayer((raw > 128).astype(numpy.uint8), name="thresh direct=%r" % direct, colortable=colortable, direct=direct) l2.visible = direct return (l1, l2)
def __init__(self): Viewer.__init__(self) self.installEventFilter(self)
if len(args) != 1: parser.error("no hdf5 dataset supplied") x = args[0].find(".h5") fname = args[0][:x + 3] gname = args[0][x + 4:] # load data f = h5py.File(fname, "r") raw = f[gname].value assert raw.ndim == 3 assert raw.dtype == numpy.uint8 f.close() app = QApplication([]) v = Viewer() direct = True raw.shape = (1, ) + raw.shape + (1, ) l1 = v.addGrayscaleLayer(raw, name="raw", direct=True) l1.visible = direct colortable = [ QColor(0, 0, 0, 0).rgba(), QColor(255, 0, 0).rgba(), QColor(0, 255, 0).rgba(), QColor(0, 0, 255).rgba() ] s = ((raw // 64)).astype(numpy.uint8)
gt = vigra.readHDF5("/home/stamylew/volumes/groundtruth/dense_groundtruth/100p_cube1_dense_gt.h5", "data") from volumina.api import Viewer from volumina.pixelpipeline.datasources import LazyflowSource import sys from lazyflow.graph import Graph from lazyflow.operators.ioOperators.opStreamingHdf5Reader import OpStreamingHdf5Reader from lazyflow.operators import OpCompressedCache from PyQt4.QtGui import QApplication app = QApplication(sys.argv) v = Viewer() #raw layer v.addGrayscaleLayer(raw, name="test") #predict layer #predict = np.array(predict[:,:,:,0,0]) * 255 #v.addColorTableLayer(predict.astype(np.float32), name="prediction") v.addGrayscaleLayer(predict.astype(np.float32), name="org") #trimap layer tm = np.array(tm)*255 print np.unique(tm) #v.addColorTableLayer(tm.astype(np.float32), name="trimap") #v.addGrayscaleLayer(tm.astype(np.float32), name="tm")