当前位置:网站首页>MATLAB basic operation command
MATLAB basic operation command
2022-06-26 09:14:00 【G fruit】
Learning materials
MATLAB file :https://ww2.mathworks.cn/help/matlab/ref/imwrite.html
% Command line semicolon : Cancel output
% Command line comma : The separation command
Image operation
Read images
f=imread('filename.jpg')% Read the current directory image , Save as f Array
f=imread('D:\pictures\filename.jpg')% Absolute address
f=imread('.\pictures\filename.jpg')% Relative address
Display images
imshow(f,G)%G Is the grayscale series , If you omit G, The default grayscale level is 256
imshow(f,[low high])% Will be less than or equal to low The value of is displayed in black , All greater than or equal to high The values of are displayed in white
imshow(f,[ ])% take low Set to array minimum , Variable high Set to numerical maximum
Interactively display the brightness value of a single pixel
pixval% Display the cursor over the image
Show multiple pictures
imshow(f), figure, imshow(g)% No addition figure,imshow The new image overwrites the old one
Save image
imwrite(f,'filename.jpg') perhaps imwrite(f,'filename','jpg')
Only applicable to JPEG Compression and storage of images
imwrite(f,'filename.jpg','quality',q)%q yes 0 To 100 Integer between ,q The smaller it is , The more serious the image degradation
View the details of the image file
imfinfo filename.jpg%width multiply height multiply BitDepth Divide Filesize The ratio of image compression can be obtained
Get the information of the image file
k=imfinfo('filename.jpg')
k.Width, k.Height
Only applicable to tif How to save images
imwrite(g,'filename.tif','compression','paramater'...'resolution',[colres rowres])
'paramater’ The value is 3 individual :'none’ Represents no compression ,‘packbits’ Indicates bit packet compression ’( Default parameters for non binary images ),‘ccitt’ Express ccitt Compress ( Default parameters for binary images )
[colres rowres] The column resolution and row resolution of the image are given by the number of points in each unit
The luminance image is a numerical matrix , The normalized value represents the brightness
One uint8 Class , Its pixels are uint8, The brightness range of the image is [0,255]
One uint16 Class , Its pixels are uint16, The brightness range of the image is [0,65535]
One double Class , Its pixels are all floating point numbers , The brightness range of the image is [0,1]
A binary image is a value with only 0 and 1 Logical array of , A value contains only 0 and 1 Of uint8 An array of class , stay MATLAB Is not considered a binary image
logical Function can convert a numeric matrix into a binary matrix
B=logical(A)% if A In addition to 0,1 Values outside , These values are transformed into logic 1
Test whether a value is a logical array
islogical(C)% If it is a logical array, return 1, Otherwise return to 0
Conversion between data classes
B=data_class_name(A)% such as B=uint8(A) and B=double(A)
Conversion between image class and data class
im2uint8(f)% Less than... In input 0 The Settings for 0, Greater than 1 The Settings for 255 stay , Multiply other values by 255( rounding )
im2uint16(f)
im2double(f)% When the input is uint8, Divide by 255; When the input is uint16, Divide by 65535
im2bw(f,T)% Two valued ,T It's the threshold , The default is 0.5, Output is logical class ( Normalization is included in the middle )
Only applicable to double Class normalization
mat2gray(A,[Amin,Amax])% normalization [0,1], Less than the specified parameter Amin The value of is converted to 0,, Greater than Amax The value of is converted to 1
Support nested
g=im2double(im2bw(mat2gray(f),0.6))
Support function combination
g=double(f>2)
View the number of image rows and columns
size(f,dim)%dim=1 Press the first dimension ( Row number ),dim=2 Press the second dimension ( Number of columns )
View additional information about the image array , such as Bytes
whos f
Vector operations
v=[1 3 5 7 9]
Vector index
v(2)% Vector number 2 Number =3
v.'% Vector transpose
v(:)% Generate a column vector
v(1:end)% Generate a row vector
v(1:3)% Take out the vector number 1 To the first 3 Number of numbers =1 3 5
v(3:end)% Take out No 3 To the last number =5 7 9
v(1:2:end)% Start with the first number , In steps of 2, Take the last number =1 5 9
v(end:-2:1)% Start with the last number , step -2, Take the first number =9 5 1
v([1 4 5])% Pick out the second 1 individual 、 The first 4 individual 、 The first 5 Elements
Vector generating function
x=linspace(a,b,n)% Produce a product containing n A row vector of elements , this n The elements are linearly separated and contain a And b
Matrix operation
A=[1 2 3;4 5 6;7 8 9]
A=1 2 3
4 5 6
7 8 9
Matrix index
A(8)% The matrix is in MATLAB The save of is sorted by column , By column 8 Number =6
A(2,3)% The first 2 Xing di 3 Column =6
A(:,3)% The first 3 Column
A(2,:)% The first 2 That's ok
A(1:2,1:3)% The first 1-2 Xing di 1-3 Column
A(:,3)=0% The first 3 Column full deployment 0
A(end,end)% Last row last column
A(end,end-2)% The last line is the derivative 2 Column
A(2:end,end:-2:1)% The first 2 Line to last line , The last column , In steps of -2, Until the first column
Use a vector as the index of a matrix
A([1 3],[2 3])% The first 1 Xing He 3 That's ok , The first 2 Column and column 3 Column
Logical array as the index of matrix
D=logical([1 0 0;0 0 1;0 0 0])
A(D)% The first 1 Xing di 1 individual , The first 2 Xing di 3 individual
Find the sum of all the elements of a matrix
sum(A(:))% A single colon turns a matrix into a vector
f It's a 1024X1024 Image
f(end:-1:1,:)% Flip vertically
f(257:768,257:768)% Image cropping
f(1:2:end,1:2:end)% Secondary sampling
ndims(A)% Array A Dimension of (>2)
zeros(m,n)% The generation size is m X n whole 0 Elemental double Class matrix
ons(m,n)% The generation size is m X n whole 1 Elemental double Class matrix
ture(m,n)% Generate all 1 Elemental logical Class matrix
false(m,n)% Generate all 0 Elemental logical Class matrix
magic(m,n)% Generate magic matrix ( The ranks of 、 The sum of the main diagonal elements is relative , Elements are integers )
rand(m,n)% The generated elements are all in [0,1] Interval uniformly distributed random number
randn(m,n)% The generating elements conform to the normal distribution ( The mean for 0, The variance of 1) The random number
MATLAB Function definition
%function notes
function [outputs]=function_name(inputs)
function [s,p]=sumprod(f,g)
help function_name% View function comments
edit sumprod% Edit the file
Period character (.) Distinguish between array operations and matrix operators
A*B Matrix multiplication
A.*B Array multiplication ( Elements multiply )
IPT Supported image arithmetic functions
imadd% Add two images , Or add constants to the image
imsubtract% Subtract two figures or subtract constants from an image
immultiply% Multiply two graphs , Or multiply the image by a constant
imdivide% Divide two graphs , Or the image divided by a constant
imabsdiff% The absolute difference between two graphs
imcomplement% Images complement each other
imlincomb% Calculate the linear combination of multiple graphs
max(A)
max(A,B)
max(A,[ ],dim)
Relational operator (A、B Same dimension )
A==B% The corresponding position elements are equal to 1, The rest are 0
A>=B% The corresponding position element is greater than or equal to 1, The rest are 0
>% Greater than
<% Less than
~>% It's not equal to
Logical operators
&% And operation , whole 0 For or not at all 0 by 1, For the other 0
|% Or operations , There are not 0 by 1, For the other 0
~% Non operation , Not 0 by 0,0 by 1
xor% The logical difference between the two numbers is 1
all% If all elements in a vector are not 0 by 1, For the other 0, Operate by column
any% If there are elements in a vector that are not 0 by 1, For the other 0, Operate by column
nemwl(A)% Get the number of pixels of the image
边栏推荐
- Fix the problem that the rich text component of the applet does not support the properties of video cover, autoplay, controls, etc
- Data warehouse (1) what is data warehouse and what are the characteristics of data warehouse
- 51 single chip microcomputer ROM and ram
- ImportError: ERROR: recursion is detected during loading of “cv2“ binary extensions. Check OpenCV in
- 2021 software university ranking crawler program
- Pytorch neural network
- [300+ continuous sharing of selected interview questions from large manufacturers] column on interview questions of big data operation and maintenance (I)
- phpcms v9去掉phpsso模块
- MySQL在服务里找不到(未卸载)
- Implementation code of interceptor and filter
猜你喜欢

51 single chip microcomputer ROM and ram

【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(一)

《单片机原理及应用》——概述

Yolov5 advanced level 2 installation of labelimg

Behavior tree file description

Yolov5 advanced zero environment rapid creation and testing

Phpcms V9 mall module (fix the Alipay interface Bug)
![[program compilation and pretreatment]](/img/c9/45353cf6578628ad44f149350873f5.png)
[program compilation and pretreatment]

Phpcms applet plug-in version 4.0 was officially launched

Practice is the fastest way to become a network engineer
随机推荐
运行时端常用类的介绍
【开源】使用PhenoCV-WeedCam进行更智能、更精确的杂草管理
Adding confidence threshold for demo visualization in detectron2
Vipshop work practice: Jason's deserialization application
Baidu applet rich text parsing tool bdparse
[qnx hypervisor 2.2 user manual]12.2 terminology (II)
基于SSM的毕业论文管理系统
How to convert wechat applet into Baidu applet
ImportError: ERROR: recursion is detected during loading of “cv2“ binary extensions. Check OpenCV in
Sqoop merge usage
phpcms小程序插件教程网站正式上线
Efficiency thesis Reading 1
Yolov5 advanced camera real-time acquisition and recognition
Phpcms V9 mobile phone access computer station one-to-one jump to the corresponding mobile phone station page plug-in
外部排序和大小堆相关知识
Lagrange multiplier method
Cookie session and token
Execution process at runtime
Applet realizes picture preloading (picture delayed loading)
Tensor