Пример #1
0
def createLabelColorBar():

    imp7 = ImagePlus("labelColorBar", ShortProcessor(180, 20))
    ip7 = imp7.getProcessor()
    pix = ip7.getPixels()
    n_pixels = len(pix)
    # catch width
    w = imp7.getWidth()
    # create a ramp gradient from left to right
    for i in range(len(pix)):
        pix[i] = int((i % w) / 18) + 1

    # adjust min and max
    ip7.setMinAndMax(0, 255)
    font = Font("SansSerif", Font.PLAIN, 12)
    overlay = Overlay()
    for i in range(len(pix)):

        roi = TextRoi(i * 18 + 2, 2, str(i + 1), font)
        roi.setStrokeColor(Color.black)
        overlay.add(roi)
        imp7.setOverlay(overlay)

    imp7.show()
    IJ.run("glasbey_on_dark")
    imp7 = imp7.flatten()

    return imp7
Пример #2
0
def generate_limit_labels(imp, limits, cb_fraction, params):
    """generate text ROIs in correct positions to label colorbar"""
    rois = []
    w = imp.getWidth()
    h = imp.getHeight()
    txt_h_px = float(h) / 15
    txt_sz_pt = int(round((18.0 / 24.0) * txt_h_px))
    for limit in limits:
        roi = TextRoi(1, 1, str(round(limit, 3)),
                      Font("SansSerif", Font.ITALIC, txt_sz_pt))
        roi.setJustification(TextRoi.RIGHT)
        roi.setFillColor(Color.BLACK)
        roi.setStrokeColor(Color.WHITE)
        rois.append(roi)
    roim = RoiManager(False)
    roim.reset()
    imp.show()
    mbui.autoset_zoom(imp)
    for fridx in range(1, imp.getNSlices() + 1):
        imp.setPosition(fridx)
        roi_uu = rois[1].clone()
        xpos = w - cb_fraction * w - float(w) / 100 - rois[1].getFloatWidth()
        roi_uu.setLocation(xpos, 1)
        imp.setRoi(roi_uu)
        roim.addRoi(roi_uu)
        roi_ll = rois[0].clone()
        roi_ll.setLocation(xpos, h - rois[0].getFloatHeight())
        imp.setRoi(roi_ll)
        roim.addRoi(roi_ll)
    roim.runCommand("Show All")
    FileSaver(imp).saveAsTiff(
        os.path.join(params.output_path,
                     "overlaid curvature nudged labels.tif"))
    # nudge positions
    roim.reset()
    imp.killRoi()
    for fridx in range(1, imp.getNSlices() + 1):
        imp.setPosition(fridx)
        roi_uu = rois[1].clone()
        xpos = w - cb_fraction * w - float(w) / 100
        roi_uu.setLocation(xpos, 1)
        imp.setRoi(roi_uu)
        roim.addRoi(roi_uu)
        roi_ll = rois[0].clone()
        roi_ll.setLocation(xpos, h - rois[0].getFloatHeight())
        imp.setRoi(roi_ll)
        roim.addRoi(roi_ll)
    roim.runCommand("Show All")
    FileSaver(imp).saveAsTiff(
        os.path.join(params.output_path, "overlaid curvature.tif"))
    return imp
Пример #3
0
def draw_scale(image, ticks):
    cal = image.getCalibration()
    overlay = Overlay()
    image.setOverlay(overlay)
    TextRoi.setGlobalJustification(TextRoi.CENTER)
    offset = image.getHeight() - extend
    for tick in ticks:
        tick_pos = cal.getRawX(tick)
        line = Line(tick_pos, offset, tick_pos, offset + font_size)
        line.setWidth(font_size // 8)
        line.setStrokeColor(Color(1.00, 1.00, 1.00))
        overlay.add(line)
        text = TextRoi(tick_pos, offset + font_size, str(tick), font)
        text_width = text.getFloatWidth()
        text_y = text.getYBase()
        text.setLocation(tick_pos - text_width/2, text_y)
        text.setStrokeColor(Color(1.00, 1.00, 1.00))
        overlay.add(text)
Пример #4
0
    def createMIP(self):
        print "starting createMIP"
        for a in self.itemSelected:
            ImStack = None
            for filename in self.dict1.get(a):
                self.savfileName = a
                if not filename.endswith(self.fileExt):
                    continue
                path = self.sourceDir + filename
                # Upon finding the first image, initialize the VirtualStack
                if ImStack is None:
                    imp = IJ.openImage(path)
                    ImStack = VirtualStack(imp.width, imp.height, None,
                                           self.sourceDir)
                # Add a slice, relative to the sourceDIr
                ImStack.addSlice(filename)
            #adding text overlay to output images so we can differentiate them. Overlay is non destructive - does not affect pixel values of image, and can be selected and deleted
            prefix_overlay = Overlay()
            font = Font("SansSerif", Font.PLAIN, 10)
            roi = TextRoi(0, 0, a)
            roi.setStrokeColor(Color(1.00, 1.00, 1.00))
            prefix_overlay.add(roi)
            #
            OnscreenImage = ImagePlus(self.sourceDir, ImStack)
            OnscreenImage.setOverlay(prefix_overlay)
            OnscreenImage.show()

            print "Generating MIP, waiting..."
            self.outimp = self.maxZprojection(
                OnscreenImage)  #generate max projection
            self.outimp.setOverlay(prefix_overlay)
            self.outimp.show()
            print "Max projection generated"
            if self.saveState == "Y":
                self.saveMIP()
            print "Finished!"
rt = ResultsTable.getResultsTable()
celli = 0
FONT = Font(Font.SANS_SERIF, Font.BOLD, 16)
for cell in cells_hoescht_opn:
    area = cell.getStatistics().area * cal.pixelWidth * cal.pixelHeight
    if area >= MINA and area <= MAXA:
        cell.setStrokeColor(Color.MAGENTA)
        ol.add(cell)

        edm_sca1_gfp.setRoi(cell)
        dist = edm_sca1_gfp.getStatistics().mean * cal.pixelWidth

        row = rt.getCounter()
        rect = cell.getBounds()
        rt.setValue("Image", row, imp.getTitle())
        rt.setValue("OPN+ Cell", row, celli)
        rt.setValue("X", row, (rect.x + rect.width / 2.0) * cal.pixelWidth)
        rt.setValue("Y", row, (rect.y + rect.height / 2.0) * cal.pixelHeight)
        rt.setValue(
            "OPN+ cell distance from SCA1+ GFP+ (" + u"\u00b5" + "m" + ")",
            row, dist)

        label = TextRoi(rect.x, rect.y - 16, str(celli), FONT)
        label.setStrokeColor(Color.MAGENTA)
        ol.add(label)

        celli += 1

rt.show("Results")
imp.setOverlay(ol)
Пример #6
0
impProc.setInterpolationMethod(ImageProcessor.NONE)
impProc = impProc.resize(canvasWidth,canvasHeight)
imp.setProcessor(impProc)
imp.show()

IJ.run(imp, "Rainbow RGB", "");
IJ.run(imp, "Canvas Size...", "width=800 height=1024 position=Top-Center zero");

testROI = Roi(0,canvasHeight,canvasWidth,6)
testROI.setFillColor(Color.WHITE)
imp.setRoi(testROI,True)

overlay = Overlay(testROI)
font = Font("SansSerif",Font.PLAIN,fontSize)

# Write the EmissionWavelengths according
# to the metadata read earlier.
for i in xrange(1,len(pixelInt2[0]),tickInterval):
    pixelSize = (canvasWidth/(len(pixelInt2[0])*1.0))
    calc      = (pixelSize)*(i)
    roi       = TextRoi(calc+(pixelSize*0.2),canvasHeight+10,str(emissionWL[i]),font)
    roi.setStrokeColor(Color(1.00, 1.00, 1.00));
    overlay.add(roi)

imp.setOverlay(overlay)
imp.show()
IJ.run(imp, "Calibration Bar...", "location=[Upper Right] fill=None label=White number=3 decimal=1 font=9 zoom=2 bold overlay");

# Saves the output file.
IJ.saveAs(imp,"png",hyperspaceImage)
Пример #7
0
            gfp.setStrokeColor(Color.MAGENTA)
            gfp.setPosition(0, z, 1)
            ol.add(gfp)

    gfpMean = gfpSum / gfpA if gfpA > 0 else 0

    row = rt.getCounter()

    uni = row % 26
    cha = chr(ord('A') + uni)
    name = ""
    while len(name) < (row + 1) / 26.0:
        name += cha

    label = TextRoi(name, cXbf - 20, cYbf + 20, FONT)
    label.setStrokeColor(Color.GREEN)
    label.setPosition(0, z, 1)
    ol.add(label)

    rt.setValue("Organoid", row, name)
    rt.setValue("X", row, cXbf * cal.pixelWidth)
    rt.setValue("Y", row, cYbf * cal.pixelHeight)
    rt.setValue("Area", row,
                roiStatsBF.area * cal.pixelWidth * cal.pixelHeight)
    rt.setValue("Contained Tomato Area", row,
                tomatoA * cal.pixelWidth * cal.pixelHeight)
    rt.setValue("Contained GFP Area", row,
                gfpA * cal.pixelWidth * cal.pixelHeight)
    rt.setValue("Contained GFP Mean", row, gfpMean)

imp.setOverlay(ol)
Пример #8
0
# 2014-11-25  JRM 1.1.00  Jython version of Create_Overlay.js

from org.python.core import codecs
codecs.setDefaultEncoding('utf-8')

from ij import IJ, ImagePlus, WindowManager
from ij.gui import Roi, TextRoi, Overlay, OvalRoi, Line, PolygonRoi
from java.awt import Color, Font

imp = IJ.openImage("http://imagej.nih.gov/ij/images/blobs.gif")

# create an overlay
ol = Overlay()
fnt = Font("SanSerif", Font.BOLD, 28)
roi = TextRoi(10, 5, "This is an overlay", fnt)
roi.setStrokeColor(Color.yellow)
roi.setFillColor(Color(0,0,0,0.5))
ol.add(roi)

roi = Roi(30,70,200,150)
roi.setStrokeColor(Color.blue)
roi.setFillColor(Color(0,0,1,0.3))
ol.add(roi)

roi = OvalRoi(60,60,140,140)
roi.setStrokeColor(Color.green)
roi.setStrokeWidth(15)
ol.add(roi)

roi = Line(30,70,230,230)
roi.setStrokeColor(Color.red)