def scaleImageUI():  
	gd = GenericDialog("Scale")  
	gd.addSlider("Scale", 1, 200, 100)  
	gd.addCheckbox("Preview", True)  
	# The UI elements for the above two inputs  
	slider = gd.getSliders().get(0) # the only one  
	checkbox = gd.getCheckboxes().get(0) # the only one  
	
	imp = WM.getCurrentImage()  
	if not imp:  
		print "Open an image first!"  
		return  
	
	previewer = ScalingPreviewer(imp, slider, checkbox)  
	slider.addAdjustmentListener(previewer)  
	checkbox.addItemListener(previewer)  
		
	gd.showDialog()  
	
	if gd.wasCanceled():  
		previewer.reset()  
		print "User canceled dialog!"  
	else:  
		previewer.scale()  
	
	previewer.destroy()  
def getOptions(imp):
  gd = GenericDialog("Correct 3D Drift Options")
  channels = []
  for ch in range(1, imp.getNChannels()+1 ):
    channels.append(str(ch))
  methods = ["phase_correlation","center_of_mass"]
  gd.addChoice("Channel for registration:", channels, channels[0])
  gd.addChoice("Method for registration:", methods, methods[1])
  gd.addNumericField("Background value:", 0, 0)
  gd.addCheckbox("Multi_time_scale computation for enhanced detection of slow drifts?", False)
  gd.addCheckbox("Sub_pixel drift correction (possibly needed for slow drifts)?", False)
  gd.addCheckbox("Edge_enhance images for possibly improved drift detection?", False)
  gd.addCheckbox("Use virtualstack for saving the results to disk to save RAM?", False)
  gd.addCheckbox("Drift correct only data inside ROI?", False)
  gd.addCheckbox("Only compute drift vectors?", False)
  gd.addMessage("If you put a ROI, drift will only be computed in this region;\n the ROI will be moved along with the drift to follow your structure of interest.")
  gd.addSlider("z_min of ROI", 1, imp.getNSlices(), 1)
  gd.addSlider("z_max of ROI", 1, imp.getNSlices(), imp.getNSlices())
  gd.showDialog()
  if gd.wasCanceled():
    return
  channel = gd.getNextChoiceIndex() + 1  # zero-based
  method = gd.getNextChoiceIndex() + 1  # zero-based
  bg_value = gd.getNextNumber()
  multi_time_scale = gd.getNextBoolean()
  subpixel = gd.getNextBoolean()
  process = gd.getNextBoolean()
  virtual = gd.getNextBoolean()
  only_roi = gd.getNextBoolean()
  only_compute = gd.getNextBoolean()
  roi_z_min = int(gd.getNextNumber())
  roi_z_max = int(gd.getNextNumber())
  return channel, method, bg_value, virtual, multi_time_scale, subpixel, process, only_roi, only_compute, roi_z_min, roi_z_max
Пример #3
0
def get_opts():
	gd = GenericDialog("setup plugin")
	#channels = map(lambda x: str(x), range(1,imp.getNChannels()+1))
	channels = ['1','2','3'];
	modes = ['batch mode', 'manual']
	gd.addChoice("processing mode",modes,modes[1])
	gd.addChoice("choose channel for pre-registration: ", channels, channels[0])
	gd.addChoice("choose channel for registration: ", channels, channels[2])
	gd.addChoice("channel for cell detection: ", channels, channels[1])
	gd.addChoice("channel for osteoblast detection: ", channels, channels[2])
	gd.addChoice("channel for vasculature detection: ", channels, channels[0])
#	gd.addNumericField("quantile for cell segmentation", 0.9995, 36)
	gd.addNumericField("rough cell size in microns", 15., 2)
#	gd.addSlider("minimal z depth (voxels) for detected cells", 1, imp.getNSlices()+1, 8)
	gd.addSlider("minimal z depth (voxels) for detected cells", 1,36, 5)
	gd.addSlider("minimal z depth (voxels) for detected cells", 1,36, 25)

	gd.addCheckbox("delete black frames (recommended)", True)
	gd.addChoice("channel to estimate black frames: ", channels, channels[2])
	gd.addCheckbox("rough registration of time series", True)
	gd.addCheckbox("descriptor-based registration of time series", True)
	gd.addCheckbox("detect cells", False)
	gd.addCheckbox("export osteoblast structures", False)
	gd.addCheckbox("export vasculature structures", False)
	gd.addCheckbox("save registered movie", True)
	gd.addCheckbox("delete temporary files", True)
	#gd.addCheckbox("show 3d vis", False)

	gd.showDialog()
	proc_mode = gd.getNextChoice()
	ch_pre = gd.getNextChoice()
	reg = gd.getNextChoice()
	cc = gd.getNextChoice()
	ost_ch = gd.getNextChoice()
	vasc_ch = gd.getNextChoice()
	#quantile = gd.getNextNumber()
	size = gd.getNextNumber()
	minz = gd.getNextNumber()
	zmax = gd.getNextNumber()
	del_black = gd.getNextBoolean();
	black_ch = gd.getNextChoice()
	preregflag = gd.getNextBoolean();
	regflag = gd.getNextBoolean()
	detect_cells = gd.getNextBoolean()
	struct_exp = gd.getNextBoolean()
	vasc_exp = gd.getNextBoolean()
	save_res = gd.getNextBoolean()
	del_tmp = gd.getNextBoolean()
	#vis = gd.getNextBoolean()

	return proc_mode, ch_pre, reg, cc, ost_ch, vasc_ch, size, minz, zmax, del_black, black_ch, preregflag, regflag, detect_cells, struct_exp, vasc_exp, save_res, del_tmp
def getOptions():
    gd = GenericDialog("Options")
    gd.addStringField("name", "Untitled")
    gd.addNumericField("alpha", 0.25, 2)  # show 2 decimals
    gd.addCheckbox("optimize", True)
    types = ["8-bit", "16-bit", "32-bit"]
    gd.addChoice("output as", types, types[2])
    gd.addSlider("scale", 1, 100, 100)
    gd.showDialog()
    #
    if gd.wasCanceled():
        print "User canceled dialog!"
        return
    # Read out the options
    name = gd.getNextString()
    alpha = gd.getNextNumber()
    optimize = gd.getNextBoolean()
    output = gd.getNextChoice()
    scale = gd.getNextNumber()
    return name, alpha, optimize, output, scale
Пример #5
0
    def setupDialog(imp):

        gd = GenericDialog("Collective migration buddy options")
        gd.addMessage("Collective migration buddy 2.0, you are analyzing: " +
                      imp.getTitle())
        calibration = imp.getCalibration()

        if (calibration.frameInterval > 0):
            default_interval = calibration.frameInterval
            default_timeunit = calibration.getTimeUnit()

        else:
            default_interval = 8
            default_timeunit = "min"

        gd.addNumericField("Frame interval:", default_interval,
                           2)  # show 2 decimals
        gd.addCheckbox("Do you want to use a gliding window?", True)
        gd.addCheckbox(
            "Project hyperStack? (defaluts to projecting current channel only)",
            False)
        gd.addStringField("time unit", default_timeunit, 3)
        gd.addSlider("Start compacting at frame:", 1, imp.getNFrames(), 1)
        gd.addSlider("Stop compacting at frame:", 1, imp.getNFrames(),
                     imp.getNFrames())
        gd.addNumericField("Number of frames to project in to one:", 3,
                           0)  # show 0 decimals

        gd.addChoice('Method to use for frame projection:', methods_as_strings,
                     methods_as_strings[5])

        gd.showDialog()

        if gd.wasCanceled():
            IJ.log("User canceled dialog!")
            return

        return gd
Пример #6
0
def run(title):
    gd = GenericDialog("Record Window")
    gd.addMessage("Maximum number of frames to record.\nZero means infinite, interrupt with ESC key.")
    gd.addNumericField("Max. frames:", 50, 0)
    gd.addNumericField("Milisecond interval:", 300, 0)
    gd.addSlider("Start in (seconds):", 0, 20, 5)
    frames = []
    titles = []
    for f in Frame.getFrames():
        if f.isEnabled() and f.isVisible():
            frames.append(f)
            titles.append(f.getTitle())
    gd.addChoice("Window:", titles, titles[0])
    gd.addCheckbox("To file", False)
    gd.showDialog()
    if gd.wasCanceled():
        return
    n_frames = int(gd.getNextNumber())
    interval = gd.getNextNumber() / 1000.0  # in seconds
    frame = frames[gd.getNextChoiceIndex()]
    delay = int(gd.getNextNumber())
    tofile = gd.getNextBoolean()

    dir = None
    if tofile:
        dc = DirectoryChooser("Directory to store image frames")
        dir = dc.getDirectory()
        if dir is None:
            return  # dialog canceled

    snaps = []
    borders = None
    executors = Executors.newFixedThreadPool(1)
    try:
        while delay > 0:
            IJ.showStatus("Starting in " + str(delay) + "s.")
            time.sleep(1)  # one second
            delay -= 1

        IJ.showStatus("Capturing frame borders...")
        bounds = frame.getBounds()
        robot = Robot()
        frame.toFront()
        time.sleep(0.5)  # half a second
        borders = robot.createScreenCapture(bounds)

        IJ.showStatus("Recording " + frame.getTitle())

        # Set box to the inside borders of the frame
        insets = frame.getInsets()
        box = bounds.clone()
        box.x = insets.left
        box.y = insets.top
        box.width -= insets.left + insets.right
        box.height -= insets.top + insets.bottom

        start = System.currentTimeMillis() / 1000.0  # in seconds
        last = start
        intervals = []
        real_interval = 0
        i = 1
        fus = None
        if tofile:
            fus = []

            # 0 n_frames means continuous acquisition
        while 0 == n_frames or (len(snaps) < n_frames and last - start < n_frames * interval):
            now = System.currentTimeMillis() / 1000.0  # in seconds
            real_interval = now - last
            if real_interval >= interval:
                last = now
                img = snapshot(frame, box)
                if tofile:
                    fus.append(executors.submit(Saver(i, dir, bounds, borders, img, insets)))  # will flush img
                    i += 1
                else:
                    snaps.append(img)
                intervals.append(real_interval)
            else:
                time.sleep(interval / 5)
                # interrupt capturing:
            if IJ.escapePressed():
                IJ.showStatus("Recording user-interrupted")
                break

                # debug:
                # print "insets:", insets
                # print "bounds:", bounds
                # print "box:", box
                # print "snap dimensions:", snaps[0].getWidth(), snaps[0].getHeight()

                # Create stack
        stack = None
        if tofile:
            for fu in snaps:
                fu.get()  # wait on all
            stack = VirtualStack(bounds.width, bounds.height, None, dir)
            files = File(dir).list(TifFilter())
            Arrays.sort(files)
            for f in files:
                stack.addSlice(f)
        else:
            stack = ImageStack(bounds.width, bounds.height, None)
            t = 0
            for snap, real_interval in zip(snaps, intervals):
                bi = BufferedImage(bounds.width, bounds.height, BufferedImage.TYPE_INT_RGB)
                g = bi.createGraphics()
                g.drawImage(borders, 0, 0, None)
                g.drawImage(snap, insets.left, insets.top, None)
                stack.addSlice(str(IJ.d2s(t, 3)), ImagePlus("", bi).getProcessor())
                t += real_interval
                snap.flush()
                bi.flush()

        borders.flush()

        ImagePlus(frame.getTitle() + " recording", stack).show()
        IJ.showStatus("Done recording " + frame.getTitle())
    except Exception, e:
        print "Some error ocurred:"
        print e.printStackTrace()
        IJ.showStatus("")
        if borders is not None:
            borders.flush()
        for snap in snaps:
            snap.flush()
Пример #7
0
def run(title):
    gd = GenericDialog('Record Window')
    gd.addMessage(
        "Maximum number of frames to record.\nZero means infinite, interrupt with ESC key."
    )
    gd.addNumericField('Max. frames:', 50, 0)
    gd.addNumericField('Milisecond interval:', 300, 0)
    gd.addSlider('Start in (seconds):', 0, 20, 5)
    frames = []
    titles = []
    for f in Frame.getFrames():
        if f.isEnabled() and f.isVisible():
            frames.append(f)
            titles.append(f.getTitle())
    gd.addChoice('Window:', titles, titles[0])
    gd.addCheckbox("To file", False)
    gd.showDialog()
    if gd.wasCanceled():
        return
    n_frames = int(gd.getNextNumber())
    interval = gd.getNextNumber() / 1000.0  # in seconds
    frame = frames[gd.getNextChoiceIndex()]
    delay = int(gd.getNextNumber())
    tofile = gd.getNextBoolean()

    dir = None
    if tofile:
        dc = DirectoryChooser("Directory to store image frames")
        dir = dc.getDirectory()
        if dir is None:
            return  # dialog canceled

    snaps = []
    borders = None
    executors = Executors.newFixedThreadPool(1)
    try:
        while delay > 0:
            IJ.showStatus('Starting in ' + str(delay) + 's.')
            time.sleep(1)  # one second
            delay -= 1

        IJ.showStatus('Capturing frame borders...')
        bounds = frame.getBounds()
        robot = Robot()
        frame.toFront()
        time.sleep(0.5)  # half a second
        borders = robot.createScreenCapture(bounds)

        IJ.showStatus("Recording " + frame.getTitle())

        # Set box to the inside borders of the frame
        insets = frame.getInsets()
        box = bounds.clone()
        box.x = insets.left
        box.y = insets.top
        box.width -= insets.left + insets.right
        box.height -= insets.top + insets.bottom

        start = System.currentTimeMillis() / 1000.0  # in seconds
        last = start
        intervals = []
        real_interval = 0
        i = 1
        fus = None
        if tofile:
            fus = []

        # 0 n_frames means continuous acquisition
        while 0 == n_frames or (len(snaps) < n_frames
                                and last - start < n_frames * interval):
            now = System.currentTimeMillis() / 1000.0  # in seconds
            real_interval = now - last
            if real_interval >= interval:
                last = now
                img = snapshot(frame, box)
                if tofile:
                    fus.append(
                        executors.submit(
                            Saver(i, dir, bounds, borders, img,
                                  insets)))  # will flush img
                    i += 1
                else:
                    snaps.append(img)
                intervals.append(real_interval)
            else:
                time.sleep(interval / 5)
            # interrupt capturing:
            if IJ.escapePressed():
                IJ.showStatus("Recording user-interrupted")
                break

        # debug:
        #print "insets:", insets
        #print "bounds:", bounds
        #print "box:", box
        #print "snap dimensions:", snaps[0].getWidth(), snaps[0].getHeight()

        # Create stack
        stack = None
        if tofile:
            for fu in snaps:
                fu.get()  # wait on all
            stack = VirtualStack(bounds.width, bounds.height, None, dir)
            files = File(dir).list(TifFilter())
            Arrays.sort(files)
            for f in files:
                stack.addSlice(f)
        else:
            stack = ImageStack(bounds.width, bounds.height, None)
            t = 0
            for snap, real_interval in zip(snaps, intervals):
                bi = BufferedImage(bounds.width, bounds.height,
                                   BufferedImage.TYPE_INT_RGB)
                g = bi.createGraphics()
                g.drawImage(borders, 0, 0, None)
                g.drawImage(snap, insets.left, insets.top, None)
                stack.addSlice(str(IJ.d2s(t, 3)),
                               ImagePlus('', bi).getProcessor())
                t += real_interval
                snap.flush()
                bi.flush()

        borders.flush()

        ImagePlus(frame.getTitle() + " recording", stack).show()
        IJ.showStatus('Done recording ' + frame.getTitle())
    except Exception, e:
        print "Some error ocurred:"
        print e.printStackTrace()
        IJ.showStatus('')
        if borders is not None: borders.flush()
        for snap in snaps:
            snap.flush()
Пример #8
0
# Take a snapshot after a delay specified in a dialog
# 
# The plugin has to fork, which is done by:
# 1 - declaring a function to do the work, 'snasphot'
# 2 - invoking the function via thread.start_new_thread,
#     which runs it in a separate thread.

from ij import IJ
from ij.gui import GenericDialog
import thread
import time

def snapshot(delay):
   time.sleep(delay)
   IJ.doCommand('Capture Screen')

gd = GenericDialog('Delay')
gd.addSlider('Delay (secs.): ', 0, 20, 5)
gd.showDialog()

if not gd.wasCanceled():
	# the 'extra' comma signals tuple, a kind of list in python.
	thread.start_new_thread(snapshot, (int(gd.getNextNumber()),))
Пример #9
0
from java.lang import Math, System

image = WindowManager.getCurrentImage()
ip = image.getProcessor()
pixelsCopy = ip.getPixelsCopy()
pixels = ip.getPixels()
width = ip.getWidth()
height = ip.getHeight()

minWidth = int(Math.sqrt(len(pixels) / 16))
maxWidth = minWidth * 16


class Listener(AdjustmentListener):
    def adjustmentValueChanged(self, event):
        value = event.getSource().getValue()
        rowstride = min(width, value)
        for j in range(0, min(height, int(width * height / value))):
            System.arraycopy(pixelsCopy, j * value, pixels, j * width,
                             rowstride)
        image.updateAndDraw()


gd = GenericDialog("Width")
gd.addSlider("width", minWidth, maxWidth, ip.getHeight())
gd.getSliders().get(0).addAdjustmentListener(Listener())
gd.showDialog()
if gd.wasCanceled():
    pixels[0:width * height] = pixelsCopy
    image.updateAndDraw()
Пример #10
0
from java.awt.event import AdjustmentListener

from java.lang import Math, System

image = WindowManager.getCurrentImage()
ip = image.getProcessor()
pixelsCopy = ip.getPixelsCopy()
pixels = ip.getPixels()
width = ip.getWidth()
height = ip.getHeight()

minWidth = int(Math.sqrt(len(pixels) / 16))
maxWidth = minWidth * 16

class Listener(AdjustmentListener):
	def adjustmentValueChanged(self, event):
		value = event.getSource().getValue()
		rowstride = min(width, value)
		for j in range(0, min(height, int(width * height / value))):
			System.arraycopy(pixelsCopy, j * value,
				pixels, j * width, rowstride)
		image.updateAndDraw()

gd = GenericDialog("Width")
gd.addSlider("width", minWidth, maxWidth, ip.getHeight())
gd.getSliders().get(0).addAdjustmentListener(Listener())
gd.showDialog()
if gd.wasCanceled():
	pixels[0:width * height] = pixelsCopy
	image.updateAndDraw()
Пример #11
0
# Take a snapshot after a delay specified in a dialog
#
# The plugin has to fork, which is done by:
# 1 - declaring a function to do the work, 'snasphot'
# 2 - invoking the function via thread.start_new_thread,
#     which runs it in a separate thread.

from ij import IJ
from ij.gui import GenericDialog
import thread
import time


def snapshot(delay):
    time.sleep(delay)
    IJ.doCommand('Capture Screen')


gd = GenericDialog('Delay')
gd.addSlider('Delay (secs.): ', 0, 20, 5)
gd.showDialog()

if not gd.wasCanceled():
    # the 'extra' comma signals tuple, a kind of list in python.
    thread.start_new_thread(snapshot, (int(gd.getNextNumber()), ))