API documentation
Photo
Bases: QObject
A base class representing a single photo. Provides access to the RGB/Grayscale pixel data for a photo as well as
access to label images (LabelImg
) associated with this Photo.
This class acts only as the interface defining what the classes subclassing this class should implement.
Source code in maphis\common\photo.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
|
image: np.ndarray
abstractmethod
property
Returns the pixel data for the photo. Beware that the order of sizes returned by the property image_size
(width, height) is different from the size stored in the shape
(height, width, channels) tuple of the
returned pixel data.
Returns:
Type | Description |
---|---|
ndarray
|
the pixel data |
image_scale: Optional[pint.Quantity]
property
writable
Return image scale as pint.Quantity
if set, otherwise None
.
Returns:
Type | Description |
---|---|
Optional[Quantity]
|
the image scale if set, otherwise |
image_size: typing.Tuple[int, int]
abstractmethod
property
Returns the image size (width, height).
Returns:
Type | Description |
---|---|
Tuple[int, int]
|
the image size in (width, height) order. |
label_image_info: Dict[str, LabelImgInfo]
abstractmethod
property
Returns a dict label_name
-> LabelImgInfo
.
Returns:
Type | Description |
---|---|
Dict[str, LabelImgInfo]
|
dictionary mapping label names to |
__getitem__(label_name)
abstractmethod
Returns the LabelImg
instance stored under label_name
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
label_name |
str
|
The name under which the |
required |
Returns:
Type | Description |
---|---|
LabelImg
|
a |
Raises:
Type | Description |
---|---|
KeyError
|
If no |
Source code in maphis\common\photo.py
LabelImg
Bases: QObject
A class representing a label image.
Source code in maphis\common\label_image.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
|
region_props: Dict[int, Dict[str, RegionProperty]]
property
writable
Returns a dictionary of (label -> (property_key -> RegionProperty
) pairs.
used_labels: Optional[typing.Set[int]]
property
Returns the set of labels that are present in this label image.
__getitem__(level)
Returns a label image generated from this one, where all the labels are from the level level
of label_hierarchy
.
Source code in maphis\common\label_image.py
create2(path, image_size, label_info, label_name)
classmethod
Creates new LabelImg
object.
path: Path - where this label image should be stored
image_size: (height, width)
label_info: LabelImgInfo
label_name: str - not used, stored in label_info
Source code in maphis\common\label_image.py
get_region_props(region_label)
Returns (property_key -> RegionProperty) for
region_label`.
Source code in maphis\common\label_image.py
mask_for(label)
Returns a binary (np.bool) image where True
values mark pixels whose value is label
or are descendants of label
.
Source code in maphis\common\label_image.py
LabelImgInfo
Info about a particular LabelImg
object.
Source code in maphis\common\label_image.py
Action
A class specifying the common interface for RegionComputation
, PropertyComputation
and GeneralAction
.
Attributes:
Name | Type | Description |
---|---|---|
info |
Info
|
metadata |
_user_params |
Dict[str, Param]
|
dictionary of user |
_group |
str
|
a category where this |
_settings_widget |
Optional[ParamWidget]
|
an optional |
Source code in maphis\common\action.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
|
can_be_executed: typing.Tuple[bool, str]
property
Determines whether this Action
can be executed or not.
Returns:
Type | Description |
---|---|
Tuple[bool, str]
|
|
group: str
property
Group the Action belongs to.
It is used to organize PropertyComputation
s, or where to put GeneralAction
s in the application's
menu bar.
setting_widget: typing.Optional[QWidget]
property
An optional widget containing parameters to customize the Action
s behaviour.
Returns:
optional widget with user parameters.
user_params: typing.List[Param]
property
Returns:
Type | Description |
---|---|
List[Param]
|
list of |
current_settings_to_str_dict()
Serialize the current values of user parameters provided by the Action
into a dictionary.
The returned dictionary has 2 entries:
- 'standard_parameters' -> a dictionary of serialized Param
values, keyed by the keys of
self._user_params
- 'custom_parameters' -> this can be anything, it is up to the Action
implementation to correctly
deserialize in the method Action.setup_settings_from_dict
.
Returns:
Type | Description |
---|---|
Dict[str, Dict[str, str]]
|
dictionary of string representations of user parameters for this |
Source code in maphis\common\action.py
initialize()
Prepare everything before executing the Action
such as loading heavy resources etc.
Returns:
Type | Description |
---|---|
Tuple[bool, str]
|
|
Source code in maphis\common\action.py
setup_settings_from_dict(_dict)
Deserializes parameter values from the provided _dict
argument.
Custom implementation of subclasses of Action
must take care of properly deserializing values stored under the
'custom_parameters' key.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
_dict |
Dict[str, Dict[str, str]]
|
string representations of parameter values |
required |
Source code in maphis\common\action.py
GeneralAction
Bases: Action
Base class for custom GeneralAction.
Source code in maphis\common\action.py
GeneralActionContext
Bases: IntEnum
The necessary context in which a GeneralAction is enabled.
Source code in maphis\common\action.py
PropertyComputation
Bases: Action
Base class for custom PropertyComputation
s
Attributes:
Name | Type | Description |
---|---|---|
_units |
UnitRegistry
|
the unit registry ( |
_pixels |
Unit
|
(pint.Unit): pixels unit |
_no_unit |
Unit
|
|
example_props_dict |
Dict[str, RegionProperty]
|
dictionary of exemplary |
_export_target |
str
|
the values computed by this computation will be stored in the sheet (xlsx export) or file (csv export) named by the value specified by this variable. |
Source code in maphis\common\action.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
|
__call__(photo, region_labels, regions_cache, props)
abstractmethod
The actual computation of the property. The property is computed for the photo
and only for
regions specified by region_labels
. If this computation allows to compute various variants, they will be
specified in props
(for example, when you are computing GLCM properties, you have these options to compute:
'Contrast', 'Dissimilarity', 'Energy' and some more. These are considered as variants).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
photo |
Photo
|
photo for which to compute the property |
required |
region_labels |
List[int]
|
labels of regions that we want to compute the property for |
required |
regions_cache |
RegionsCache
|
regions cache for efficient access to regions |
required |
props |
List[str]
|
which variants of the property (if any) to compute |
required |
Returns:
Type | Description |
---|---|
List[RegionProperty]
|
list of properties computed for the photo. |
Source code in maphis\common\action.py
RegionComputation
Bases: Action
Base class for custom RegionComputation
s.
Source code in maphis\common\action.py
__call__(photo, labels=None, storage=None)
abstractmethod
The actual implementation of the functionality that is to be provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
photo |
Photo
|
the photo that the |
required |
labels |
Optional[Set[int]]
|
restrict the computation on this set of labels |
None
|
storage |
Optional[Storage]
|
the |
None
|
Returns:
Type | Description |
---|---|
List[LabelImg]
|
list of |
Source code in maphis\common\action.py
action_info(name, description, group='General')
Decorator to provide information about Action subclasses. By an Action subclass it is understood either classes that subclass GeneralAction, RegionComputation or PropertyComputation, or functions that are decorated by @region_computation, @scalar_property_computation, @vector_property_computation or @general_action.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the name - how it would be shown in GUI |
required |
description |
str
|
description of what it does |
required |
group |
str
|
category - for |
'General'
|
Returns:
Type | Description |
---|---|
Union[GeneralAction, PropertyComputation, RegionComputation, Callable[[Any], Any]]
|
the decorated |
Source code in maphis\common\action.py
general_action(name, description, group='General', general_action_context=GeneralActionContext.Application)
Decorator to turn a function of appropriate signature into a GeneralAction
subclass.
The function signature is expected to be as follows:
GeneralAction
, State
, ActionContext
) -> None
<func_name>
is used as a key of your computation in MAPHIS and will be stored in project files to correctly
identify the origin of results (segmentations, properties, etc.), so it's good provide clear and easy to interpret
name for your function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the |
required |
description |
str
|
what this action does |
required |
group |
str
|
placement of this action in the menu bar, e.g. |
'General'
|
general_action_context |
GeneralActionContext
|
what is the necessary context for this action to be enabled in |
Application
|
Returns:
Type | Description |
---|---|
Callable[[GeneralAction, State, ActionContext], None]
|
the decorated function which will be turned into |
Source code in maphis\common\action.py
param_bool(name, description, key, default_value)
Decorator that adds a boolean user parameter to subclasses of GeneralAction
, RegionComputation
or
PropertyComputation
or functions that have been decorated with @general_action
, @region_computation
or
@property_computation
decorators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the parameter - how it will be presented in the GUI |
required |
description |
str
|
what this parameter affects |
required |
key |
str
|
how this parameter will be referenced to in your implementation, but also in project files. |
required |
default_value |
bool
|
default value |
required |
Returns:
Type | Description |
---|---|
Union[GeneralAction, PropertyComputation, RegionComputation, Callable[[Any], Any]]
|
the decorated |
Source code in maphis\common\action.py
param_int(name, description, key, default_value, min_value, max_value)
Decorator that adds an integer user parameter to subclasses of GeneralAction
, RegionComputation
or
PropertyComputation
or functions that have been decorated with @general_action
, @region_computation
or
@property_computation
decorators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the parameter - how it will be presented in the GUI |
required |
description |
str
|
what this parameter affects |
required |
key |
str
|
how this parameter will be referenced to in your implementation, but also in project files. |
required |
default_value |
int
|
default value |
required |
min_value |
int
|
the lowest permissible value |
required |
max_value |
int
|
the highest permissible value |
required |
Returns:
Type | Description |
---|---|
Union[GeneralAction, PropertyComputation, RegionComputation, Callable[[Any], Any]]
|
the decorated |
Source code in maphis\common\action.py
param_string(name, description, key, default_value)
Decorator that adds a string user parameter to subclasses of GeneralAction
, RegionComputation
or
PropertyComputation
or functions that have been decorated with @general_action
, @region_computation
or
@property_computation
decorators.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the parameter - how it will be presented in the GUI |
required |
description |
str
|
what this parameter affects |
required |
key |
str
|
how this parameter will be referenced to in your implementation, but also in project files. |
required |
default_value |
str
|
default value |
required |
Returns:
Type | Description |
---|---|
Union[GeneralAction, PropertyComputation, RegionComputation, Callable[[Any], Any]]
|
the decorated |
Source code in maphis\common\action.py
region_computation(name, description, group='General')
Decorator to turn a function of appropriate signature into a RegionComputation
subclass.
The function signature is expected to be one of these two:
1. RegionComputation
, Photo
, *args) -> List[LabelImg
]
2. RegionComputation
, Photo
, Optional[Set[int]], Storage
) -> List[LabelImg
]
<func_name>
is used as a key of your computation in MAPHIS and will be stored in project files to correctly
identify the origin of results (segmentations, properties, etc.), so it's good provide clear and easy to interpret
name for your function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the |
required |
description |
str
|
what this computation does |
required |
group |
str
|
category, most likely will be 'Segmentation' for |
'General'
|
Returns:
Type | Description |
---|---|
Callable[[RegionComputation, Photo, Optional[Set[int]], Storage], List[LabelImg]]
|
the decorated function which will be turned into |
Source code in maphis\common\action.py
scalar_property_computation(name, description, group, export_target, default_value)
Decorator to turn a function of appropriate signature into a PropertyComputation
subclass that generates
scalar properties.
The function signature is expected to be as follows:
PropertyComputation
, Photo
, List[int], RegionsCache
, List[str]) -> List[RegionProperty
]
<func_name>
is used as a key of your computation in MAPHIS and will be stored in project files to correctly
identify the origin of results (segmentations, properties, etc.), so it's good provide clear and easy to interpret
name for your function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the |
required |
description |
str
|
what kind of scalar property this computation computes |
required |
group |
str
|
category of property, e.g., 'Dimensions', 'Shape',... (see the |
required |
export_target |
str
|
name of the sheet in Excel spreadsheet where values of this property will be stored. In case of CSV export, |
required |
default_value |
ScalarValue
|
default value for this property |
required |
Returns:
Type | Description |
---|---|
Callable[[PropertyComputation, Photo, List[int], RegionsCache, List[str]], List[RegionProperty]]
|
the decorated function which will be turned into |
Source code in maphis\common\action.py
vector_property_computation(name, description, group, export_target, value_count, value_names, unit)
Decorator to turn a function of appropriate signature into a PropertyComputation
subclass that generates
vector properties.
The function signature is expected to be as follows:
<func_name>(PropertyComputation, Photo, List[int], RegionsCache, List[str]) -> List[RegionProperty]
<func_name>
is used as a key of your computation in MAPHIS and will be stored in project files to correctly
identify the origin of results (segmentations, properties, etc.), so it's good provide clear and easy to interpret
name for your function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
name of the |
required |
description |
str
|
what kind of vector property this computation computes |
required |
group |
str
|
category of property, e.g., 'Dimensions', 'Shape',... (see the |
required |
export_target |
str
|
|
required |
Returns:
Type | Description |
---|---|
Callable[[PropertyComputation, Photo, List[int], RegionsCache, List[str]], List[RegionProperty]]
|
the decorated function which will be turned into |
Source code in maphis\common\action.py
Region
dataclass
Object representing a region. mask
and image
attributes are subimages of the original label image and photo that
the region represented by this object originates from.
Attributes:
Name | Type | Description |
---|---|---|
label |
int
|
the integer label of the region |
mask |
ndarray
|
binary mask of the region |
image |
ndarray
|
subimage of the photo this region covers |
bbox |
Tuple[int, int, int, int]
|
corners of the bounding box of this region - (top, left, bottom, right) |
Source code in maphis\common\regions_cache.py
RegionsCache
Stores Region
objects, one for each integer label present in region_labels
.
Intended for efficient access to regions so you don't have to repeatedly search for them.
Attributes:
Name | Type | Description |
---|---|---|
regions |
typing.Dict[int, [`Region`][maphis.common.regions_cache.Region]]
|
dictionary of |
data_storage |
Dict[str, Any]
|
this is for you to cache arbitrary data pertaining to the specific photo, that you expect you will need at some later point. |
Source code in maphis\common\regions_cache.py
RegionProperty
A class representing a property for a specific region.
Source code in maphis\measurement\region_property.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
|
MatrixValue
Bases: Value
Source code in maphis\measurement\values.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
from_dict(_dict)
classmethod
Constructs a MatrixValue
from a dictionary. Raises KeyError if the dictionary does not
have all the needed fields.
Source code in maphis\measurement\values.py
ScalarValue
Bases: Value
Source code in maphis\measurement\values.py
from_dict(_dict)
classmethod
Constructs a ScalarValue
from a dictionary. Raises KeyError if the dictionary does not
have all the needed fields.
Source code in maphis\measurement\values.py
VectorValue
Bases: Value
Source code in maphis\measurement\values.py
from_dict(_dict)
classmethod
Constructs a VectorValue
from a dictionary. Raises KeyError if the dictionary does not
have all the needed fields.