Ejemplo n.º 1
0
def mosaicGradient3D(imIn, imOut, grid=m3D.DEFAULT_GRID3D):
    """
    Builds the mosaic-gradient 3D image of 'imIn' and puts the result in 'imOut'.
    The mosaic-gradient image is built by computing the differences of two
    mosaic images generated from 'imIn', the first one having its watershed
    lines valued by the suprema of the adjacent catchment basins values, the
    second one been valued by the infima.
    """
    
    imWrk1 = m3D.image3DMb(imIn)
    imWrk2 = m3D.image3DMb(imIn)
    imWrk3 = m3D.image3DMb(imIn)
    imWrk4 = m3D.image3DMb(imIn)
    imWrk5 = m3D.image3DMb(imIn)
    mosaic3D(imIn, imWrk2, imWrk3, grid=grid)
    m3D.sub3D(imWrk2, imWrk3, imWrk1)
    m3D.logic3D(imWrk2, imWrk3, imWrk2, "sup")
    m3D.negate3D(imWrk2, imWrk2)
    se = m3D.structuringElement3D(m3D.getDirections3D(grid), grid)
    while m3D.computeVolume3D(imWrk3) != 0:
        m3D.dilate3D(imWrk1, imWrk4, 2, se=se)
        m3D.dilate3D(imWrk2, imWrk5, 2, se=se)
        m3D.logic3D(imWrk4, imWrk3, imWrk4, "inf")
        m3D.logic3D(imWrk5, imWrk3, imWrk5, "inf")
        m3D.logic3D(imWrk1, imWrk4, imWrk1, "sup")
        m3D.logic3D(imWrk2, imWrk5, imWrk2, "sup")
        m3D.erode3D(imWrk3, imWrk3, 2, se=se)
    m3D.negate3D(imWrk2, imWrk2)
    m3D.sub3D(imWrk1, imWrk2, imOut)
Ejemplo n.º 2
0
def mosaicGradient3D(imIn, imOut, grid=m3D.DEFAULT_GRID3D):
    """
    Builds the mosaic-gradient 3D image of 'imIn' and puts the result in 'imOut'.
    The mosaic-gradient image is built by computing the differences of two
    mosaic images generated from 'imIn', the first one having its watershed
    lines valued by the suprema of the adjacent catchment basins values, the
    second one been valued by the infima.
    """

    imWrk1 = m3D.image3DMb(imIn)
    imWrk2 = m3D.image3DMb(imIn)
    imWrk3 = m3D.image3DMb(imIn)
    imWrk4 = m3D.image3DMb(imIn)
    imWrk5 = m3D.image3DMb(imIn)
    mosaic3D(imIn, imWrk2, imWrk3, grid=grid)
    m3D.sub3D(imWrk2, imWrk3, imWrk1)
    m3D.logic3D(imWrk2, imWrk3, imWrk2, "sup")
    m3D.negate3D(imWrk2, imWrk2)
    se = m3D.structuringElement3D(m3D.getDirections3D(grid), grid)
    while m3D.computeVolume3D(imWrk3) != 0:
        m3D.dilate3D(imWrk1, imWrk4, 2, se=se)
        m3D.dilate3D(imWrk2, imWrk5, 2, se=se)
        m3D.logic3D(imWrk4, imWrk3, imWrk4, "inf")
        m3D.logic3D(imWrk5, imWrk3, imWrk5, "inf")
        m3D.logic3D(imWrk1, imWrk4, imWrk1, "sup")
        m3D.logic3D(imWrk2, imWrk5, imWrk2, "sup")
        m3D.erode3D(imWrk3, imWrk3, 2, se=se)
    m3D.negate3D(imWrk2, imWrk2)
    m3D.sub3D(imWrk1, imWrk2, imOut)
Ejemplo n.º 3
0
 def updateim(self):
     # Updates the display (perform a rendering)
     depth = self.im_ref().getDepth()
     volume = 0
     if depth == 1:
         # binary 3D image
         self.planeLabel.config(text="")
         im8 = mamba.imageMb(self.W, self.H, 8)
         self.raw = b""
         for im2D in self.im_ref():
             mamba.convert(im2D, im8)
             self.raw += im8.extractRaw()
             volume += mamba.computeVolume(im2D)
     elif depth == 32:
         # 32-bit 3D image
         if self.master.bplane == 4:
             self.planeLabel.config(text="Plane : all")
             im3D_8 = m3D.image3DMb(self.im_ref(), 8)
             m3D.convert3D(self.im_ref(), im3D_8)
             self.raw = im3D_8.extractRaw()
             volume = m3D.computeVolume3D(self.im_ref())
         else:
             self.planeLabel.config(text="Plane : %d" %
                                    (self.master.bplane))
             im8 = mamba.imageMb(self.W, self.H, 8)
             self.raw = b""
             for im2D in self.im_ref():
                 mamba.copyBytePlane(im2D, self.master.bplane, im8)
                 self.raw += im8.extractRaw()
                 volume += mamba.computeVolume(im2D)
     else:
         # Greyscale image
         self.planeLabel.config(text="")
         self.raw = self.im_ref().extractRaw()
         volume = m3D.computeVolume3D(self.im_ref())
     self.setImagePlaneZ()
     self.setImagePlaneY()
     self.setImagePlaneX()
     self.planex.eraseTarget()
     self.planey.eraseTarget()
     self.planez.eraseTarget()
     self.volLabel.config(text="Volume : %d" % (volume))
     value = self.im_ref().getPixel((self.x, self.y, self.z))
     self.posLabel.config(text="At (%d,%d,%d) = %d" %
                          (self.x, self.y, self.z, value))
Ejemplo n.º 4
0
 def updateim(self):
     # Updates the display (perform a rendering)
     depth = self.im_ref().getDepth()
     volume = 0
     if depth==1:
         # binary 3D image
         self.planeLabel.config(text="")
         im8 = mamba.imageMb(self.W, self.H, 8)
         self.raw = b""
         for im2D in self.im_ref():
             mamba.convert(im2D, im8)
             self.raw += im8.extractRaw()
             volume += mamba.computeVolume(im2D)
     elif depth==32:
         # 32-bit 3D image
         if self.master.bplane==4:
             self.planeLabel.config(text="Plane : all")
             im3D_8 = m3D.image3DMb(self.im_ref(), 8)
             m3D.convert3D(self.im_ref(), im3D_8)
             self.raw = im3D_8.extractRaw()
             volume = m3D.computeVolume3D(self.im_ref())
         else:
             self.planeLabel.config(text="Plane : %d" % (self.master.bplane))
             im8 = mamba.imageMb(self.W, self.H, 8)
             self.raw = b""
             for im2D in self.im_ref():
                 mamba.copyBytePlane(im2D, self.master.bplane, im8)
                 self.raw += im8.extractRaw()
                 volume += mamba.computeVolume(im2D)
     else:
         # Greyscale image
         self.planeLabel.config(text="")
         self.raw = self.im_ref().extractRaw()
         volume = m3D.computeVolume3D(self.im_ref())
     self.setImagePlaneZ()
     self.setImagePlaneY()
     self.setImagePlaneX()
     self.planex.eraseTarget()
     self.planey.eraseTarget()
     self.planez.eraseTarget()
     self.volLabel.config(text="Volume : %d" % (volume))
     value = self.im_ref().getPixel((self.x, self.y, self.z))
     self.posLabel.config(text="At (%d,%d,%d) = %d" % (self.x,self.y,self.z,value))
Ejemplo n.º 5
0
 def _convertIntoVTKImage(self):
     # Converts the associated sequence into a VTK image
     # structure to be able to display it using the rendering
     # mechanisms of VTK
     W, H, L = self.im_ref().getSize()
     depth = self.im_ref().getDepth()
 
     if depth==8:
         # 8-bit 3D image
         self.planeLabel.config(text="")
         raw_data = self.im_ref().extractRaw()
     elif depth==32:
         # 32-bit 3D image
         im3D_8 = m3D.image3DMb(self.im_ref(), 8)
         if self.master.bplane==4:
             self.planeLabel.config(text="Plane : all")
             m3D.convert3D(self.im_ref(), im3D_8)
         else:
             self.planeLabel.config(text="Plane : %d" % (self.master.bplane))
             m3D.copyBytePlane3D(self.im_ref(), self.master.bplane, im3D_8)
         raw_data = im3D_8.extractRaw()
     else:
         # binary 3D image
         self.planeLabel.config(text="")
         im8 = mamba.imageMb(W, H, 8)
         raw_data = b""
         for im2D in self.im_ref():
             mamba.convert(im2D, im8)
             raw_data += im8.extractRaw()
     volume = m3D.computeVolume3D(self.im_ref())
     self.vtk_im.CopyImportVoidPointer(raw_data, len(raw_data))
         
     self.vtk_im.SetNumberOfScalarComponents(1)
     extent = self.vtk_im.GetDataExtent()
     self.vtk_im.SetDataExtent(extent[0], extent[0] + W - 1,
                               extent[2], extent[2] + H - 1,
                               extent[4], extent[4] + L - 1)
     self.vtk_im.SetWholeExtent(extent[0], extent[0] + W - 1,
                                extent[2], extent[2] + H - 1,
                                extent[4], extent[4] + L - 1)
     self.volLabel.config(text="Volume = %d" % (volume))
Ejemplo n.º 6
0
 def updateim(self):
     # Updates the display (perform a rendering)
     volume = m3D.computeVolume3D(self.im_ref())
     if self.im_ref().getDepth()==32:
         immb = mamba.imageMb(self.im_ref()[self.z], 8)
         if self.master.bplane==4:
             mamba.convert(self.im_ref()[self.z], immb)
             self.planeLabel.config(text="Plane : all")
         else:
             mamba.copyBytePlane(self.im_ref()[self.z],self.master.bplane,immb)
             self.planeLabel.config(text="Plane : %d" % (self.master.bplane))
         im = utils.convertToPILFormat(immb.mbIm)
     else:
         self.planeLabel.config(text="")
         im = utils.convertToPILFormat(self.im_ref()[self.z].mbIm)
     if self.master.palname:
         im.putpalette(palette.getPalette(self.master.palname))
     self.planez.display(im)
     self.volLabel.config(text="Volume : %d" % (volume))
     value = self.im_ref().getPixel((self.x, self.y, self.z))
     self.posLabel.config(text="At (%d,%d,%d) = %d" % (self.x, self.y, self.z,value))
Ejemplo n.º 7
0
 def updateim(self):
     # Updates the display (perform a rendering)
     volume = m3D.computeVolume3D(self.im_ref())
     if self.im_ref().getDepth() == 32:
         immb = mamba.imageMb(self.im_ref()[self.z], 8)
         if self.master.bplane == 4:
             mamba.convert(self.im_ref()[self.z], immb)
             self.planeLabel.config(text="Plane : all")
         else:
             mamba.copyBytePlane(self.im_ref()[self.z], self.master.bplane, immb)
             self.planeLabel.config(text="Plane : %d" % (self.master.bplane))
         im = utils.convertToPILFormat(immb.mbIm)
     else:
         self.planeLabel.config(text="")
         im = utils.convertToPILFormat(self.im_ref()[self.z].mbIm)
     if self.master.palname:
         im.putpalette(palette.getPalette(self.master.palname))
     self.planez.display(im)
     self.volLabel.config(text="Volume : %d" % (volume))
     value = self.im_ref().getPixel((self.x, self.y, self.z))
     self.posLabel.config(text="At (%d,%d,%d) = %d" % (self.x, self.y, self.z, value))