jingweimo的个人博客分享 http://blog.sciencenet.cn/u/jingweimo

博文

Python: Basic Image Processing

已有 3538 次阅读 2016-9-9 10:03 |系统分类:科研笔记

# Path Setup

import os

os.system('cls') # for windows or Ctrl+L

os.chdir('path') # path setup


# Image loading

img = Image.open('Lenna.png')
img.show(img) #RGB

#img = Image.open('lenna.png').convert('L') #Gray-scale

img.save(os.path.join(os.getcwd(),'imgNew.tiff'),'tiff') # getcwd gets the current path


# Convolution filtering

import numpy as np

import scipy.ndimage

from scipy.misc.pilutil import Image

b = scipy.ndimage.filters.convolve(img,k)

k = np.ones((5,5))/25

b = scipy.misc.toimage(b)

b.show()


# Contrast stretching

import math, numpy

#import scipy.misc

#from scipy.misc.pilutil import Image

img1=scipy.misc.fromimage(img) # convert img (image class) to an ndarrary

# img1 = numpy.asarray(img)

b = img1.min()

a = img1.max()

# print a,b

# converting img1 to float

c = img1.astype(float) # uint8 to floating precision

# contrast stretching

img2 = 255*(c - a)/(b - a)

img3 = scipy.misc.toimage(img2) # converted back to image class

img3.show()


# Fourier transform

# import math, numpy

import scipy.fftpack as fftim

# from scipy.misc.pilutil import Image

img1 = numpy.asarray(a)

fft1 = abs(fftim.fft2(img1))

fft2 = fftim.fftshift(fft1)

import pylab as py

py.imshow(fft2)





https://blog.sciencenet.cn/blog-578676-1001802.html

上一篇:Programming in C++ with Visual Studio 2015
下一篇:Phython: shorthand notations
收藏 IP: 68.48.108.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2025-1-17 02:32

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部