发布网友
共3个回答
懂视网
本文主要给大家介绍windows上安装Anaconda和python的教程详解,非常不错,具有参考借鉴价值,需要的朋友参考下
一提到数字图像处理编程,可能大多数人就会想到matlab,但matlab也有自身的缺点:
1、不开源,价格贵
2、软件容量大。一般3G以上,高版本甚至达5G以上。
3、只能做研究,不易转化成软件。
因此,我们这里使用Python这个脚本语言来进行数字图像处理。
要使用Python,必须先安装python,一般是2.7版本以上,不管是在windows系统,还是Linux系统,安装都是非常简单的。
要使用python进行各种开发和科学计算,还需要安装对应的包。这和matlab非常相似,只是matlab里面叫工具箱(toolbox),而python里面叫库或包。基于python脚本语言开发的数字图片处理包,其实很多,比如PIL,Pillow, OpenCV, scikit-image等。
对比这些包,PIL和Pillow只提供最基础的数字图像处理,功能有限;OpenCV实际上是一个c++库,只是提供了python接口,更新速度非常慢。到现在python都发展到了3.5版本,而opencv只支持到python 2.7版本;scikit-image是基于scipy的一款图像处理包,它将图片作为numpy数组进行处理,正好与matlab一样,因此,我们最终选择scikit-image进行数字图像处理。
一、需要的安装包
因为scikit-image是基于scipy进行运算的,因此安装numpy和scipy是肯定的。要进行图片的显示,还需要安装matplotlib包,综合起来,需要的包有:
Python >= 2.6 Numpy >= 1.6.1 Cython >= 0.21 Six >=1.4 SciPy >=0.9 Matplotlib >= 1.1.0 NetworkX >= 1.8 Pillow >= 1.7.8 dask[array] >= 0.5.0
比较,安装起来非常费事,尤其是scipy,在windows上基本安装不上。
但是不用怕,我们选择一款集成安装环境就行了,在此推荐Anaconda, 它把以上需要的包都集成在了一起,因此我们实际上从头到尾只需要安装Anaconda软件就行了,其它什么都不用装。
二、下载并安装 anaconda
先到www.continuum.io/downloads 下载anaconda, 现在的版本有python2.7版本和python3.5版本,下载好对应版本、对应系统的anaconda,它实际上是一个sh脚本文件,大约280M左右。
本系列以windows7+python3.5为例,因此我们下载如下图红框里的版本:
名称为: Anaconda3-2.4.1-Windows-x86_.exe
是一个可执行的exe文件,下载完成好,直接双击就可以安装了。
在安装的时候,假设我们安装在D盘根目录,如:
并且将两个选项都选上,将安装路径写入环境变量。
然后等待安装完成就可以了。
安装完成后,打开windows的命令提示符:
输入conda list 就可以查询现在安装了哪些库,常用的numpy, scipy名列其中。如果你还有什么包没有安装上,可以运行
conda install *** 来进行安装。(***为需要的包的名称)
如果某个包版本不是最新的,运行 conda update *** 就可以更新了。
三、简单测试
anaconda自带了一款编辑器spyder,我们以后就可以用这款编辑器来编写代码。
spyder.exe放在安装目录下的scripts里面,如我的是 D:/Anaconda3/scripts/spyder.exe, 直接双击就能运行。我们可以右键发送到桌面快捷方式,以后运行就比较方便了。
我们简单编写一个程序来测试一下安装是否成功,该程序用来打开一张图片并显示。首先准备一张图片,然后打开spyder,编写如下代码:
from skimage import io img=io.imread('d:/dog.jpg') io.imshow(img)
将其中的d:/dog.jpg 改成你的图片位置
然后点击上面工具栏里的绿色三角进行运行,最终显示
如果右下角“ Ipython console" 能显示出图片,说明我们的运行环境安装成功。
我们可以选择右上角的 ” variable explorer" 来查看图片信息,如
我们可以把这个程序保存起来,注意python脚本文件的后缀名为py.
四、skimage包的子模块
skimage包的全称是scikit-image SciKit (toolkit for SciPy) ,它对scipy.ndimage进行了扩展,提供了更多的图片处理功能。它是由python语言编写的,由scipy 社区开发和维护。skimage包由许多的子模块组成,各个子模块提供不同的功能。主要子模块列表如下:
子模块名称 | 主要实现功能 |
io | 读取、保存和显示图片或视频 |
data | 提供一些测试图片和样本数据 |
color | 颜色空间变换 |
filters | 图像增强、边缘检测、排序滤波器、自动阈值等 |
draw | 操作于numpy数组上的基本图形绘制,包括线条、矩形、圆和文本等 |
transform | 几何变换或其它变换,如旋转、拉伸和拉东变换等 |
morphology | 形态学操作,如开闭运算、骨架提取等 |
exposure | 图片强度调整,如亮度调整、直方图均衡等 |
feature | 特征检测与提取等 |
measure | 图像属性的测量,如相似性或等高线等 |
segmentation | 图像分割 |
restoration | 图像恢复 |
util | 通用函数 |
用到一些图片处理的操作函数时,需要导入对应的子模块,如果需要导入多个子模块,则用逗号隔开,如:
from skimage import io,data,color
热心网友
How to set up your own anaconda in a scientific way?
python2, python3, R in conda
Introction
what is anaconda?
According to its own website, Anaconda is the leading open data science platform powered by Python. The open source version of Anaconda is a high performance distribution of Python and R and includes over 100 of the most popular Python, R and Scala packages for data science.
Or you can simply regard it as a manager of the packages of your programming languages.
why we want to use anaconda?
Convinient to manage packages
Jupyter notebook
object
Set up anaconda for a python and r user (linux)
I use py2 more often so I set it my default environment
Get started!
Click this link and download corresponding version of anaconda.
Type the following line in the terminal and the installation will be set up automatically
```bash Anaconda2-4.3.1-Linux-x86_.sh``` .Do include the "bash" command even if you are not using the bash shell.
Add the following line to the .bashrc or .zshrc(if you are a zsh user).
```export PATH="/home/zijun/anaconda2/bin:$PATH"```Create python3 environment in your conda.
```conda create -n py3 python=3.5 anaconda```Create R environment in your conda.
```conda create -n r -c r r-essentials```Install tck for R (enable install.packages() in R)
```source activate rNote1: if you want to remove environment you install:
```conda remove --name py3 --all```Note2: switch different environment
```source activate rSome issues you may encounter ring the process
Q: tcl not found
install.packages('highfrequency')
--- Please select a CRAN mirror for use in this session ---
Error: .onLoad failed in loadNamespace() for 'tcltk', details:
call: fun(libname, pkgname)
error: Can't find a usable init.tcl in the following directories:
/opt/anaconda1anaconda2anaconda3/lib/tcl8.5 ./lib/tcl8.5 ./lib/tcl8.5 ./library ./library ./tcl8.5.18/library ./tcl8.5.18/library
A: Solution:
Just do the step 5 above to solve this problem.
Or add the following lines to the .bashrc or .zshrc
``` export TCL_LIBRARY="/home/zijun/anaconda2/lib/tcl8.5"Note1: tck is a package which supports install.packages() function and it is installed in the global environment if you use sudo apt-get install tcl8.5-dev tk8.5-dev and conda has no access to it.
Note2: packages will be installed in /home/zijun/anaconda/envs/r/lib/R/library using install.packages()
Q: How to install packages in R
A: Since we set up the tcl, we can easily use install.packages() or remove.packages() to manage the R packages. However in this way, conda will lose control over r packages. Also you may find some suggestions using conda-build like this:
switch back to the root environment
type conda install conda-build in the terminal
Use conda skeleton cran and conda build to install packages (you may mind the dependency issue)
However this will not give you the control either. Moreover, there might be more issues about shitty sytax in R. So my suggestion is simply using install.packages() in R to install your packages.
热心网友
建议安装anaconda管理python,这个比较稳定,用pip总会出现一些奇奇怪怪的错误,科学计算用anaconda最好了