729-2

1 高斯滤波(Gaussian filter)

拟合函数-project3:code

    sigma_x = 0.  # 0.0001
    sigma_y = 0.
    sigma = [sigma_y, sigma_x]
    Exact = scipy.ndimage.filters.gaussian_filter(Exact, sigma, mode='constant')

1.1 c++ 代码实现

https://blog.csdn.net/geduo_feng/article/details/81604921

1.2 python实现

https://blog.csdn.net/sunmc1204953974/article/details/50634652
什么是高通?什么是低通?

1 单色-灰度图

import matplotlib as mpl
mpl.use('TkAgg')
from PIL import Image
from pylab import *
from numpy import *
from scipy.ndimage import filters

#读取图片,灰度化并转为数组
im = array(Image.open('test.jpg').convert('L'))
#进行σ = 2的高斯滤波
im2 = filters.gaussian_filter(im,2)
#进行σ = 5的高斯滤波
im3 = filters.gaussian_filter(im,5)
#进行σ = 10的高斯滤波
im4 = filters.gaussian_filter(im,10)

#显示图像
gray()
subplot(141)
title('source')
imshow(im)

subplot(142)
title('sigma=2')
imshow(im2)

subplot(143)
title('sigma=5')
imshow(im3)

subplot(144)
title('sigma=10')
imshow(im4)
show()

在这里插入图片描述

2 彩色

import matplotlib as mpl
mpl.use('TkAgg')
from PIL import Image
from pylab import *
from numpy import *
from scipy.ndimage import filters
import copy

#读取图片,灰度化并转为数组
im = array(Image.open('test.jpg'))
#r通道
r = im[:,:,0]
#g通道
g = im[:,:,1]
#b通道
b = im[:,:,2]

#对r通道进行σ = 2的高斯滤波
r = filters.gaussian_filter(r,20)
#对g通道进行σ = 2的高斯滤波
g = filters.gaussian_filter(g,20)
#对b通道进行σ = 2的高斯滤波
b = filters.gaussian_filter(b,20)

#组合各通道
im2 = copy.deepcopy(im)
im2[:,:,0] = r
im2[:,:,1] = g
im2[:,:,2] = b

#显示图像
subplot(121)
title('source')
imshow(im)

subplot(122)
title('After GaussFilter')
imshow(im2)

show()       

在这里插入图片描述

matlab实现:
https://blog.csdn.net/ytang_/article/details/52749497

2 pycharm设置

参考:
https://www.cnblogs.com/wendj/archive/2018/09/21/9685012.html

第一步:

在这里插入图片描述
第二步:
在这里插入图片描述

3 python使用

3.1 meshgrid函数–用得比较多

import numpy as np

x = np.array([0,1,2,3])
y = np.array([0,1,2,3,4])
m,n = np.meshgrid(x,y)
print(m.shape)
print(n.shape)
print(m)
print(n)

(5, 4)
(5, 4)
[[0 1 2 3]
 [0 1 2 3]
 [0 1 2 3]
 [0 1 2 3]
 [0 1 2 3]]
[[0 0 0 0]
 [1 1 1 1]
 [2 2 2 2]
 [3 3 3 3]
 [4 4 4 4]]

3.2 mgrid函数??

3.3 查看所有的关键字

help("keywords")

Here is a list of the Python keywords.  Enter any keyword to get more help.

False               def                 if                  raise
None                del                 import              return
True                elif                in                  try
and                 else                is                  while
as                  except              lambda              with
assert              finally             nonlocal            yield
break               for                 not                 
class               from                or                  
continue            global              pass                

当时是【lambda】没有认识到 也是一个关键字

3.4 help的使用

查看python所有的modules:help("modules")
单看python所有的modules中包含指定字符串的modules: help("modules yourstr")
查看python中常见的topics: help("topics")
查看python标准库中的module:import os.path + help("os.path")
查看python内置的类型:help("list")
查看python类型的成员方法:help("str.find") 
查看python内置函数:help("open")

3.5 Matplotlib:TkAgg、Agg问题backend(编译器后端)

参考:https://www.cnblogs.com/bymo/p/7447409.html

总结的解决方法如下:

1.画图是现在ipython下作图,发现直接操作就行。

2.当用pycharm时,会加上:
import matplotlib as mpl 
mpl.use('TkAgg')

3.当远程作图时,会加上:
import matplotlib.pyplot as plt
plt.switch_backend('agg')
这个函数实际上就是
def switch_backend(newbackend):
    ...
    matplotlib.use(newbackend, warn=False, force=True)
	...
所以也等价于
import matplotlib as mpl 
mpl.use('agg')

1.问题:在本地用matplotlib绘图可以,但是在ssh远程绘图的时候会报错 RuntimeError: Invalid DISPLAY variable

2.原因:matplotlib的默认backend是TkAgg,而FltkAgg, GTK, GTKAgg, GTKCairo, TkAgg , Wx or WxAgg这几个backend都要求有GUI图形界面的,所以在ssh操作的时候会报错.
验证一下:

ipython下:
import matplotlib.pyplot as plt
print(plt.get_backend())
#module://ipykernel.pylab.backend_inline

pycharm下:
import matplotlib.pyplot as plt
print(plt.get_backend())
#TkAgg

ssh下:
import matplotlib.pyplot as plt
plt.get_backend()
'agg'

所以在远程作图时,我们调用了matplotlib,此时默认的是TkAgg,而ssh没有GUI,所以是agg。

3.解决方法:指定不需要GUI的backend(Agg, Cairo, PS, PDF or SVG)
那么就需要改matplotlib的backend为不需要GUI的backend(Agg, Cairo, PS, PDF or SVG)。

import matplotlib.pyplot as plt
plt.switch_backend('agg')

4.源码

去ipython里面查看函数源码:

def switch_backend(newbackend):
    """
    Switch the default backend.  This feature is **experimental**, and
    is only expected to work switching to an image backend.  e.g., if
    you have a bunch of PostScript scripts that you want to run from
    an interactive ipython session, you may want to switch to the PS
    backend before running them to avoid having a bunch of GUI windows
    popup.  If you try to interactively switch from one GUI backend to
    another, you will explode.

    Calling this command will close all open windows.
    """
    close('all')
    global _backend_mod, new_figure_manager, draw_if_interactive, _show
    
    
    matplotlib.use(newbackend, warn=False, force=True)----主要部分!!!
    
    
	from matplotlib.backends import pylab_setup
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
def use(arg, warn=True, force=False):
    """
    Set the matplotlib backend to one of the known backends.

    The argument is case-insensitive. *warn* specifies whether a
    warning should be issued if a backend has already been set up.
    *force* is an **experimental** flag that tells matplotlib to
    attempt to initialize a new backend by reloading the backend
    module.

    .. note::

        This function must be called *before* importing pyplot for
        the first time; or, if you are not using pyplot, it must be called
        before importing matplotlib.backends.  If warn is True, a warning
        is issued if you try and call this after pylab or pyplot have been
        loaded.  In certain black magic use cases, e.g.
        :func:`pyplot.switch_backend`, we are doing the reloading necessary to
        make the backend switch work (in some cases, e.g., pure image
        backends) so one can set warn=False to suppress the warnings.

    To find out which backend is currently set, see
    :func:`matplotlib.get_backend`.

    """
    # Lets determine the proper backend name first
    if arg.startswith('module://'):
        name = arg
    else:
        # Lowercase only non-module backend names (modules are case-sensitive)
        arg = arg.lower()
        name = validate_backend(arg)

    # Check if we've already set up a backend
    if 'matplotlib.backends' in sys.modules:
        # Warn only if called with a different name
        if (rcParams['backend'] != name) and warn:
            warnings.warn(_use_error_msg)

        # Unless we've been told to force it, just return
        if not force:
            return
        need_reload = True
    else:
        need_reload = False

    # Store the backend name
    rcParams['backend'] = name

    # If needed we reload here because a lot of setup code is triggered on
    # module import. See backends/__init__.py for more detail.
    if need_reload:
        reload(sys.modules['matplotlib.backends'])

3.6 Matplotlib:mpl_toolkits.mplot3d工具包

参考:
https://www.jianshu.com/p/b563920fa7a8

1.简介:
mpl_toolkits.mplot3d是Matplotlib里面专门用来画三维图的工具包,官方指南请点击此处《mplot3d tutorial》
https://matplotlib.org/tutorials/toolkits/mplot3d.html
2.使用:
导入–使用from mpl_toolkits.mplot3d import *或者import mpl_toolkits.mplot3d as p3d
画图–

有两种方式

fig = plt.figure()
ax = p3d.Axes3D(fig)

或者

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

3.练习:
画三维图需要先得到一个Axes3D对象,上面两种方式得到的ax都是Axes3D对象,接下来就可以调用函数在ax上画图了。如下(IPython):

import numpy as np
import matplotlib as mpl
mpl.use('TkAgg')
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d as p3d

fig = plt.figure()
ax = p3d.Axes3D(fig)

z = np.linspace(0, 15, 1000)
x = np.sin(z)
y = np.cos(z)
ax.plot(x, y, z, 'green')
plt.show()

在这里插入图片描述

4 linux下proxy设定的一般方法

代理服务器配置的相关问题,服务器是离线的,使用代理的方式来连接网络。
参考:https://www.cnblogs.com/liyuzhao/p/4398829.html

1.linux下proxy的常规设置
一般是把如下环境变量的设置放到/etc/profile.d/proxy.sh文件中。 对于没有系统权限的用户,可以将下面的内容添加到自己用户目录下的.profile文件中。 这样登录后,大多数的应用程序都可以正常上网。

#proxy=http://用户名:密码@ProxyURL或IP地址:端口号
proxy=http://ProxyURL或IP地址:端口号
export http_proxy=$proxy
export https_proxy=$proxy
export ftp_proxy=$proxy

export no_proxy=以逗号分隔的除外列表

2.CentOS的yum工具的proxy设置
CentOS下,设置了上述proxy后,yum还是有不能正确下载有些资源包的情况,可以通过在 /etc/yum.conf文件中添加如下内容来单独设置proxy。

proxy=http://ProxyURL或IP地址:端口号
proxy_username=用户名
proxy_password=密码

5 yum

这个问题出现在,当使用tex公式在Ubuntu下远程作图时,就报错了。
之后想到的解决办法:要么就使用红帽系统;要么就使用 ssh -x 登录就有图像界面啦

报错为:[Python] RuntimeError: Invalid DISPLAY variable

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值