:py:mod:`kwcoco.demo.toypatterns` ================================= .. py:module:: kwcoco.demo.toypatterns Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: kwcoco.demo.toypatterns.CategoryPatterns kwcoco.demo.toypatterns.Rasters Functions ~~~~~~~~~ .. autoapisummary:: kwcoco.demo.toypatterns.star Attributes ~~~~~~~~~~ .. autoapisummary:: kwcoco.demo.toypatterns.profile .. py:data:: profile .. py:class:: CategoryPatterns(categories=None, fg_scale=0.5, fg_intensity=0.9, rng=None) Bases: :py:obj:`object` .. rubric:: Example >>> from kwcoco.demo.toypatterns import * # NOQA >>> self = CategoryPatterns.coerce() >>> chip = np.zeros((100, 100, 3)) >>> offset = (20, 10) >>> dims = (160, 140) >>> info = self.random_category(chip, offset, dims) >>> print('info = {}'.format(ub.repr2(info, nl=1))) >>> # xdoctest: +REQUIRES(--show) >>> import kwplot >>> kwplot.autompl() >>> kwplot.imshow(info['data'], pnum=(1, 2, 1), fnum=1, title='chip-space') >>> kpts = kwimage.Points._from_coco(info['keypoints']) >>> kpts.translate(-np.array(offset)).draw(radius=3) >>> ##### >>> mask = kwimage.Mask.coerce(info['segmentation']) >>> kwplot.imshow(mask.to_c_mask().data, pnum=(1, 2, 2), fnum=1, title='img-space') >>> kpts.draw(radius=3) >>> kwplot.show_if_requested() .. py:attribute:: _default_categories .. py:attribute:: _default_keypoint_categories .. py:attribute:: _default_catnames :annotation: = ['star', 'eff', 'superstar'] .. py:method:: coerce(CategoryPatterns, data=None, **kwargs) :classmethod: Construct category patterns from either defaults or only with specific categories. Can accept either an existig category pattern object, a list of known catnames, or mscoco category dictionaries. .. rubric:: Example >>> data = ['superstar'] >>> self = CategoryPatterns.coerce(data) .. py:method:: __len__(self) .. py:method:: __getitem__(self, index) .. py:method:: __iter__(self) .. py:method:: index(self, name) .. py:method:: get(self, index, default=ub.NoParam) .. py:method:: random_category(self, chip, xy_offset=None, dims=None, newstyle=True, size=None) .. rubric:: Example >>> from kwcoco.demo.toypatterns import * # NOQA >>> self = CategoryPatterns.coerce(['superstar']) >>> chip = np.random.rand(64, 64) >>> info = self.random_category(chip) .. py:method:: render_category(self, cname, chip, xy_offset=None, dims=None, newstyle=True, size=None) .. rubric:: Example >>> from kwcoco.demo.toypatterns import * # NOQA >>> self = CategoryPatterns.coerce(['superstar']) >>> chip = np.random.rand(64, 64) >>> info = self.render_category('superstar', chip, newstyle=True) >>> print('info = {}'.format(ub.repr2(info, nl=-1))) >>> info = self.render_category('superstar', chip, newstyle=False) >>> print('info = {}'.format(ub.repr2(info, nl=-1))) .. rubric:: Example >>> from kwcoco.demo.toypatterns import * # NOQA >>> self = CategoryPatterns.coerce(['superstar']) >>> chip = None >>> dims = (64, 64) >>> info = self.render_category('superstar', chip, newstyle=True, dims=dims, size=dims) >>> print('info = {}'.format(ub.repr2(info, nl=-1))) .. py:method:: _todo_refactor_geometric_info(self, cname, xy_offset, dims) This function is used to populate kpts and sseg information in the autogenerated coco dataset before rendering. It is redundant with other functionality. TODO: rectify with _from_elem .. rubric:: Example >>> self = CategoryPatterns.coerce(['superstar']) >>> dims = (64, 64) >>> cname = 'superstar' >>> xy_offset = None >>> self._todo_refactor_geometric_info(cname, xy_offset, dims) .. py:method:: _package_info(self, cname, data, mask, kpts, xy_offset, dims, newstyle) packages data from _from_elem into coco-like annotation .. py:method:: _from_elem(self, cname, chip, size=None) .. rubric:: Example >>> # hack to allow chip to be None >>> chip = None >>> size = (32, 32) >>> cname = 'superstar' >>> self = CategoryPatterns.coerce() >>> self._from_elem(cname, chip, size) .. py:function:: star(a, dtype=np.uint8) Generates a star shaped structuring element. Much faster than skimage.morphology version .. py:class:: Rasters .. py:method:: superstar() :staticmethod: test data patch .. py:method:: eff() :staticmethod: test data patch