BioImager  3.9.1
A .NET microscopy imaging library. Supports various microscopes by using imported libraries & GUI automation. Supported libraries include PriorĀ® & ZeissĀ® & all devices supported by Micromanager 2.0 and python-microscope.
Loading...
Searching...
No Matches
microscope.simulators._ImageGenerator Class Reference

Public Member Functions

def __init__ (self)
 
def enable_numbering (self, enab)
 
def get_data_types (self)
 
def data_type (self)
 
def set_data_type (self, index)
 
def get_methods (self)
 
def method (self)
 
def set_method (self, index)
 
def get_image (self, width, height, dark=0, light=255, index=None)
 
def black (self, w, h, dark, light)
 
def white (self, w, h, dark, light)
 
def gradient (self, w, h, dark, light)
 
def noise (self, w, h, dark, light)
 
def one_gaussian (self, w, h, dark, light)
 
def sawtooth (self, w, h, dark, light)
 

Public Attributes

 numbering
 

Detailed Description

Generates test images, with methods for configuration via a Setting.

Definition at line 53 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

def microscope.simulators._ImageGenerator.__init__ (   self)

Definition at line 56 of file __init__.py.

56 def __init__(self):
57 self._methods = (
58 self.noise,
59 self.gradient,
60 self.sawtooth,
61 self.one_gaussian,
62 self.black,
63 self.white,
64 )
65 self._method_index = 0
66 self._datatypes = (np.uint8, np.uint16, float)
67 self._datatype_index = 0
68 self._theta = _theta_generator()
69 self.numbering = True
70 # Font for rendering counter in images.
71 self._font = ImageFont.load_default()
72

Member Function Documentation

◆ black()

def microscope.simulators._ImageGenerator.black (   self,
  w,
  h,
  dark,
  light 
)
Ignores dark and light - returns zeros

Definition at line 112 of file __init__.py.

112 def black(self, w, h, dark, light):
113 """Ignores dark and light - returns zeros"""
114 return np.zeros((h, w))
115

◆ data_type()

def microscope.simulators._ImageGenerator.data_type (   self)

Definition at line 79 of file __init__.py.

79 def data_type(self):
80 return self._datatype_index
81

◆ enable_numbering()

def microscope.simulators._ImageGenerator.enable_numbering (   self,
  enab 
)

Definition at line 73 of file __init__.py.

73 def enable_numbering(self, enab):
74 self.numbering = enab
75

◆ get_data_types()

def microscope.simulators._ImageGenerator.get_data_types (   self)

Definition at line 76 of file __init__.py.

76 def get_data_types(self):
77 return (t.__name__ for t in self._datatypes)
78

◆ get_image()

def microscope.simulators._ImageGenerator.get_image (   self,
  width,
  height,
  dark = 0,
  light = 255,
  index = None 
)
Return an image using the currently selected method.

Definition at line 97 of file __init__.py.

97 def get_image(self, width, height, dark=0, light=255, index=None):
98 """Return an image using the currently selected method."""
99 m = self._methods[self._method_index]
100 d = self._datatypes[self._datatype_index]
101 # return Image.fromarray(m(width, height, dark, light).astype(d), 'L')
102 data = m(width, height, dark, light).astype(d)
103 if self.numbering and index is not None:
104 text = "%d" % index
105 size = tuple(d + 2 for d in self._font.getsize(text))
106 img = Image.new("L", size)
107 ctx = ImageDraw.Draw(img)
108 ctx.text((1, 1), text, fill=light)
109 data[0 : size[1], 0 : size[0]] = np.asarray(img)
110 return data
111

References microscope.simulators._ImageGenerator._datatype_index, microscope.simulators._ImageGenerator._datatypes, microscope.simulators._ImageGenerator._font, microscope.simulators._ImageGenerator._method_index, microscope.simulators._ImageGenerator._methods, and microscope.simulators._ImageGenerator.numbering.

◆ get_methods()

def microscope.simulators._ImageGenerator.get_methods (   self)
Return the names of available image generation methods

Definition at line 85 of file __init__.py.

85 def get_methods(self):
86 """Return the names of available image generation methods"""
87 return (m.__name__ for m in self._methods)
88

References microscope.simulators._ImageGenerator._methods.

◆ gradient()

def microscope.simulators._ImageGenerator.gradient (   self,
  w,
  h,
  dark,
  light 
)
A single gradient across the whole image from top left to bottom right.

Definition at line 125 of file __init__.py.

125 def gradient(self, w, h, dark, light):
126 """A single gradient across the whole image from top left to bottom right."""
127 xx, yy = np.meshgrid(range(w), range(h))
128 return dark + light * (xx + yy) / (xx.max() + yy.max())
129

◆ method()

def microscope.simulators._ImageGenerator.method (   self)
Return the index of the current image generation method.

Definition at line 89 of file __init__.py.

89 def method(self):
90 """Return the index of the current image generation method."""
91 return self._method_index
92

References microscope.simulators._ImageGenerator._method_index.

◆ noise()

def microscope.simulators._ImageGenerator.noise (   self,
  w,
  h,
  dark,
  light 
)
Random noise.

Definition at line 130 of file __init__.py.

130 def noise(self, w, h, dark, light):
131 """Random noise."""
132 return np.random.randint(dark, light, size=(h, w))
133

◆ one_gaussian()

def microscope.simulators._ImageGenerator.one_gaussian (   self,
  w,
  h,
  dark,
  light 
)

Definition at line 134 of file __init__.py.

134 def one_gaussian(self, w, h, dark, light):
135 "A single gaussian"
136 sigma = 0.01 * max(w, h)
137 x0 = np.random.randint(w)
138 y0 = np.random.randint(h)
139 xx, yy = np.meshgrid(range(w), range(h))
140 return dark + light * np.exp(
141 -((xx - x0) ** 2 + (yy - y0) ** 2) / (2 * sigma**2)
142 )
143

◆ sawtooth()

def microscope.simulators._ImageGenerator.sawtooth (   self,
  w,
  h,
  dark,
  light 
)
A sawtooth gradient that rotates about 0,0.

Definition at line 144 of file __init__.py.

144 def sawtooth(self, w, h, dark, light):
145 """A sawtooth gradient that rotates about 0,0."""
146 th = next(self._theta)
147 xx, yy = np.meshgrid(range(w), range(h))
148 wrap = 0.1 * max(xx.max(), yy.max())
149 return dark + light * ((np.sin(th) * xx + np.cos(th) * yy) % wrap) / (
150 wrap
151 )
152
153

References microscope.simulators._ImageGenerator._theta.

◆ set_data_type()

def microscope.simulators._ImageGenerator.set_data_type (   self,
  index 
)

Definition at line 82 of file __init__.py.

82 def set_data_type(self, index):
83 self._datatype_index = index
84

◆ set_method()

def microscope.simulators._ImageGenerator.set_method (   self,
  index 
)
Set the image generation method.

Definition at line 93 of file __init__.py.

93 def set_method(self, index):
94 """Set the image generation method."""
95 self._method_index = index
96

References microscope.simulators._ImageGenerator._method_index.

◆ white()

def microscope.simulators._ImageGenerator.white (   self,
  w,
  h,
  dark,
  light 
)
Ignores dark and light - returns max value for current data type.

Definition at line 116 of file __init__.py.

116 def white(self, w, h, dark, light):
117 """Ignores dark and light - returns max value for current data type."""
118 d = self._datatypes[self._datatype_index]
119 if issubclass(d, np.integer):
120 value = np.iinfo(d).max
121 else:
122 value = 1.0
123 return value * np.ones((h, w)).astype(d)
124

References microscope.simulators._ImageGenerator._datatype_index, and microscope.simulators._ImageGenerator._datatypes.

Member Data Documentation

◆ numbering

microscope.simulators._ImageGenerator.numbering

Definition at line 69 of file __init__.py.

Referenced by microscope.simulators._ImageGenerator.get_image().


The documentation for this class was generated from the following file: