Skip to content

Commit

Permalink
first complete version
Browse files Browse the repository at this point in the history
  • Loading branch information
volker-baecker committed Apr 1, 2024
1 parent 589a7ba commit 93356ca
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 91 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def loadOptions():
if "=" in option:
value = parts[1]
if key=="label":
Label = int(value)
LABEL = int(value)
if key=="zoom":
NR_OF_ZOOM_OUTS = int(value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ macro "Remove Background [f2]" {
}


macro "Remove Background (f2) Action Tool Options" {
showRemoveBackgroundOptions();
}


macro "Measure Image (f3) Action Tool - C000T4b12m" {
measureImage();
}
Expand Down Expand Up @@ -170,6 +175,13 @@ function convertWells() {
}


function showRemoveBackgroundOptions() {
call("ij.Prefs.set", "mri.options.only", "true");
run("remove background");
call("ij.Prefs.set", "mri.options.only", "false");
}


function showMeasureIntensityOptions() {
call("ij.Prefs.set", "mri.options.only", "true");
run("measure without spots");
Expand Down Expand Up @@ -212,14 +224,22 @@ function loadOptions(path) {
function jumpToSelectedLabel() {
call("ij.Prefs.set", "mri.options.only", "false");
row = Table.getSelectionStart;
col = Table.getColumn("Label");
label =col[row];
label = LABEL
if (row > -1) {
col = Table.getColumn("Label");
label =col[row];
}
zoom = NR_OF_ZOOM_OUT;
pluginsPath = getDirectory("plugins");
path = pluginsPath + "Measure-Intensity-Without-Spots/jtl-options.txt";
if (File.exists(path)) {
optionsString = File.openAsString(path);
optionsString = File.openAsString(path);
parts = split(optionsString, " ");
if (row == -1) {
parts0 = split(parts[0], "=");
labelTxt = parts0[1];
label = labelTxt.trim();
}
parts = split(parts[1], "=");
zoomTxt = parts[1];
zoom = zoomTxt.trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
NUCLEUS_MIN_AREA = 50
SHOW_LABELS = False
SAVE_OPTIONS = True
ADDITIONAL_OPTIONS = []
URL = "https://github.com/MontpellierRessourcesImagerie/imagej_macros_and_scripts/wiki/Measure-Intensity-Without-Spots"


Expand Down Expand Up @@ -42,20 +43,26 @@ def main():


def showDialog():
global NUCLEI_CHANNEL, SIGNAL_CHANNEL, NUCLEUS_MIN_AREA, METHODS, METHOD, SAVE_OPTIONS, URL
global NUCLEI_CHANNEL, SIGNAL_CHANNEL, NUCLEUS_MIN_AREA, METHODS, METHOD, ADDITIONAL_OPTIONS, SAVE_OPTIONS, URL

cls = NucleiSegmentationMethod
methodClasses = list(set(cls.__subclasses__()))
ADDITIONAL_OPTIONS = []
for methodClass in methodClasses:
print(methodClass.name(), methodClass.options())

if methodClass.name() == METHOD:
for option in methodClass.options().values():
ADDITIONAL_OPTIONS.append(option)
print(ADDITIONAL_OPTIONS)
if os.path.exists(getOptionsPath()):
loadOptions()
gd = GenericDialog("Measure Without Spots Options");
gd.addNumericField("Nuclei Channel: ", NUCLEI_CHANNEL)
gd.addNumericField("Signal Channel: ", SIGNAL_CHANNEL)
gd.addNumericField("Min. Area Nucleus: ", NUCLEUS_MIN_AREA)
gd.addChoice("Method: ", METHODS, METHOD)
for option in ADDITIONAL_OPTIONS:
if option['type'] == int or option['type'] == float:
gd.addNumericField(option['name'] + ': ' , option['value'])
gd.addCheckbox("Save Options", SAVE_OPTIONS)
gd.addHelp(URL)
gd.showDialog()
Expand All @@ -65,6 +72,9 @@ def showDialog():
SIGNAL_CHANNEL = int(gd.getNextNumber())
NUCLEUS_MIN_AREA = float(gd.getNextNumber())
METHOD = gd.getNextChoice()
for option in ADDITIONAL_OPTIONS:
if option['type'] == int or option['type'] == float:
option['value'] = option['type'](gd.getNextNumber())
SAVE_OPTIONS = gd.getNextBoolean()
if SAVE_OPTIONS:
saveOptions()
Expand All @@ -83,11 +93,13 @@ def getOptionsString():
optionsString = optionsString + " signal=" + str(SIGNAL_CHANNEL)
optionsString = optionsString + " min.=" + str(NUCLEUS_MIN_AREA)
optionsString = optionsString + " method.=" + str(METHOD)
for option in ADDITIONAL_OPTIONS:
optionsString = optionsString + " " + option['name'] + "=" + str(option['value'])
return optionsString


def loadOptions():
global NUCLEI_CHANNEL, SIGNAL_CHANNEL, NUCLEUS_MIN_AREA, METHOD
global NUCLEI_CHANNEL, SIGNAL_CHANNEL, NUCLEUS_MIN_AREA, METHOD, ADDITIONAL_OPTIONS

optionsPath = getOptionsPath()
optionsString = IJ.openAsString(optionsPath)
Expand All @@ -107,6 +119,9 @@ def loadOptions():
NUCLEUS_MIN_AREA = float(value)
if key=="method":
METHOD = str(value)
for additionalOption in ADDITIONAL_OPTIONS:
if key==additionalOption['name']:
additionalOption['value'] = additionalOption['type'](value)


def saveOptions():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,12 @@ class SubtractGaussianAndThresholdSegmentation(NucleiSegmentationMethod):

@classmethod
def name(cls):
return "subtract Gaussian and threshold"
return "subtract_Gaussian_and_threshold"


@classmethod
def options(cls):
return { 1 : {'name': 'sigma', 'defaultValue': 40.86, 'type' : int}}
return { 1 : {'name': 'sigma', 'value': 40.86, 'type' : float}}


def __init__(self, image):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
import os
from ij import IJ
from ij import Prefs
from ij.gui import GenericDialog
from ij import WindowManager
from ij.plugin import Duplicator
from ij.plugin import RGBStackMerge


SPOTS_CHANNEL = 2
SIGNAL_CHANNEL = 2
NUCLEI_CHANNEL = 1
LAMBDA_FLAT = 0.50
LAMBDA_DARK = 0.50
SAVE_OPTIONS = True
URL = "https://github.com/MontpellierRessourcesImagerie/imagej_macros_and_scripts/wiki/Measure-Intensity-Without-Spots"

def main():

def main():
optionsOnly = Prefs.get("mri.options.only", "false")
if not showDialog():
return
if optionsOnly=="true":
return
return
image = IJ.getImage()
width, height, nChannels, nSlices, nFrames = image.getDimensions()
spotsChannelImage = Duplicator().run(image, SPOTS_CHANNEL, SPOTS_CHANNEL, 1, nSlices, 1, nFrames)
spotsChannelImage = Duplicator().run(image, SIGNAL_CHANNEL, SIGNAL_CHANNEL, 1, nSlices, 1, nFrames)
spotsChannelImage.show()
title = spotsChannelImage.getTitle()
IJ.run(spotsChannelImage, "BaSiC ", "processing_stack=[" + spotsChannelImage.getTitle() + "] flat-field=None dark-field=None shading_estimation=[Estimate shading profiles] shading_model=[Estimate both flat-field and dark-field] setting_regularisationparametes=Automatic temporal_drift=[Replace with zero] correction_options=[Compute shading and correct images] lambda_flat=" + str(LAMBDA_FLAT) + " lambda_dark=" + str(LAMBDA_DARK))
Expand All @@ -32,10 +41,79 @@ def main():
resultImage.setTitle(title)
resultImage.show()


def showDialog():
global NUCLEI_CHANNEL, SIGNAL_CHANNEL, LAMBDA_FLAT, SAVE_OPTIONS, LAMBDA_DARK, URL

if os.path.exists(getOptionsPath()):
loadOptions()
gd = GenericDialog("Remove Background Options");
gd.addNumericField("Nuclei Channel: ", NUCLEI_CHANNEL)
gd.addNumericField("Signal Channel: ", SIGNAL_CHANNEL)
gd.addNumericField("Lambda_Flat: ", LAMBDA_FLAT)
gd.addNumericField("Lambda_Dark: ", LAMBDA_DARK)
gd.addCheckbox("Save Options", SAVE_OPTIONS)
gd.addHelp(URL)
gd.showDialog()
if gd.wasCanceled():
return False
NUCLEI_CHANNEL = int(gd.getNextNumber())
SIGNAL_CHANNEL = int(gd.getNextNumber())
LAMBDA_FLAT = float(gd.getNextNumber())
LAMBDA_DARK = float(gd.getNextNumber())
SAVE_OPTIONS = gd.getNextBoolean()
if SAVE_OPTIONS:
saveOptions()
return True


def getOptionsPath():
pluginsPath = IJ.getDirectory("plugins");
optionsPath = pluginsPath + "Measure-Intensity-Without-Spots/rb-options.txt";
return optionsPath;


def getOptionsString():
optionsString = ""
optionsString = optionsString + "nuclei=" + str(NUCLEI_CHANNEL)
optionsString = optionsString + " signal=" + str(SIGNAL_CHANNEL)
optionsString = optionsString + " lambda_flat=" + str(LAMBDA_FLAT)
optionsString = optionsString + " lambda_dark=" + str(LAMBDA_DARK)
return optionsString


def closeWindow(title):
win = WindowManager.getWindow(title)
win.close()


def loadOptions():
global NUCLEI_CHANNEL, SIGNAL_CHANNEL, LAMBDA_FLAT, LAMBDA_DARK

optionsPath = getOptionsPath()
optionsString = IJ.openAsString(optionsPath)
optionsString = optionsString.replace("\n", "")
options = optionsString.split(" ")
for option in options:
parts = option.split("=")
key = parts[0]
value = ""
if "=" in option:
value = parts[1]
if key=="nuclei":
NUCLEI_CHANNEL = int(value)
if key=="signal":
SIGNAL_CHANNEL = int(value)
if key=="lambda_flat":
LAMBDA_FLAT = float(value)
if key=="lambda_dark":
LAMBDA_DARK = float(value)


def saveOptions():
optionsString = getOptionsString()
optionsPath = getOptionsPath()
IJ.saveString(optionsString, getOptionsPath())


main()

This file was deleted.

0 comments on commit 93356ca

Please sign in to comment.