Python 从撇渣机上移除填料';s try_all_threshold matplotlib图
我正在尝试自动保存scikit图像的Python 从撇渣机上移除填料';s try_all_threshold matplotlib图,python,matplotlib,seaborn,scikit-image,Python,Matplotlib,Seaborn,Scikit Image,我正在尝试自动保存scikit图像的try\u all\u threshold生成的图形 MWE: 输出包含大量填充,我必须删除这些填充: 我试过使用其他答案中建议的bbox\u inches='tight',pad\u inches=0,但没有效果 matplotlib删除所有填充缺少什么?您应该更改figsize以匹配您试图设置的图像的纵横比try\u all\u threshold将生成一个形状网格(4,2)以填充输入的图形大小。如果您的图像大部分是水平的,这会在垂直维度中提供大量空白。
try\u all\u threshold
生成的图形
MWE:
输出包含大量填充,我必须删除这些填充:
我试过使用其他答案中建议的bbox\u inches='tight',pad\u inches=0
,但没有效果
matplotlib删除所有填充缺少什么?您应该更改
figsize
以匹配您试图设置的图像的纵横比try\u all\u threshold
将生成一个形状网格(4,2)
以填充输入的图形大小。如果您的图像大部分是水平的,这会在垂直维度中提供大量空白。使用figsize=(6,5)
我对您的图像获得了一个不错的结果:
(编辑:
figsize=
以英寸(宽度、高度)表示。)您应该更改figsize
以匹配您试图设置的图像的纵横比try\u all\u threshold
将生成一个形状网格(4,2)
以填充输入的图形大小。如果您的图像大部分是水平的,这会在垂直维度中提供大量空白。使用figsize=(6,5)
我对您的图像获得了一个不错的结果:
(编辑:figsize=
以英寸为单位表示(宽度、高度)
#! /usr/bin/env python
import sys
import os
from pathlib import Path
import numpy
import skimage
from skimage import color, filters, io
import matplotlib as mpl
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
skimage.io.use_plugin("pil")
mpl.rcParams["font.family"] = ["sans-serif"]
mpl.rcParams["font.sans-serif"] = ["Linux Biolinum"]
mpl.rcParams["axes.titlesize"] = "medium"
def analyze(files):
for index, file in enumerate(files):
print("Analyzing {0}, please wait...".format(file))
try:
image = io.imread(file)
except ValueError as error:
print("Error when loading image, skipping: {0}".format(error))
continue
luma = color.rgb2gray(image)
# Threshold the image to obtain the reference borders
fig, ax = filters.try_all_threshold(
luma, figsize=(1, 2), verbose=False)
plt.show()
fig.savefig("test.png")
def main():
if len(sys.argv) > 1:
files = [path for path in sys.argv[1:] if Path(path).exists()]
if len(files) == 0:
print("No images to slice.")
else:
print("Found {0} images to slice.".format(len(files)))
analyze(files)
if __name__ == "__main__":
main()