Skip to content

Commit

Permalink
export ok, background correction started
Browse files Browse the repository at this point in the history
  • Loading branch information
volker-baecker committed Mar 19, 2024
1 parent 96cf56e commit de4306d
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 47 deletions.
81 changes: 81 additions & 0 deletions volker/toolsets/measure_intensity_without_spots/conversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import os
from ij import ImagePlus
from ij import ImageStack
from ij.io import FileSaver
from ij.plugin import RGBStackMerge
from loci.plugins import BF
from loci.plugins.in import ImporterOptions
from loci.formats import ImageReader


class BFWellsSeriesToTifStackSeries(object):


def __init__(self, path):
self.inputPath = path
self.outputFolderName = "export"


def setOutputFolderName(self, name):
self.outputFolderName = name


def getOutputPath(self):
outputPath = os.path.join(os.path.dirname(self.inputPath), self.outputFolderName)
if not os.path.exists(outputPath):
os.makedirs(outputPath)
return outputPath


def getNumberOfChannels(self):
reader = ImageReader()
reader.setId(self.inputPath)
nrOfChannels = reader.getSizeC()
return nrOfChannels


def getOptions(self):
options = ImporterOptions()
options.setId(self.inputPath)
options.setOpenAllSeries(True)
options.setSplitChannels(True)
return options


def getImages(self):
images = list(BF.openImagePlus(self.getOptions()))
width = images[0].getWidth()
height = images[0].getHeight()
return images, width, height


def run(self):
nrOfChannels = self.getNumberOfChannels()
options = self.getOptions()
images, width, height = self.getImages()
cStacks = [None]*nrOfChannels
for c in range(nrOfChannels):
cStacks[c] = ImageStack(width, height)
lastWell = None
title = ""
cImages = [None]*nrOfChannels
for c in range(nrOfChannels):
cImages[c] = [image for i, image in enumerate(images) if i%2==c]
for cImageTupel in zip(*cImages):
title = cImageTupel[0].getTitle()
calibration = cImageTupel[0].getCalibration()
well = title.split("Well ")[1].split(" Field")[0]
if well == lastWell or lastWell==None:
for c in range(nrOfChannels):
cStacks[c].addSlice(cImageTupel[c].getProcessor())
else:
imagesC = [ImagePlus(title.replace("C=0", "C=" + str(c)), cStacks[c]) for c in range(nrOfChannels)]
resultImage = RGBStackMerge.mergeChannels(imagesC, False)
resultImage.setCalibration(calibration)
saver = FileSaver(resultImage)
print(os.path.join(self.getOutputPath(), title.replace(" - C=0", "")))
saver.saveAsTiffStack(os.path.join(self.getOutputPath(), title.replace(" - C=0", "")))
cStacks = [None]*nrOfChannels
for c in range(nrOfChannels):
cStacks[c] = ImageStack(width, height)
lastWell = well
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from ij import IJ

CHANNEL = 2
LAMBDA_FLAT = 0.50
LAMBDA_DARK = 0.50
image = IJ.getImage()
width, height, nChannels, nSlices, nFrames = image.getDimensions()
spotsChannelImage = Duplicator().run(image, CHANNEL, CHANNEL, 1, nSlices, 1, nFrames)
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=" + LAMBDA_FLAT + " lambda_dark=" + LAMBDA_DARK)
IJ.selectImage()
49 changes: 10 additions & 39 deletions volker/toolsets/measure_intensity_without_spots/export_wells.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,19 @@
from ij import ImagePlus
from ij import ImageStack
from ij.io import FileSaver
from ij.io import OpenDialog
from ij.plugin import RGBStackMerge
from loci.plugins import BF
from loci.formats import ImageReader
from loci.plugins.in import ImportProcess
from loci.plugins.in import ImporterOptions
from loci.formats import ImageReader
from fr.cnrs.mri.cialib.conversion import BFWellsSeriesToTifStackSeries

def main():
PATH = "/home/baecker/Documents/mri/in/marina/Quantification fluorescence/iHCS2301104-07-1et2-col2b-10X_Plate_45944/iHCS2301104-07-1et2-col2b-10X.HTD"
OUT_PATH = os.path.dirname(PATH)
OUT_PATH = os.path.join(OUT_PATH, "export")

if not os.path.exists(OUT_PATH):
os.makedirs(OUT_PATH)

CHANNELS = 2
options = ImporterOptions()
options.setId(PATH)
options.setOpenAllSeries(True)
options.setSplitChannels(True)
images = list(BF.openImagePlus(options))
c0Stack = ImageStack(images[0].getWidth(), images[0].getHeight())
c1Stack = ImageStack(images[0].getWidth(), images[0].getHeight())
lastWell = None
title = ""
c0Images = [image for i, image in enumerate(images) if i%2==0]
c1Images = [image for i, image in enumerate(images) if i%2==1]
for c0Image, c1Image in zip(c0Images, c1Images):
print(c0Image.getTitle(), c1Image.getTitle())
title = c0Image.getTitle()
well = title.split("Well ")[1].split(" Field")[0]
if well == lastWell or lastWell==None:
c0Stack.addSlice(c0Image.getProcessor())
c1Stack.addSlice(c1Image.getProcessor())
else:
imageC0 = ImagePlus(title, c0Stack)
imageC1 = ImagePlus(title.replace("C=0", "C=1"), c1Stack)
resultImage = RGBStackMerge.mergeChannels([imageC0, imageC1], False)
saver = FileSaver(resultImage)
saver.saveAsTiffStack(os.path.join(OUT_PATH, title.replace(" - C=0", "")))
c0Stack = ImageStack(images[0].getWidth(), images[0].getHeight())
c1Stack = ImageStack(images[0].getWidth(), images[0].getHeight())
lastWell = well

def main():
od = OpenDialog("Choose a file", None)
folder = od.getDirectory()
file = od.getFileName()
path = folder + file
converter = BFWellsSeriesToTifStackSeries(path)
converter.run()

main()
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,62 @@ macro "Measure Intensity Without Spots Help Action Tool - C000D0eDf8DfdDfeDffC02
}


macro "Remove Background (f1) Action Tool - C000T4b12r" {
macro "Convert bioformats wells to tif series (f1) Action Tool - C000T4b12c" {
convertWells()
}


macro "Convert bioformats wells to tif series [F1]" {
convertWells()
}


macro "Remove Background (f2) Action Tool - C000T4b12r" {
removeBackground();
}


macro "Remove Background [f1]" {
macro "Remove Background [f2]" {
removeBackground();
}


macro "Measure Image (f2) Action Tool - C000T4b12m" {
macro "Measure Image (f3) Action Tool - C000T4b12m" {
measureImage();
}


macro "measure image [F2]" {
macro "measure image [F3]" {
measureImage();
}


macro "Measure Image (f2) Action Tool Options" {
macro "Measure Image (f3) Action Tool Options" {
showMeasureIntensityOptions();
}


macro "Jump To Selected Label (f3) Action Tool - C000T4b12j" {
macro "Jump To Selected Label (f4) Action Tool - C000T4b12j" {
jumpToSelectedLabel();
}


macro "Jump To Selected Label (f3) Action Tool Options" {
macro "Jump To Selected Label (f4) Action Tool Options" {
showJumpToSeletedLabelOptions();
}


macro "jump to selected label [F2]" {
macro "jump to selected label [F4]" {
jumpToSelectedLabel();
}



function convertWells() {
run("export wells");
}


function showMeasureIntensityOptions() {
call("ij.Prefs.set", "mri.options.only", "true");
run("measure without spots");
Expand Down

0 comments on commit de4306d

Please sign in to comment.