当前位置:网站首页>Scientific computing toolkit SciPy image processing
Scientific computing toolkit SciPy image processing
2022-07-24 21:06:00 【Hua Weiyun】
Reading guide
scipy It also provides many methods about image processing , Mainly packaged in ndimage In bag , This article mainly introduces the use of some image processing methods
Image filtering
- Get photo
from scipy import misc,ndimagefrom matplotlib import pyplot as plt# Get a picture from the website img = misc.ascent()# Displays a grayscale image plt.gray()# display picture plt.imshow(f)plt.show()
- wave filtering
wave filteringIt is usually used for image denoising ,scipy Many filtering algorithms are also provided in
# Gauss filtering ,sigma Set the standard deviation of Gaussian kernel gauss_f_img = ndimage.gaussian_filter(img,sigma=3)# Maximum filtering max_f_img = ndimage.maximum_filter(img,size=20)# median filtering median_f_img = ndimage.median_filter(img,size=20)# Minimum filtering min_f_img = ndimage.minimum_filter(img,size=20)# Percentile filtering percentile_f_img = ndimage.percentile_filter(img,percentile=20,size=20)# Set the display of the picture listimg_list = [img,gauss_f_img,max_f_img,median_f_img,min_f_img,percentile_f_img]title_list = ["origin","guassian filter","maximum filter","median filter","minimum filter","percentile filter"]for i in range(len(img_list)): plt.subplot(2,3,i+1) # Set the title of the display picture plt.title(title_list[i]) # display picture plt.imshow(img_list[i]) # Turn off the display of the coordinate axis plt.axis("off")plt.show()
Image interpolation
Image interpolation is also widely used in image processing , for example : Perspective transformation 、 Affine transformation 、 translation 、 The zoom 、 rotate You can see it when you wait ,scipy Several functions are also provided for image interpolation , Let's take a look at
On the principle of image affine transformation , You can refer to my article Understand affine transformation
- Affine transformation
# Define the translation matrix of an image M = np.array([[1,0,10],[0,1,30]])# Affine transformation affine_img = ndimage.affine_transform(img,M)plt.imshow(affine_img)plt.show()
- Image rotation
# Rotated image #reshape Set whether to display all images ,True Show all ,False The image will be cropped rotate_img = ndimage.rotate(img,45,reshape=False)plt.imshow(rotate_img)plt.show()
- Image zooming
# Reduce the image to the original 1/2zoom_img = ndimage.zoom(img,0.5)plt.imshow(zoom_img)plt.show()
- Geometric interpolation
adoptgeometric_transformWe can realize geometric interpolation , You only need to define a function of image position transformation , As defined belowshift_funcFunction to move the image to the lower left corner 1 Pixel , The cross-border position uses... By default 0 Fill in
a = np.arange(0,12).reshape((4,3))def shift_func(output_coords): # Define the interpolation function return (output_coords[0] - 1,output_coords[1] - 1)# The pixel values of the coordinates are transformed according to the coordinates of the data t_a = ndimage.geometric_transform(a,shift_func)"""[[ 0 1 2] [ 3 4 5] [ 6 7 8] [ 9 10 11]][[0 0 0] [0 0 1] [0 3 4] [0 6 7]]"""边栏推荐
- How to apply Po mode in selenium automated testing
- [feature construction] construction method of features
- API data interface for historical data of A-share index
- Docker builds redis and clusters
- Can century model simulate soil respiration? Practice technology application and case analysis of century model
- Problems with SQLite compare comparison tables
- ma.glasnost.orika. MappingException:No converter registered for conversion from Date to LocalDateTime
- One bite of Stream(7)
- Processing of null value of Oracle notes
- MySQL docker installation master-slave deployment
猜你喜欢

One bite of Stream(7)

Drive subsystem development

How to apply Po mode in selenium automated testing

Selenium is detected as a crawler. How to shield and bypass it

A simple method of converting SVG to PDF

How to test WebService interface

Lua environment configuration

C # image template matching and marking

Node installation using NVM succeeded, but NPM installation failed (error while downloading, TLS handshake timeout)

How to set appium script startup parameters
随机推荐
How does starknet change the L2 landscape?
Overloaded & lt; for cv:: point;, But VS2010 cannot find it
Flink window & time principle
Modulenotfounderror: no module named 'pysat.solvers' (resolved)
Alibaba sentinel basic operation
One bite of Stream(6)
Baidu classic interview question - determine prime (how to optimize?)
96. Strange tower of Hanoi
Do you want to enroll in a training class or study by yourself?
Vscode connected to the remote server cannot format the code / document (resolved)
Node installation using NVM succeeded, but NPM installation failed (error while downloading, TLS handshake timeout)
Static & dynamic & file address book
MySQL data recovery
Spark related FAQ summary
Lua environment configuration
C synchronous asynchronous callback state machine async await demo
[learning notes] agc008
How to learn automated testing
How to apply Po mode in selenium automated testing
C WinForm actual operation XML code, including the demonstration of creating, saving, querying and deleting forms