def from_dataset_item(cls: type["ImageResult"], item: ImageItem | NumpyImageItem) -> "ImageResult":
        """Create an ImageResult object from a DatasetItem object.

        This is a temporary solution until we refactor the visualizer to take a
        DatasetItem object directly as input.

        Args:
            item (ImageItem | NumpyImageItem): Dataset item to convert

        Returns:
            ImageResult: New image result object
        """
        if isinstance(item, ImageItem):
            item = item.to_numpy()
        item_dict = asdict(item)
        field_names = {field.name for field in fields(cls)} & set(item_dict.keys())
        return cls(**{key: item_dict[key] for key in field_names})
Create an ImageResult object from a DatasetItem object.

        This is a temporary solution until we refactor the visualizer to take a
        DatasetItem object directly as input.

        Args:
            item (ImageItem | NumpyImageItem): Dataset item to convert

        Returns:
            ImageResult: New image result object
        
src/anomalib/utils/visualization/image.py