Exemple #1
0
def removeParticles(fp, removeList, comm, size, rank):
    [row, col, numFrames, frameList] = misc.getVitals(fp)
    particleList = fp.attrs['particleList']
    zfillVal = fp.attrs['zfillVal']
    procFrameList = numpy.array_split(frameList, size)
    for frame in procFrameList[rank]:
        labelImg = fp['/segmentation/labelStack/' +
                      str(frame).zfill(zfillVal)].value
        for r in removeList:
            labelImg[labelImg == r] = 0
        numpy.save(str(frame).zfill(zfillVal) + '.npy', labelImg)
    comm.Barrier()

    if (rank == 0):
        for frame in frameList:
            labelImg = numpy.load(str(frame).zfill(zfillVal) + '.npy')
            fileIO.writeH5Dataset(
                fp, '/segmentation/labelStack/' + str(frame).zfill(zfillVal),
                labelImg)
            fileIO.delete(str(frame).zfill(zfillVal) + '.npy')
        for r in removeList:
            fp.attrs['particleList'] = numpy.delete(
                fp.attrs['particleList'],
                numpy.where(fp.attrs['particleList'] == r))
    comm.Barrier()
    return 0
def globalRelabelParticles(fp, correctionList, comm, size, rank):
    [row, col, numFrames, frameList] = misc.getVitals(fp)
    particleList = fp.attrs['particleList']
    zfillVal = fp.attrs['zfillVal']
    procFrameList = numpy.array_split(frameList, size)
    for frame in procFrameList[rank]:
        labelImg = fp['/segmentation/labelStack/' +
                      str(frame).zfill(zfillVal)].value
        for i in range(len(correctionList)):
            for j in range(len(correctionList[i]) - 1):
                labelImg[labelImg == correctionList[i]
                         [j]] = correctionList[i][-1]
        numpy.save(str(frame).zfill(zfillVal) + '.npy', labelImg)
    comm.Barrier()

    if (rank == 0):
        for frame in frameList:
            labelImg = numpy.load(str(frame).zfill(zfillVal) + '.npy')
            fileIO.writeH5Dataset(
                fp, '/segmentation/labelStack/' + str(frame).zfill(zfillVal),
                labelImg)
            fileIO.delete(str(frame).zfill(zfillVal) + '.npy')
            particleInFrame = numpy.unique(labelImg)[1:]
            if (frame == frameList[0]):
                particleList = particleInFrame.copy()
            else:
                particleList = numpy.unique(
                    numpy.append(particleList, particleInFrame))
        fp.attrs['particleList'] = particleList
    comm.Barrier()
    return 0
Exemple #3
0
def relabelParticles(fp, comm, size, rank):
    [row, col, numFrames, frameList] = misc.getVitals(fp)
    particleList = fp.attrs['particleList']
    zfillVal = fp.attrs['zfillVal']
    procFrameList = numpy.array_split(frameList, size)

    maxLabel = numpy.max(particleList) + 1
    counter = 1

    newLabels = {}
    for particle in particleList:
        newLabels[particle] = []

    for frame in frameList:
        particlesInFrame = numpy.unique(
            fp['/segmentation/labelStack/' +
               str(frame).zfill(zfillVal)].value)[1:]
        for p in particlesInFrame:
            if not newLabels[p]:
                newLabels[p] = [maxLabel, counter]
                maxLabel += 1
                counter += 1

    for frame in procFrameList[rank]:
        labelImg = fp['/segmentation/labelStack/' +
                      str(frame).zfill(zfillVal)].value
        for key in newLabels.keys():
            labelImg[labelImg == key] = newLabels[key][0]
        for key in newLabels.keys():
            labelImg[labelImg == newLabels[key][0]] = newLabels[key][1]
        numpy.save(str(frame).zfill(zfillVal) + '.npy', labelImg)
    comm.Barrier()

    if (rank == 0):
        for frame in frameList:
            labelImg = numpy.load(str(frame).zfill(zfillVal) + '.npy')
            if (counter < 256):
                labelImg = labelImg.astype('uint8')
            elif (counter < 65536):
                labelImg = labelImg.astype('uint16')
            else:
                labelImg = labelImg.astype('uint32')
            fileIO.writeH5Dataset(
                fp, '/segmentation/labelStack/' + str(frame).zfill(zfillVal),
                labelImg)
            fileIO.delete(str(frame).zfill(zfillVal) + '.npy')
            particleInFrame = numpy.unique(labelImg)[1:]
            if (frame == frameList[0]):
                particleList = particleInFrame.copy()
            else:
                particleList = numpy.unique(
                    numpy.append(particleList, particleInFrame))
        fp.attrs['particleList'] = particleList
    comm.Barrier()
    return 0
Exemple #4
0
def framewiseRelabelParticles(fp, frameWiseCorrectionList, comm, size, rank):
    [row, col, numFrames, frameList] = misc.getVitals(fp)
    particleList = fp.attrs['particleList']
    zfillVal = fp.attrs['zfillVal']
    procFrameList = numpy.array_split(frameList, size)

    for frame in procFrameList[rank]:
        labelImg = fp['/segmentation/labelStack/' +
                      str(frame).zfill(zfillVal)].value
        for frameWiseCorrection in frameWiseCorrectionList:
            subFrameList, subCorrectionList = frameWiseCorrection[
                0], frameWiseCorrection[1]
            for subFrame in subFrameList:
                if (frame == subFrame):
                    newLabel = subCorrectionList[-1]
                    for oldLabel in subCorrectionList[:-1]:
                        labelImg[labelImg == oldLabel] = newLabel
        numpy.save(str(frame).zfill(zfillVal) + '.npy', labelImg)
    comm.Barrier()

    if (rank == 0):
        for frame in frameList:
            labelImg = numpy.load(str(frame).zfill(zfillVal) + '.npy')
            fileIO.writeH5Dataset(
                fp, '/segmentation/labelStack/' + str(frame).zfill(zfillVal),
                labelImg)
            fileIO.delete(str(frame).zfill(zfillVal) + '.npy')
            particleInFrame = numpy.unique(labelImg)[1:]
            if (frame == frameList[0]):
                particleList = particleInFrame.copy()
            else:
                particleList = numpy.unique(
                    numpy.append(particleList, particleInFrame))
        fp.attrs['particleList'] = particleList
    comm.Barrier()
    return 0
Exemple #5
0
        '.png', finalImg)
outFile.close()
fp.flush(), fp.close()
comm.Barrier()

if (rank == 0):
    for r in range(size):
        if (r == 0):
            measures = numpy.loadtxt(outputDir + '/segmentation_' + str(r) +
                                     '.dat')
        else:
            measures = numpy.row_stack(
                (measures,
                 numpy.loadtxt(outputDir + '/segmentation_' + str(r) +
                               '.dat')))
        fileIO.delete(outputDir + '/segmentation_' + str(r) + '.dat')
    numpy.savetxt(outputDir + '/segmentation.dat', measures, fmt='%.6f')
comm.Barrier()
#######################################################################

#######################################################################
# CREATE BINARY IMAGES INTO HDF5 FILE
#######################################################################
if (rank == 0):
    print "Creating binary images from segmented images"

if (rank == 0):
    fp = h5py.File(outputFile, 'r+')
else:
    fp = h5py.File(outputFile, 'r')
[row, col, numFrames, frameList] = misc.getVitals(fp)
        '.png', finalImg)
outFile.close()
fp.flush(), fp.close()
comm.Barrier()

if (rank == 0):
    for r in range(size):
        if (r == 0):
            measures = numpy.loadtxt(outputDir + '/segmentation_' + str(r) +
                                     '.dat')
        else:
            measures = numpy.row_stack(
                (measures,
                 numpy.loadtxt(outputDir + '/segmentation_' + str(r) +
                               '.dat')))
        fileIO.delete(outputDir + '/segmentation_' + str(r) + '.dat')
    numpy.savetxt(outputDir + '/segmentation.dat', measures, fmt='%.6f')
comm.Barrier()
#######################################################################

#######################################################################
# CREATE BINARY IMAGES INTO HDF5 FILE
#######################################################################
#if (rank==0):
#print "Creating binary images from segmented images"

#if (rank==0):
#fp = h5py.File(outputFile, 'r+')
#else:
#fp = h5py.File(outputFile, 'r')
#[row,col,numFrames,frameList] = misc.getVitals(fp)