Пример #1
0
def test_image_filename_defaults():
    '''test format constraint, and validity of jpeg and png'''
    tpath = ipath.get_ipython_package_dir()
    nt.assert_raises(ValueError,
                     display.Image,
                     filename=os.path.join(tpath,
                                           'testing/tests/badformat.gif'),
                     embed=True)
    nt.assert_raises(ValueError, display.Image)
    nt.assert_raises(ValueError,
                     display.Image,
                     data='this is not an image',
                     format='badformat',
                     embed=True)
    from IPython.html import DEFAULT_STATIC_FILES_PATH
    # check boths paths to allow packages to test at build and install time
    imgfile = os.path.join(tpath, 'html/static/base/images/logo.png')
    if not os.path.exists(imgfile):
        imgfile = os.path.join(DEFAULT_STATIC_FILES_PATH,
                               'base/images/logo.png')
    img = display.Image(filename=imgfile)
    nt.assert_equal('png', img.format)
    nt.assert_is_not_none(img._repr_png_())
    img = display.Image(filename=os.path.join(tpath, 'testing/tests/logo.jpg'),
                        embed=False)
    nt.assert_equal('jpeg', img.format)
    nt.assert_is_none(img._repr_jpeg_())
Пример #2
0
def test_image_filename_defaults():
    """test format constraint, and validity of jpeg and png"""
    tpath = ipath.get_ipython_package_dir()
    nt.assert_raises(
        ValueError,
        display.Image,
        filename=os.path.join(tpath, "testing/tests/badformat.zip"),
        embed=True,
    )
    nt.assert_raises(ValueError, display.Image)
    nt.assert_raises(
        ValueError,
        display.Image,
        data="this is not an image",
        format="badformat",
        embed=True,
    )
    # check boths paths to allow packages to test at build and install time
    imgfile = os.path.join(tpath, "core/tests/2x2.png")
    img = display.Image(filename=imgfile)
    nt.assert_equal("png", img.format)
    nt.assert_is_not_none(img._repr_png_())
    img = display.Image(filename=os.path.join(tpath, "testing/tests/logo.jpg"),
                        embed=False)
    nt.assert_equal("jpeg", img.format)
    nt.assert_is_none(img._repr_jpeg_())
Пример #3
0
def test_image_size():
    """Simple test for display.Image(args, width=x,height=y)"""
    thisurl = 'http://www.google.fr/images/srpr/logo3w.png'
    img = display.Image(url=thisurl, width=200, height=200)
    nt.assert_equal(u'<img src="%s" width="200" height="200"/>' % (thisurl), img._repr_html_())
    img = display.Image(url=thisurl, width=200)
    nt.assert_equal(u'<img src="%s" width="200"/>' % (thisurl), img._repr_html_())
    img = display.Image(url=thisurl)
    nt.assert_equal(u'<img src="%s"/>' % (thisurl), img._repr_html_())
Пример #4
0
def test_image_size():
    """Simple test for display.Image(args, width=x,height=y)"""
    thisurl = 'http://www.google.fr/images/srpr/logo3w.png'
    img = display.Image(url=thisurl, width=200, height=200)
    nt.assert_equal(u'<img src="%s" width="200" height="200"/>' % (thisurl), img._repr_html_())
    img = display.Image(url=thisurl, metadata={'width':200, 'height':200})
    nt.assert_equal(u'<img src="%s" width="200" height="200"/>' % (thisurl), img._repr_html_())
    img = display.Image(url=thisurl, width=200)
    nt.assert_equal(u'<img src="%s" width="200"/>' % (thisurl), img._repr_html_())
    img = display.Image(url=thisurl)
    nt.assert_equal(u'<img src="%s"/>' % (thisurl), img._repr_html_())
    img = display.Image(url=thisurl, unconfined=True)
    nt.assert_equal(u'<img src="%s" class="unconfined"/>' % (thisurl), img._repr_html_())
Пример #5
0
def test_image_filename_defaults():
    '''test format constraint, and validity of jpeg and png'''
    tpath = ipath.get_ipython_package_dir()
    nt.assert_raises(ValueError, display.Image, filename=os.path.join(tpath, 'testing/tests/badformat.gif'),
                     embed=True)
    nt.assert_raises(ValueError, display.Image)
    nt.assert_raises(ValueError, display.Image, data='this is not an image', format='badformat', embed=True)
    # check boths paths to allow packages to test at build and install time
    imgfile = os.path.join(tpath, 'core/tests/2x2.png')
    img = display.Image(filename=imgfile)
    nt.assert_equal('png', img.format)
    nt.assert_is_not_none(img._repr_png_())
    img = display.Image(filename=os.path.join(tpath, 'testing/tests/logo.jpg'), embed=False)
    nt.assert_equal('jpeg', img.format)
    nt.assert_is_none(img._repr_jpeg_())
Пример #6
0
def test_image_mimes():
    fmt = get_ipython().display_formatter.format
    for format in display.Image._ACCEPTABLE_EMBEDDINGS:
        mime = display.Image._MIMETYPES[format]
        img = display.Image(b'garbage', format=format)
        data, metadata = fmt(img)
        nt.assert_equal(sorted(data), sorted([mime, 'text/plain']))
Пример #7
0
def _display_canvas(canvas):
    with tempfile.NamedTemporaryFile(suffix=".png") as file_png:
        canvas.SaveAs(file_png.name)
        ip_img = display.Image(filename=file_png.name,
                               format='png',
                               embed=True)
    return ip_img._repr_png_()
Пример #8
0
def _display_any(obj):
    file = tempfile.NamedTemporaryFile(suffix=".png")
    obj.Draw()
    ROOT.gPad.SaveAs(file.name)
    ip_img = display.Image(filename=file.name, format='png', embed=True)
    print("trying to display canvas")
    return ip_img._repr_png_()
Пример #9
0
def _draw_image(meth, *args, **kwargs):
    file_handle = tempfile.NamedTemporaryFile(suffix='.png')
    with preserve_current_canvas():
        canvas = Canvas()
        meth(*args, **kwargs)
        canvas.SaveAs(file_handle.name)
    return display.Image(filename=file_handle.name, format='png', embed=True)
Пример #10
0
def test_retina_jpeg():
    here = os.path.dirname(__file__)
    img = display.Image(os.path.join(here, "2x2.jpg"), retina=True)
    nt.assert_equal(img.height, 1)
    nt.assert_equal(img.width, 1)
    data, md = img._repr_jpeg_()
    nt.assert_equal(md['width'], 1)
    nt.assert_equal(md['height'], 1)
Пример #11
0
def test_retina_png():
    here = os.path.dirname(__file__)
    img = display.Image(os.path.join(here, "2x2.png"), retina=True)
    nt.assert_equal(img.height, 1)
    nt.assert_equal(img.width, 1)
    data, md = img._repr_png_()
    nt.assert_equal(md["width"], 1)
    nt.assert_equal(md["height"], 1)
Пример #12
0
def _display_any(obj):
    with tempfile.NamedTemporaryFile(suffix=".png") as file_png:
        obj.Draw()
        ROOT.gPad.SaveAs(file_png.name)
        ip_img = display.Image(filename=file_png.name,
                               format='png',
                               embed=True)
    return ip_img._repr_png_()
Пример #13
0
def display_canvas(canvas):
    """Helper method for drawing a ROOT canvas inline, used with python magic functions"""
    if rootv == 5:
        file = tempfile.NamedTemporaryFile(suffix=".png")
        canvas.SaveAs(file.name)
        display.display(
            display.Image(filename=file.name, format='png', embed=True))
    else:
        canvas.Draw()
Пример #14
0
def display_pil_image(im):
    """Displayhook function for PIL Images, rendered as PNG."""

    b = BytesIO()
    im.save(b, format='png')
    data = b.getvalue()

    ip_img = display.Image(data=data, format='png', embed=True)
    return ip_img._repr_png_()
Пример #15
0
def _display_any(obj):
    """Helper method for drawing a ROOT canvas inline, used with python magic functions"""
    if rootv == 5:
        file = tempfile.NamedTemporaryFile(suffix=".png")
        obj.Draw()
        ROOT.gPad.SaveAs(file.name)
        ip_img = display.Image(filename=file.name, format='png', embed=True)
        return ip_img._repr_png_()
    else:
        obj.Draw()
Пример #16
0
def display_cairo_surface(surface):
    """Displayhook function for Surfaces Images, rendered as PNG."""
    b = BytesIO()

    surface.write_to_png(b)
    b.seek(0)
    data = b.read()

    ip_img = display.Image(data=data, format='png', embed=True)
    return ip_img._repr_png_()
Пример #17
0
def PlotDot(dot: str) -> None:
  """Compile and display the given dot plot."""
  with tempfile.TemporaryDirectory() as d:
    dot_path = pathlib.Path(d) / "dot.dot"
    png_path = pathlib.Path(d) / "dot.png"

    fs.Write(dot_path, dot.encode("utf-8"))
    try:
      subprocess.check_call(
        ["dot", str(dot_path), "-Tpng", "-o", str(png_path)]
      )
    except subprocess.CalledProcessError as e:
      raise ValueError(f"Failed to process dotgraph: {dot}")
    display.display(display.Image(filename=f"{d}/dot.png"))
Пример #18
0
def test_image_filename_defaults():
    '''test format constraint, and validity of jpeg and png'''
    tpath = ipath.get_ipython_package_dir()
    nt.assert_raises(ValueError,
                     display.Image,
                     filename=os.path.join(tpath,
                                           'testing/tests/badformat.gif'),
                     embed=True)
    nt.assert_raises(ValueError, display.Image)
    nt.assert_raises(ValueError,
                     display.Image,
                     data='this is not an image',
                     format='badformat',
                     embed=True)
    imgfile = os.path.join(tpath,
                           'frontend/html/notebook/static/ipynblogo.png')
    img = display.Image(filename=imgfile)
    nt.assert_equal('png', img.format)
    nt.assert_is_not_none(img._repr_png_())
    img = display.Image(filename=os.path.join(tpath, 'testing/tests/logo.jpg'),
                        embed=False)
    nt.assert_equal('jpeg', img.format)
    nt.assert_is_none(img._repr_jpeg_())
Пример #19
0
# load model
print('loading pretrained model from %s' % model_path)
if params.multi_gpu:
    model = torch.nn.DataParallel(model)
model.load_state_dict(torch.load(model_path))

converter = utils.strLabelConverter(params.alphabet)

transformer = dataset.resizeNormalize((100, 32))
image = Image.open(image_path).convert('L')
image = transformer(image)
if torch.cuda.is_available():
    image = image.cuda()
image = image.view(1, *image.size())
image = Variable(image)

model.eval()
preds = model(image)

_, preds = preds.max(2)
preds = preds.transpose(1, 0).contiguous().view(-1)

preds_size = Variable(torch.IntTensor([preds.size(0)]))
raw_pred = converter.decode(preds.data, preds_size.data, raw=True)
sim_pred = converter.decode(preds.data, preds_size.data, raw=False)
display.display(display.Image(image_path))
print(image_path)
print('%-20s => %-20s' % (raw_pred, sim_pred))

f = open("crnn_test.txt", "w+")
Пример #20
0
    dot_path = pathlib.Path(d) / "dot.dot"
    png_path = pathlib.Path(d) / "dot.png"

    fs.Write(dot_path, dot.encode("utf-8"))
    try:
      subprocess.check_call(
<<<<<<< HEAD
<<<<<<< HEAD:labm8/py/viz.py
        ["dot", str(dot_path), "-Tpng", "-o", str(png_path)]
      )
=======
          ['dot', str(dot_path), '-Tpng', '-o',
           str(png_path)])
>>>>>>> 8be094257... Move //labm8 to //labm8/py.:labm8/py/viz.py
    except subprocess.CalledProcessError as e:
      raise ValueError(f"Failed to process dotgraph: {dot}")
    display.display(display.Image(filename=f"{d}/dot.png"))
=======
  percs = ' '.join(
      [f'{p}%={np.percentile(arr, p):.0f}' for p in [0, 50, 95, 99, 100]],)
  return (f'n={len(arr)}, mean={arr.mean():.2f}, stdev={arr.std():.2f}, '
          f'percentiles=[{percs}]')
>>>>>>> 49340dc00... Auto-format labm8 python files.:labm8/viz.py
=======
        ["dot", str(dot_path), "-Tpng", "-o", str(png_path)]
      )
    except subprocess.CalledProcessError as e:
      raise ValueError(f"Failed to process dotgraph: {dot}")
    display.display(display.Image(filename=f"{d}/dot.png"))
>>>>>>> 4242aed2a... Automated code format.
Пример #21
0
def test_base64image():
    display.Image("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAWJLR0QAiAUdSAAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB94BCRQnOqNu0b4AAAAKSURBVAjXY2AAAAACAAHiIbwzAAAAAElFTkSuQmCC")
Пример #22
0
def _display_canvas(canvas):
    file = tempfile.NamedTemporaryFile(suffix=".png")
    canvas.SaveAs(file.name)
    ip_img = display.Image(filename=file.name, format='png', embed=True)
    print("trying to display canvas")
    return ip_img._repr_png_()
def _display_any(obj):
    file = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
    obj.Draw()
    ROOT.gPad.SaveAs(file.name)
    ip_img = display.Image(filename=file.name, format='png', embed=True)
    return ip_img._repr_png_()
Пример #24
0
def _display_canvas(canvas):
    file_handle = tempfile.NamedTemporaryFile(suffix='.png')
    canvas.SaveAs(file_handle.name)
    ip_img = display.Image(filename=file_handle.name, format='png', embed=True)
    return ip_img._repr_png_()