Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement Filters Protocol #160

@alessiamarcolini

Description

@alessiamarcolini

It could be nice to implement two Protocols for our Filter classes in the filters subpackage, namely ImageFilter and MorphologicalFilter.

This would be very similar to the implementation of a Scorer protocol (see https://github.com/histolab/histolab/blob/master/src/histolab/scorer.py#L36-L44)

The idea would be to have an abstract and not implemented __call__ method and a concrete __repr__ method, since every filter share the same __repr__ implementation:

def __repr__(self) -> str:
    return self.__class__.__name__ + "()"

Careful attention must be paid in the type annotations for the __call__ method for the two protocols:

  • image filters take a PIL.Image.Image and output Union[PIL.Image.Image, np.ndarray]
  • morphological filters take a np.ndarray and output a np.ndarray

Once we have the protocols, all the classes must subclass the respective protocol to get the implementation of __repr__, and we can use the protocols to improve the type annotations of apply_filters method of Tile (see https://github.com/histolab/histolab/blob/master/src/histolab/tile.py#L50)

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions