Giter Site home page Giter Site logo

wkentaro / imgviz Goto Github PK

View Code? Open in Web Editor NEW
238.0 11.0 30.0 32.66 MB

Image Visualization Tools (object detection, semantic and instance segmentation)

Home Page: https://imgviz.readthedocs.io

License: MIT License

Python 98.62% Just 0.97% Makefile 0.41%
image-visualization deep-learning semantic-segmentation instance-segmentation object-detection

imgviz's People

Contributors

hmaarrfk avatar iory avatar wkentaro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imgviz's Issues

Visualize Semantic Segmentation with Legend

image

def draw_label(label, img=None, label_names=None, colormap=None, **kwargs):
    """Draw pixel-wise label with colorization and label names.
    label: ndarray, (H, W)
        Pixel-wise labels to colorize.
    img: ndarray, (H, W, 3), optional
        Image on which the colorized label will be drawn.
    label_names: iterable
        List of label names.
    """
    import matplotlib.pyplot as plt

    backend_org = plt.rcParams['backend']
    plt.switch_backend('agg')

    plt.subplots_adjust(left=0, right=1, top=1, bottom=0,
                        wspace=0, hspace=0)
    plt.margins(0, 0)
    plt.gca().xaxis.set_major_locator(plt.NullLocator())
    plt.gca().yaxis.set_major_locator(plt.NullLocator())

    if label_names is None:
        label_names = [str(l) for l in range(label.max() + 1)]

    colormap = _validate_colormap(colormap, len(label_names))

    label_viz = label2rgb(
        label, img, n_labels=len(label_names), colormap=colormap, **kwargs
    )
    plt.imshow(label_viz)
    plt.axis('off')

    plt_handlers = []
    plt_titles = []
    for label_value, label_name in enumerate(label_names):
        if label_value not in label:
            continue
        fc = colormap[label_value]
        p = plt.Rectangle((0, 0), 1, 1, fc=fc)
        plt_handlers.append(p)
        plt_titles.append('{value}: {name}'
                          .format(value=label_value, name=label_name))
    plt.legend(plt_handlers, plt_titles, loc='lower right', framealpha=.5)

    f = io.BytesIO()
    plt.savefig(f, bbox_inches='tight', pad_inches=0)
    plt.cla()
    plt.close()

    plt.switch_backend(backend_org)

    out_size = (label_viz.shape[1], label_viz.shape[0])
    out = PIL.Image.open(f).resize(out_size, PIL.Image.BILINEAR).convert('RGB')
    out = np.asarray(out)
    return out

AttributeError: type object 'Callable' has no attribute '_abc_registry'

Hi, when I try to install imgviz in Win10 64bit (python3.7), I got errors:

ERROR: Command errored out with exit status 1:
   command: 'E:\Applications\WPy64-3741\python-3.7.4.amd64\python.exe' 'E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip' install --ignore-installed --no-user --prefix 'D:\temp\Temp\pip-build-env-3ixr8qgd\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.tuna.tsinghua.edu.cn/simple -- 'setuptools>=40.8.0' wheel
       cwd: None
  Complete output (42 lines):
  Traceback (most recent call last):
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\runpy.py", line 193, in _run_module_as_main
      "__main__", mod_spec)
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\runpy.py", line 85, in _run_code
      exec(code, run_globals)
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip\__main__.py", line 26, in <module>
      sys.exit(_main())
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip\_internal\cli\main.py", line 73, in main
      command = create_command(cmd_name, isolated=("--isolated" in cmd_args))
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip\_internal\commands\__init__.py", line 104, in create_command
      module = importlib.import_module(module_path)
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\importlib\__init__.py", line 127, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
    File "<frozen importlib._bootstrap>", line 983, in _find_and_load
    File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
    File "<frozen importlib._bootstrap_external>", line 728, in exec_module
    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip\_internal\commands\install.py", line 17, in <module>
      from pip._internal.cli.req_command import RequirementCommand, with_cleanup
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip\_internal\cli\req_command.py", line 16, in <module>
      from pip._internal.index.collector import LinkCollector
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip\_internal\index\collector.py", line 14, in      from pip._vendor import html5lib, requests
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip\_vendor\requests\__init__.py", line 125, in <module>
      from . import utils
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip\_vendor\requests\utils.py", line 25, in <module>
      from . import certs
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip\_vendor\requests\certs.py", line 15, in <module>
      from pip._vendor.certifi import where
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip\_vendor\certifi\__init__.py", line 1, in <module>
      from .core import contents, where
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip\_vendor\certifi\core.py", line 12, in <module>
      from importlib.resources import path as get_path, read_text
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\importlib\resources.py", line 11, in <module>
      from typing import Iterable, Iterator, Optional, Set, Union   # noqa: F401
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\typing.py", line 1359, in <module>
      class Callable(extra=collections_abc.Callable, metaclass=CallableMeta):
    File "E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\typing.py", line 1007, in __new__
      self._abc_registry = extra._abc_registry
  AttributeError: type object 'Callable' has no attribute '_abc_registry'
  ----------------------------------------
ERROR: Command errored out with exit status 1: 'E:\Applications\WPy64-3741\python-3.7.4.amd64\python.exe' 'E:\Applications\WPy64-3741\python-3.7.4.amd64\lib\site-packages\pip' install --ignore-installed --no-user --prefix 'D:\temp\Temp\pip-build-env-3ixr8qgd\overlay' --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.tuna.tsinghua.edu.cn/simple -- 'setuptools>=40.8.0' wheel Check the logs for full command output.

How can I solve it?

Visualize Image Classification

def draw_image_classification_top5(img, label_names, proba):
    assert len(label_names) == len(proba)
    square_size = min(img.shape[:2])
    img = centerize(img, dst_shape=(square_size, square_size))
    # draw bars
    bars = np.zeros((square_size // 2, square_size, 3), dtype=np.uint8)
    bars.fill(255)
    step = square_size // (2 * 5)
    for i in range(5):
        y1 = step * i
        y2 = y1 + step
        x1 = 0
        x2 = int(square_size * proba[i])
        color = np.array((proba[i], 0, 1 - proba[i]))
        bars[y1:y2, x1:x2] = (color * 255).astype(np.uint8)
        bars[y1:y1+1, :] = 0
        bars[y2-1:y2, :] = 0
        label_name = label_names[i].split(' ')[1].strip(',')
        if _OPENCV_AVAILABLE:
            cv2.putText(bars, label_name,
                        (x1 + square_size // 2, y1 + step // 2),
                        cv2.FONT_HERSHEY_PLAIN, 1, (0, 0, 0))
        else:
            _warn_opencv_unavailable()
    bars = bars[:y2, :]
    img = np.vstack((img, bars))
    return img

Keys in pyglet_imshow are not handled correctly if numlock is enabled

Hi, I think I found a bug in the pyglet_imshow module.

These checks seem to cause the on_key_press function to return without any output/action if numlock (modifiers = 16) or capslock (modifiers = 8) is enabled. Is this desired behaviour?

if modifiers == 0:

if modifiers == 0:

if modifiers == 0:

Position deviation of boxes due to image padding

Hi, thanks for the convenient visualization tool. I just find a bug for drawing multiple boxes.

The problem is caused by the image padding for out of boundary text,

src = np.pad(
. When drawing multiple boxes sequentially, the first box has caption out of image boundary, then it will pad the image, then the image shape changes, which is incorrect to draw the second box.

Cannot install by pip install --user

Could you fix this?

$ pip install --user imgviz
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/__init__.py:83: RequestsDependencyWarning: Old version of cryptography ([1, 2, 3]) may cause slowdown.
  warnings.warn(warning, RequestsDependencyWarning)
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
WARNING: The directory '/home/ushun/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
WARNING: The directory '/home/ushun/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting imgviz
  Downloading https://files.pythonhosted.org/packages/40/d2/b3efc6d6a07d5dbd59ea4153ee19dbb2a96de8dff584d1f9c5b99a9d5d4b/imgviz-0.10.4.tar.gz (7.2MB)
     |████████████████████████████████| 7.2MB 335kB/s 
Requirement already satisfied: matplotlib in /usr/lib/python2.7/dist-packages (from imgviz) (1.5.1)
Requirement already satisfied: numpy in /usr/lib/python2.7/dist-packages (from imgviz) (1.11.0)
Collecting Pillow>=5.3.0
  Downloading https://files.pythonhosted.org/packages/12/ad/61f8dfba88c4e56196bf6d056cdbba64dc9c5dfdfbc97d02e6472feed913/Pillow-6.2.2-cp27-cp27mu-manylinux1_x86_64.whl (2.1MB)
     |████████████████████████████████| 2.1MB 1.5MB/s 
Building wheels for collected packages: imgviz
  WARNING: Building wheel for imgviz failed: [Errno 13] 許可がありません: '/home/ushun/.cache/pip/wheels/47'
Failed to build imgviz
Installing collected packages: Pillow, imgviz
    Running setup.py install for imgviz ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-c2CJn6/imgviz/setup.py'"'"'; __file__='"'"'/tmp/pip-install-c2CJn6/imgviz/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-NkSHWf/install-record.txt --single-version-externally-managed --compile --user --prefix=
         cwd: /tmp/pip-install-c2CJn6/imgviz/
    Complete output (50 lines):
    /usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'long_description_content_type'
      warnings.warn(msg)
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-2.7
    creating build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/draw.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/resize.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/color.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/instances.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/tile.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/depth.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/label.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/flow.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/normalize.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/centerize.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/nchannel.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/trajectory.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/__init__.py -> build/lib.linux-x86_64-2.7/imgviz
    copying imgviz/_version.py -> build/lib.linux-x86_64-2.7/imgviz
    creating build/lib.linux-x86_64-2.7/imgviz/data
    copying imgviz/data/__init__.py -> build/lib.linux-x86_64-2.7/imgviz/data
    creating build/lib.linux-x86_64-2.7/imgviz/external
    copying imgviz/external/transformations.py -> build/lib.linux-x86_64-2.7/imgviz/external
    copying imgviz/external/__init__.py -> build/lib.linux-x86_64-2.7/imgviz/external
    creating build/lib.linux-x86_64-2.7/imgviz/_io
    copying imgviz/_io/base.py -> build/lib.linux-x86_64-2.7/imgviz/_io
    copying imgviz/_io/opencv.py -> build/lib.linux-x86_64-2.7/imgviz/_io
    copying imgviz/_io/__init__.py -> build/lib.linux-x86_64-2.7/imgviz/_io
    copying imgviz/_io/pyplot.py -> build/lib.linux-x86_64-2.7/imgviz/_io
    copying imgviz/_io/_pyglet.py -> build/lib.linux-x86_64-2.7/imgviz/_io
    creating build/lib.linux-x86_64-2.7/imgviz/data/kitti
    copying imgviz/data/kitti/__init__.py -> build/lib.linux-x86_64-2.7/imgviz/data/kitti
    creating build/lib.linux-x86_64-2.7/imgviz/data/lena
    copying imgviz/data/lena/__init__.py -> build/lib.linux-x86_64-2.7/imgviz/data/lena
    creating build/lib.linux-x86_64-2.7/imgviz/data/arc2017
    copying imgviz/data/arc2017/__init__.py -> build/lib.linux-x86_64-2.7/imgviz/data/arc2017
    creating build/lib.linux-x86_64-2.7/imgviz/data/middlebury
    copying imgviz/data/middlebury/__init__.py -> build/lib.linux-x86_64-2.7/imgviz/data/middlebury
    running egg_info
    writing requirements to imgviz.egg-info/requires.txt
    writing imgviz.egg-info/PKG-INFO
    writing top-level names to imgviz.egg-info/top_level.txt
    writing dependency_links to imgviz.egg-info/dependency_links.txt
    reading manifest file 'imgviz.egg-info/SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    writing manifest file 'imgviz.egg-info/SOURCES.txt'
    error: can't copy 'imgviz/data/kitti': doesn't exist or not a regular file
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-c2CJn6/imgviz/setup.py'"'"'; __file__='"'"'/tmp/pip-install-c2CJn6/imgviz/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-NkSHWf/install-record.txt --single-version-externally-managed --compile --user --prefix= Check the logs for full command output.
WARNING: You are using pip version 19.3; however, version 19.3.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

My environment:

$ python --version
Python 2.7.12
$ pip show pip
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Name: pip
Version: 19.3
Summary: The PyPA recommended tool for installing Python packages.
Home-page: https://pip.pypa.io/
Author: The pip developers
Author-email: [email protected]
License: MIT
Location: /usr/local/lib/python2.7/dist-packages
Requires: 
Required-by: 

`text_in_rectangle` behavior is unclear

Here's a short example that demonstrates multiple oddities with the use case of drawing text within a box.

import imgviz
import numpy as np
import matplotlib.pyplot as plt

img = np.zeros((600, 400, 3), np.uint8)

x1, y1 = (100, 100)
x2, y2 = (300, 200)

img = imgviz.draw.text_in_rectangle(img, loc="lt", text="long texttttttttttttttttttttttt", size=30, background=(0, 0, 255), aabb1=(y1, x1), aabb2=(y2, x2))
img = imgviz.draw.text_in_rectangle(img, loc="lt", text="\nshort", size=30, background=(255, 0, 0), aabb1=(y1, x1), aabb2=(y2, x2))
img = imgviz.draw.rectangle(img, (y1, x1), (y2, x2), outline=(0, 255, 0), width=1)

plt.figure()
plt.imshow(img)
plt.show()

Result:
imgviz

Observations:

  • text_in_rectangle sounds like it would draw a rectangle specified by the two provided rectangle corners, whereas what it does is draw text with a background for that text
  • It's unclear to me how to make sense of loc and keep_size even after playing around with it
  • It's unclear to me why the second rectangle corner should be provided given that no rectangle is being drawn there per se, and the size of the text background doesn't respect the specified rectangle dimensions in any way.
  • The background for the text doesn't always cover the extent of the text.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.