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

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

问题描述

我正在使用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内联"图形分辨率,请执行以下操作:

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之前运行,否则magic命令会将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,而不更改嵌入式生成的图形的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天全站免登陆