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 mulConst3D(imIn, v, imOut): """ Multiplies 'imIn' pixel values with value 'v' and puts the result in 'imOut'. The operation can be sum up in the following formula: imOut = imIn * v The operation is saturated for greyscale images. You cannot use it with binary images. """ outl = len(imOut) inl = len(imIn) if inl!=outl: mamba.raiseExceptionOnError(core.MB_ERR_BAD_SIZE) for i in range(outl): mamba.mulConst(imIn[i], v, imOut[i])
def mulConst3D(imIn, v, imOut): """ Multiplies 'imIn' pixel values with value 'v' and puts the result in 'imOut'. The operation can be sum up in the following formula: imOut = imIn * v The operation is saturated for greyscale images. You cannot use it with binary images. """ outl = len(imOut) inl = len(imIn) if inl != outl: mamba.raiseExceptionOnError(core.MB_ERR_BAD_SIZE) for i in range(outl): mamba.mulConst(imIn[i], v, imOut[i])