内嵌图像质量低 [英] inline images have low quality

查看:24
本文介绍了内嵌图像质量低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在加载一个带有 scikit-image 的 TIF 文件,并在 ipython 笔记本(2.2.0 版)中内嵌显示它.但是,这是有效的,图像在第一次显示时非常小,当我使用图像右下角的可拖动手柄调整其大小时,它只是在保留原始分辨率的同时重新缩放图像,因此放大时非常模糊.基本上就像 ipython 正在将我的图像即时转换为缩略图一样.

I'm loading a TIF file with scikit-image and displaying it inline in an ipython notebook (version 2.2.0). This works, however, the image is quite small when first displayed, and when I resize it using the draggable handle on the bottom right of the image, it just rescales the image while retaining the resolution of the original, so it's very blurry when enlarged. It's basically as if ipython is converting my image into a thumbnail on the fly.

我也尝试过使用 matplotlib 的 plt.imshow(),结果完全相同.我正在使用 ipython notebook --pylab inline 启动笔记本.

I've tried using matplotlib's plt.imshow() as well, which has the exact same result. I'm starting the notebook with ipython notebook --pylab inline.

from skimage import io
import matplotlib.pyplot as plt
image_stack = io.MultiImage("my_image.tif")
image = image_stack[0]  # it's a multi-page TIF, this gets the first image in the stack

io.imshow(image)  # or plt.imshow(image)
io.show()  # or plt.show()

推荐答案

要更改笔记本上的%matplotlib inline"图形分辨率,请执行以下操作:

To change the "%matplotlib inline" figure resolution on the notebook do:

import matplotlib as mpl
mpl.rcParams['figure.dpi']= dpi

如果您要下载/打印笔记本,我建议将 dpi 设置在 150 到 300 之间.确保 %matplotlib inlinempl.rcParams['figure.dpi']= dpi 之前运行,否则魔法命令会将 dpi 重置为其默认值(归功于 @fabioedoardoluigialberto注意到这一点).

I recommend setting the dpi somewhere between 150 and 300 if you are going to download/print the notebook. Ensure that %matplotlib inline runs before the mpl.rcParams['figure.dpi']= dpi otherwise the magic command resets the dpi to its default value (credits to @fabioedoardoluigialberto for noticing this).

下面的代码片段仅更改通过 savefig 方法保存的图形的 dpi,而不更改内联生成的图形.

The snipppet below only changes the dpi of figures saved through the savefig method, not of inline generated figures.

import matplotlib as mpl
mpl.rc("savefig", dpi=dpi)

这篇关于内嵌图像质量低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆