Skip to content

Commit

Permalink
tried to remove the edge gradient and started the library
Browse files Browse the repository at this point in the history
  • Loading branch information
volker-baecker committed Mar 6, 2024
1 parent 20f3d86 commit 93ef9c3
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
84 changes: 84 additions & 0 deletions volker/toolsets/measure_intensity_without_spots/quantification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@



class StainingAnalyzer:


def __init__(self, image, nucleiChannel, signalChannel):
self.image = image
self.nucleiChannel = nucleiChannel
self.signalChannel = signalChannel
self.nucleiMask = None
self.spotsMask = None
self.nucleiWithoutSpotsMask = None


def createNucleiMask(self):
currentChannel = self.image.getC()
self.image.setC(self.nucleiChannel)
method = self.getNucleiSegmentationMethod()
method.run()
self.nucleiMask = method.getResultMask()
self.image.setC(currentChannel)


def setMethod(self, method):
self.method = method


def getMethod(self):
if not self.method:
self.method = self.getDefaultNucleiSegmentationMethd()
return self.method


def getDefaultNucleiSegmentationMethd(self):
currentChannel = self.image.getC()
self.image.setC(self.nucleiChannel)
method = SubtractGaussianAndThresholdSegmentation(self.image.getTitle(), self.image.getProcessor())
self.image.setC(currentChannel)



def NucleiSegmentationMethod():


def __init__(self, title, processor):
self.processor = processor
self.resultMask = None
self.title = "Mask of " + title


def getOptions(self):
return {}


def getResultMask(self):
return self.resultMask


def run(self):
pass



class SubtractGaussianAndThresholdSegmentation(NucleiSegmentationMethod):


def __init__(self, title, processor):
super(SubtractGaussianAndThresholdSegmentation, self).__init__(title, processor)
self.sigma = 40.86


def setSigma(self, sigma):
"""Set the sigma of the Gaussian Blur Filter in physical units (for example micron).
"""
self.sigma = sigma


def getSigma(self):
return sigma


def run(self):
self.resultMask = ImagePlus("Mask of ", )
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import java
from ij import IJ
from jarray import array

def main():
STEP = 5

image = IJ.getImage()
width, height, nChannels, nSlices, nFrames = image.getDimensions()
found = True
counter = 1
while found and counter < 11:
print("processing iteration: ", counter)
found = False
processor = image.getProcessor()
newProcessor = processor.duplicate()
numberOfChanges = 0
for x in range(0, width):
for y in range(0, height):
value = processor.get(x, y)
if value == 0:
newValue = getMinAboveZeroInNeighborhood(x, y, processor)
if newValue == 65536:
continue
newProcessor.set(x, y, int(max(newValue-STEP, 1)))
found = True
numberOfChanges = numberOfChanges + 1
print(str(numberOfChanges) + " pixels changed")
image.setProcessor(newProcessor)
counter = counter + 1


def getMinAboveZeroInNeighborhood(x, y, processor):
imp = processor
line1 = array([float(0.0), float(0.0) ,float(0.0)], 'd')
line2 = array([float(0.0), float(0.0) ,float(0.0)], 'd')
line3 = array([float(0.0), float(0.0) ,float(0.0)], 'd')
neighbors = array([line1, line2, line3], java.lang.Class.forName("[D"))
imp.getNeighborhood(x, y, neighbors)
neighbors = list([list(line) for line in neighbors])
smallest = 65536
for line in neighbors:
for element in line:
if element == 0.0:
continue
if element < smallest:
smallest = element
return smallest


main()

0 comments on commit 93ef9c3

Please sign in to comment.