<commit_before>from numpy import ndarray, asarray

from lightning.types.base import Base
from lightning.types.decorators import viztype
from lightning.types.utils import add_property, array_to_im, polygon_to_points, polygon_to_mask


@viztype
class Image(Base):
    _name = 'image'

    @staticmethod
    def clean(imagedata):
        """
        Display an array as an image.

        .. image:: image.png

        Parameters
        ----------
        imagedata : array-like
            Image as a two dimensional (grayscale) or three dimensional (RGB) array.
        """
        if asarray(imagedata).ndim not in set((2, 3)):
            raise Exception("Input must be two or three dimensional")

        outdict = [array_to_im(imagedata)]

        return {'images': outdict}

@viztype
class ImageDraw(Base):
    _name = 'image-draw'
    _func = 'imagedraw'
    
    @staticmethod
    def clean(imagedata, coordinates=None):
        """
        Display an array as an image with polygonal regions and region drawing.

        .. image:: image.png

        Parameters
        ----------
        imagedata : array-like
            Image as a two dimensional (grayscale) or three dimensional (RGB) array.

        coordinates : array-like
            List of coordinates or list of list of coordiantes, in the form
            [[x,y],[x,y]] for one region or a [[[x0,y0],[x0,y0]], [[x1,y1],[x1,y1]]]
        """
        if asarray(imagedata).ndim not in set((2, 3)):
            raise Exception("Input must be two or three dimensional")

        imgs = [array_to_im(imagedata)]
        outdict = {'images': imgs}
        outdict = add_property(outdict, coordinates, 'coordinates')<commit_msg>Renaming<commit_after>from numpy import ndarray, asarray

from lightning.types.base import Base
from lightning.types.decorators import viztype
from lightning.types.utils import add_property, array_to_im, polygon_to_points, polygon_to_mask


@viztype
class Image(Base):
    _name = 'image'

    @staticmethod
    def clean(imagedata):
        """
        Display an array as an image.

        .. image:: image.png

        Parameters
        ----------
        imagedata : array-like
            Image as a two dimensional (grayscale) or three dimensional (RGB) array.
        """
        if asarray(imagedata).ndim not in set((2, 3)):
            raise Exception("Input must be two or three dimensional")

        outdict = [array_to_im(imagedata)]

        return {'images': outdict}

@viztype
class ImagePoly(Base):
    _name = 'image-poly'
    _func = 'imagepoly'
    
    @staticmethod
    def clean(imagedata, coordinates=None):
        """
        Display an array as an image with polygonal regions and region drawing.

        .. image:: image.png

        Parameters
        ----------
        imagedata : array-like
            Image as a two dimensional (grayscale) or three dimensional (RGB) array.

        coordinates : array-like
            List of coordinates or list of list of coordiantes, in the form
            [[x,y],[x,y]] for one region or a [[[x0,y0],[x0,y0]], [[x1,y1],[x1,y1]]]
        """
        if asarray(imagedata).ndim not in set((2, 3)):
            raise Exception("Input must be two or three dimensional")

        imgs = [array_to_im(imagedata)]
        outdict = {'images': imgs}
        outdict = add_property(outdict, coordinates, 'coordinates')
{'fraction_non_alphanumeric': 0.11009174311926606, 'fraction_numerical': 0.007102693104468778, 'mean_word_length': 2.336623889437315, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4088890', 'n_tokens_mistral': 1004, 'n_tokens_neox': 962, 'n_words': 305}