def volumeLabelling(imIn1, imIn2, imOut): """ Each connected component of the binary image or the partition 'imIn1' is labelled with the volume of the greyscale or 32-bit image 'imIn2' inside this component. The result is put in the 32-bit image 'imOut'. """ imWrk1 = mamba.imageMb(imIn1, 1) imWrk2 = mamba.imageMb(imIn1, 32) imWrk3 = mamba.imageMb(imIn1, 8) imOut.reset() n = imIn2.getDepth() # Case of a 8-bit image. if n == 8: for i in range(8): # Each bit plane is extracted and used in the labelling. mamba.copyBitPlane(imIn2, i, imWrk1) measureLabelling(imIn1, imWrk1, imWrk2) # The resulting labels are combined to obtain the final one. v = 2 ** i mamba.mulConst(imWrk2, v, imWrk2) mamba.add(imOut, imWrk2, imOut) else: for j in range(4): # Each byte plane is treated. mamba.copyBytePlane(imIn2, j, imWrk3) for i in range(8): mamba.copyBitPlane(imWrk3, i, imWrk1) measureLabelling(imIn1, imWrk1, imWrk2) v = 2 ** (8 * j + i) mamba.mulConst(imWrk2, v, imWrk2) mamba.add(imOut, imWrk2, imOut)
def volumeLabelling(imIn1, imIn2, imOut): """ Each connected component of the binary image or the partition 'imIn1' is labelled with the volume of the greyscale or 32-bit image 'imIn2' inside this component. The result is put in the 32-bit image 'imOut'. """ imWrk1 = mamba.imageMb(imIn1, 1) imWrk2 = mamba.imageMb(imIn1, 32) imWrk3 = mamba.imageMb(imIn1, 8) imOut.reset() n = imIn2.getDepth() # Case of a 8-bit image. if n == 8: for i in range(8): # Each bit plane is extracted and used in the labelling. mamba.copyBitPlane(imIn2, i, imWrk1) measureLabelling(imIn1, imWrk1, imWrk2) # The resulting labels are combined to obtain the final one. v = 2**i mamba.mulConst(imWrk2, v, imWrk2) mamba.add(imOut, imWrk2, imOut) else: for j in range(4): # Each byte plane is treated. mamba.copyBytePlane(imIn2, j, imWrk3) for i in range(8): mamba.copyBitPlane(imWrk3, i, imWrk1) measureLabelling(imIn1, imWrk1, imWrk2) v = 2**(8 * j + i) mamba.mulConst(imWrk2, v, imWrk2) mamba.add(imOut, imWrk2, imOut)
def copyBitPlane3D(imIn, plane, imOut): """ Inserts or extracts a bit plane in a 3D image. If 'imIn' is a binary image, it is inserted at 'plane' position in greyscale 'imOut'. If 'imIn' is a greyscale image, its bit plane at 'plane' position is extracted and put into binary image 'imOut'. Plane values are 0 (LSB) to 7 (MSB). """ outl = len(imOut) inl = len(imIn) if inl!=outl: mamba.raiseExceptionOnError(core.MB_ERR_BAD_SIZE) for i in range(outl): mamba.copyBitPlane(imIn[i], plane, imOut[i])
def copyBitPlane3D(imIn, plane, imOut): """ Inserts or extracts a bit plane in a 3D image. If 'imIn' is a binary image, it is inserted at 'plane' position in greyscale 'imOut'. If 'imIn' is a greyscale image, its bit plane at 'plane' position is extracted and put into binary image 'imOut'. Plane values are 0 (LSB) to 7 (MSB). """ outl = len(imOut) inl = len(imIn) if inl != outl: mamba.raiseExceptionOnError(core.MB_ERR_BAD_SIZE) for i in range(outl): mamba.copyBitPlane(imIn[i], plane, imOut[i])