segmetrics.study
- class segmetrics.study.Study
Bases:
object
Computes different performance measures for different image data.
Performance measures must be added prior to performing evaluation.
- add_measure(measure: MeasureProtocol, name: str | None = None) str
Adds a performance measure to this study.
- Parameters:
measure – The performance measure to be added.
name – An arbitrary name which uniquely identifies the performance measure within this study. Uses
measure.default_name()
ifNone
is given.
- Returns:
The name used for the measure (see above).
- merge(other: Study, sample_ids: Sequence[Any] | Literal['all'], replace: bool = True) None
Merges measures and results from
other
study.- Parameters:
other – The study which is to be merged into this study.
sample_ids – The identifiers of the samples which are to be merged (or
'all'
).replace – Whether conflicting identifiers are to be replaced (
True
) or prohibited (False
).
- print_results(write: ~typing.Callable[[str], ~typing.Any] = <built-in method write of _io.TextIOWrapper object>, pad: int = 0, fmt_unbound_float: str = 'g', line_suffix: str = '\n') None
Prints the results of this study.
- Parameters:
write – Function used for output.
pad – Number of whitespaces at the start of each line.
fmt_unbound_float – Formatting literal used for decimals not presented as percentages.
line_suffix – Suffix of each line.
- process(sample_id: Any, actual: None, unique: bool = True, replace: bool = True) Dict[str, List[float]]
Evaluates a segmentation result based on the previously set expected result.
If
unique
isTrue
, it is assumed that all objects are labeled uniquely. Useunique=False
if this is not guaranteed and the individual objects should be determined by connected component analysis instead (e.g., ifactual
is a binary image which represents the union of the individual object masks).The image
actual
must be a numpy array of integral data type. It is also allowed to be boolean if and only ifunique=False
is used.- Parameters:
sample_id – An arbitrary indentifier of the segmentation image (e.g., the filename).
actual – An image containing object masks corresponding to the segmentation result.
unique – Whether the individual object masks are uniquely labeled. Providing
False
assumes that connected components correspond to individual objects (components of different labels are not connected).replace – Whether previous results computed for the same
sample_id
should be replaced (True
) or forbidden (False
).
- set_expected(expected: None, unique: bool = True) None
Sets the expected ground truth segmentation result.
The background of the image must be labeled as
0
. Negative object labels are forbidden. Ifunique
isTrue
, it is assumed that all objects are labeled uniquely. Useunique=False
if this is not guaranteed and the individual objects should be determined by connected component analysis instead (e.g., ifexpected
is a binary image which represents the union of the individual object masks).The image
expected
must be a numpy array of integral data type. It is also allowed to be boolean if and only ifunique=False
is used.- Parameters:
expected – An image containing object masks corresponding to the ground truth.
unique – Whether the individual object masks are uniquely labeled. Providing
False
assumes that connected components correspond to individual objects (components of different labels are not connected).
- todf() pd.DataFrame
Returns the results of this study as a pandas dataframe.
- write_csv(fout: TextIO, write_samples: bool | str = 'auto', write_header: bool = True, write_summary: bool = True, **kwargs) None
Writes the results of this study as CSV.
- Parameters:
fout – File descriptor used for output.
write_samples – Whether all samples should be written separately.
write_header – Whether a header should be included (measure names).
write_summary – Whether a summary should be included in the last row.
kwargs – Additional parameters for
csv.writer
, see: https://docs.python.org/3/library/csv.html#csv.writer
- write_tsv(fout: TextIO, **kwargs) None
Writes the results of this study as TSV.
- Parameters:
fout – File descriptor used for output.
kwargs – Additional parameters passed to
write_csv()
.