BioImager  4.9.0
A .NET microscopy imaging application based on Bio library. Supports various microscopes by using imported libraries & GUI automation. Supports XInput game controllers to move stage, take images, run ImageJ macros on images or Bio C# scripts.
Loading...
Searching...
No Matches
microscope.simulators._ImageGenerator Class Reference

Public Member Functions

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

Public Attributes

bool numbering = True
 

Protected Attributes

tuple _methods
 
int _method_index = 0
 
tuple _datatypes = (np.uint8, np.uint16, float)
 
int _datatype_index = 0
 
 _theta = _theta_generator()
 
 _font = ImageFont.load_default()
 

Detailed Description

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

Definition at line 53 of file __init__.py.

Constructor & Destructor Documentation

◆ __init__()

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()

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()

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()

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()

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()

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

◆ get_methods()

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

◆ gradient()

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()

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

◆ noise()

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()

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()

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

◆ set_data_type()

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()

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

◆ white()

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

Member Data Documentation

◆ _datatype_index

int microscope.simulators._ImageGenerator._datatype_index = 0
protected

Definition at line 67 of file __init__.py.

◆ _datatypes

microscope.simulators._ImageGenerator._datatypes = (np.uint8, np.uint16, float)
protected

Definition at line 66 of file __init__.py.

◆ _font

microscope.simulators._ImageGenerator._font = ImageFont.load_default()
protected

Definition at line 71 of file __init__.py.

◆ _method_index

int microscope.simulators._ImageGenerator._method_index = 0
protected

Definition at line 65 of file __init__.py.

◆ _methods

microscope.simulators._ImageGenerator._methods
protected
Initial value:
= (
self.noise,
self.gradient,
self.sawtooth,
self.one_gaussian,
self.black,
self.white,
)

Definition at line 57 of file __init__.py.

◆ _theta

microscope.simulators._ImageGenerator._theta = _theta_generator()
protected

Definition at line 68 of file __init__.py.

◆ numbering

bool microscope.simulators._ImageGenerator.numbering = True

Definition at line 69 of file __init__.py.


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