예제 #1
0
def applyPredThresh(pixels):
    # zero removal for quantile computation
    nonzp = pixels[np.any(pixels, 1)]        
    counts = {c:np.bincount(nonzp[:,c], minlength=256) for c in colors}
    qs     = {c : 
              countQuantiles(counts[c], iles) for c in colors}

    # clunky:
    qDict = {"R8D": qs[R][0], "R9D": qs[R][1],
             "G8D": qs[G][0], "G9D": qs[G][1],
             "B8D": qs[B][0], "B9D": qs[B][1]}

    predictedThreshes = \
             dict((c, applyCurrentLM(qDict, c)) for c in colorNames)
    # print ",".join("%5.4f" % t for t in predictedThresholds.values())
    thresholdNDArray(pixels, predictedThreshes, dropSaturated=True)
예제 #2
0
def applyPredThresh(pixels):
    # zero removal for quantile computation
    nonzp = pixels[np.any(pixels, 1)]
    counts = {c: np.bincount(nonzp[:, c], minlength=256) for c in colors}
    qs = {c: countQuantiles(counts[c], iles) for c in colors}

    # clunky:
    qDict = {
        "R8D": qs[R][0],
        "R9D": qs[R][1],
        "G8D": qs[G][0],
        "G9D": qs[G][1],
        "B8D": qs[B][0],
        "B9D": qs[B][1]
    }

    predictedThreshes = \
             dict((c, applyCurrentLM(qDict, c)) for c in colorNames)
    # print ",".join("%5.4f" % t for t in predictedThresholds.values())
    thresholdNDArray(pixels, predictedThreshes, dropSaturated=True)
예제 #3
0
    predictedThreshes = \
             dict((c, applyCurrentLM(qDict, c)) for c in colorNames)
    # print ",".join("%5.4f" % t for t in predictedThresholds.values())
    thresholdNDArray(pixels, predictedThreshes, dropSaturated=True)


origFilename = osp.join(imageDataPath,
                        "Endosomes/10minend/ser3/10m60xendser31.TIF")

expThreshes = {"R": 17, "G": 41, "B": 34}

currentImage = Image.open(origFilename)

# get base arrays
asArray = {}
asArray['exp'] = fromimage(currentImage).reshape((numImagePoints, 3))
asArray['pred'] = asArray['exp'].copy()

# apply thresholds
thresholdNDArray(asArray['exp'], expThreshes, dropSaturated=True)
applyPredThresh(asArray['pred'])

# reconstruct images and write out
outputPath = "/home/mfenner/scipy_prep/final-images"

for name, arr in asArray.items():
    #     outImage = Image.merge(currentImage.mode, (arr[R], arr[G], arr[B]))
    outImage = Image.fromarray(arr.astype(np.uint8).reshape((1024, 1024, 3)))
    outImage.save(
        osp.join(outputPath, "10minEndosomeSeries3Slice1-" + name + ".tif"))
    print cnd

    stackArray = np.empty((0,3), np.uint8)
    for threshes in thisCndSet:
        print threshes["Slice"],
        expertThresholds = dict(((c, threshes[c]) for c in colorNames))

        #
        # get file->image and thresholds together
        # apply threshold
        #
        exampleFilename = fileNameFormat[threshes["Organelle"]] % threshes
        currentImage = Image.open(imageDataPath+exampleFilename)

        asArray2 = fromimage(currentImage).reshape((numImagePoints,3))
        thresholdNDArray(asArray2, expertThresholds)

        stackArray = np.concatenate((stackArray, asArray2))

    # zero removal
    currAllPixelCt     = stackArray.shape[0]
    stackArray = stackArray[np.any(stackArray, 1)]

    currNonZeroPixelCt = stackArray.shape[0]
    print "(%d --> %d)" % (currAllPixelCt, currNonZeroPixelCt)
    
    allPixelCt     += currAllPixelCt
    nonZeroPixelCt += currNonZeroPixelCt


print "%15s: %12s" % ("with [0,0,0]",    allPixelCt)
            {"15m60xendser301.TIF",
             "15m60xendser301.TIF",
             "15m60xendser301.TIF",
             "120m60xac17ser24.TIF",
             "120m60xac17ser27.TIF"}:
            print ".....skipping:"
            continue
        
        currentImage = Image.open(imageDataPath+exampleFilename)
        pixels = fromimage(currentImage).reshape((numImagePoints,3))        
        # zero removal
        if REMOVE_ZEROS:
            pixels = pixels[np.any(pixels, 1)]        
        counts = {c:np.bincount(pixels[:,c], minlength=256) for c in colors}
        qs     = {c : 
                  countQuantiles(counts[c], iles) for c in colors}
        # import pdb; pdb.set_trace()
        
        # clunky:
        qDict = {"R8D": qs[R][0], "R9D": qs[R][1],
                 "G8D": qs[G][0], "G9D": qs[G][1],
                 "B8D": qs[B][0], "B9D": qs[B][1]}

        predictedThresholds = \
                 dict((c, applyCurrentLM(qDict, c)) for c in colorNames)
        print ",".join("%5.4f" % t for t in predictedThresholds.values())
        thresholdNDArray(pixels, predictedThresholds)

        stackArray = np.concatenate((stackArray, pixels))
        
예제 #6
0
    predictedThreshes = \
             dict((c, applyCurrentLM(qDict, c)) for c in colorNames)
    # print ",".join("%5.4f" % t for t in predictedThresholds.values())
    thresholdNDArray(pixels, predictedThreshes, dropSaturated=True)

origFilename = osp.join(imageDataPath, 
                        "Endosomes/10minend/ser3/10m60xendser31.TIF")

expThreshes = {"R":17, "G":41, "B":34}

currentImage = Image.open(origFilename)

# get base arrays
asArray = {}
asArray['exp'] = fromimage(currentImage).reshape((numImagePoints,3))
asArray['pred'] = asArray['exp'].copy()

# apply thresholds
thresholdNDArray(asArray['exp'], expThreshes, dropSaturated=True)
applyPredThresh(asArray['pred'])

# reconstruct images and write out
outputPath = "/home/mfenner/scipy_prep/final-images"

for name, arr in asArray.items():
    #     outImage = Image.merge(currentImage.mode, (arr[R], arr[G], arr[B]))
    outImage = Image.fromarray(arr.astype(np.uint8).reshape((1024,1024,3)))
    outImage.save(osp.join(outputPath, 
                           "10minEndosomeSeries3Slice1-"+name+".tif"))
    print cnd

    stackArray = np.empty((0, 3), np.uint8)
    for threshes in thisCndSet:
        print threshes["Slice"],
        expertThresholds = dict(((c, threshes[c]) for c in colorNames))

        #
        # get file->image and thresholds together
        # apply threshold
        #
        exampleFilename = fileNameFormat[threshes["Organelle"]] % threshes
        currentImage = Image.open(imageDataPath + exampleFilename)

        asArray2 = fromimage(currentImage).reshape((numImagePoints, 3))
        thresholdNDArray(asArray2, expertThresholds)

        stackArray = np.concatenate((stackArray, asArray2))

    # zero removal
    currAllPixelCt = stackArray.shape[0]
    stackArray = stackArray[np.any(stackArray, 1)]

    currNonZeroPixelCt = stackArray.shape[0]
    print "(%d --> %d)" % (currAllPixelCt, currNonZeroPixelCt)

    allPixelCt += currAllPixelCt
    nonZeroPixelCt += currNonZeroPixelCt

print "%15s: %12s" % ("with [0,0,0]", allPixelCt)
print "%15s: %12s" % ("removed [0,0,0]", nonZeroPixelCt)
예제 #8
0
             "120m60xac17ser24.TIF",
             "120m60xac17ser27.TIF"}:
            print ".....skipping:"
            continue

        currentImage = Image.open(imageDataPath + exampleFilename)
        pixels = fromimage(currentImage).reshape((numImagePoints, 3))
        # zero removal
        if REMOVE_ZEROS:
            pixels = pixels[np.any(pixels, 1)]
        counts = {c: np.bincount(pixels[:, c], minlength=256) for c in colors}
        qs = {c: countQuantiles(counts[c], iles) for c in colors}
        # import pdb; pdb.set_trace()

        # clunky:
        qDict = {
            "R8D": qs[R][0],
            "R9D": qs[R][1],
            "G8D": qs[G][0],
            "G9D": qs[G][1],
            "B8D": qs[B][0],
            "B9D": qs[B][1]
        }

        predictedThresholds = \
                 dict((c, applyCurrentLM(qDict, c)) for c in colorNames)
        print ",".join("%5.4f" % t for t in predictedThresholds.values())
        thresholdNDArray(pixels, predictedThresholds)

        stackArray = np.concatenate((stackArray, pixels))
            if applyPredThresholds:
                # zero removal for quantile computation
                pixels = pixels[np.any(pixels, 1)]        
                counts = {c:np.bincount(pixels[:,c], 
                                        minlength=256) for c in colors}
                qs     = {c:countQuantiles(counts[c], iles) for c in colors}

                # clunky:
                qDict = {"R8D": qs[R][0], "R9D": qs[R][1],
                         "G8D": qs[G][0], "G9D": qs[G][1],
                         "B8D": qs[B][0], "B9D": qs[B][1]}

                predThreshes = dict((c, applyCurrentLM(qDict, 
                                                       c)) for c in colorNames)
                # print ",".join("%5.4f" % t for t in predThresholds.values())
                thresholdNDArray(pixels, predThreshes, dropSaturated=True)

            expArray = np.concatenate((expArray, pixels))
#########################################
# all to here is necessary to get joined series
#########################################

    org = simplifyOrgStain(cnd["Organelle"], cnd["Stain"])
    t = timeToIdx(cnd["Time"])

    print org, t

    # convert image stack to counts and add to histograms
    for c1, c2 in colorPairs:
        probs = toProbs(expArray[:,c1], expArray[:,c2],
                        removeNonresponders = removeNonresponders,