lecture 20 regular expressions and more image...
TRANSCRIPT
![Page 1: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/1.jpg)
Lecture 20Regular Expressions and More Image Processing
1
![Page 2: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/2.jpg)
Lecture 20 Goals
•••••
•••
2
![Page 3: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/3.jpg)
String Searching
contains().
>> s1 = "Puppies vs. Babies";>> contains(s1,'Babies')ans = logical 1>> contains(s2,'Kitties')ans = logical 0
3
![Page 4: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/4.jpg)
String Searching
contains()
>> s1 = "Puppies vs. Babies";>> contains(s1,'puppies')ans = logical 0>> contains(lower(s1),'puppies')ans = logical 1>> contains(s1,'puppies','IgnoreCase',true)ans = logical 1
4
![Page 5: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/5.jpg)
String Searching
strfind()
>> s1 = "Puppies vs. Babies";>> strfind(s1,'puppies')ans = 13>> strfind(s1,'ies')ans = 5 16>> strfind(s1,'dogs')ans = []
findstr5
![Page 6: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/6.jpg)
Directories and Filenames
dir dir
>> f = dirf = 10×1 struct array with fields: name folder date bytes isdir datenum>> f = dir('data'); % specify a relative path>> f = dir('/home/cs4user/'); % specify an absolute path
6
![Page 7: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/7.jpg)
MATLAB Structs
7
>> a = struct('a',1,'b',2,'c',3)a = struct with fields:
a: 1 b: 2 c: 3>> b = struct('type',true,'color','red','data',[4 5 6])b = struct with fields:
type: 1 color: 'red' data: [4 5 6]>> c.first = 1;>> c.second = 2;
![Page 8: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/8.jpg)
MATLAB Structs
8
>> b = struct('type',true,'color','red','data',[4 5 6]);>> fieldnames(b)ans = 3×1 cell array {'type' } {'color'} {'data' }>> isfield(b,'data')ans = logical 1>> isfield(b,'date')ans = logical 0
![Page 9: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/9.jpg)
MATLAB Structs
>> b = struct('type',true,'color','red','data',[4 5 6]);>> b.typeans = logical 1>> b.colorans = 'red'>> c.dataans = 4 5 6
9
![Page 10: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/10.jpg)
MATLAB Structs
10
>> f = dir('*.m');>> for fnum = 1:numel(f)
f(fnum).bytes endans = 278ans = 44ans = 54
![Page 11: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/11.jpg)
>> f(1).myVariable = true>> f(2).myVariable = 5>> f.myVariableans = logical 1ans = 5ans = []
MATLAB Structs
11
![Page 12: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/12.jpg)
Searching Directories
dir
>> file = dir('data_20190415.mat');>> file = dir('data/data_20190415.mat');>> file = dir(['data',filesep,'data_20190415.mat']);>> file struct with fields:
name: data_20190415.mat' folder: '/MATLAB Drive/data' date: '15-Apr-2019 21:50:21' bytes: 240 isdir: 0 datenum: 7.3753e+05
12
![Page 13: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/13.jpg)
Searching Directories
>> files = dir('*.m');f = 3×1 struct array with fields: name folder date bytes isdir datenum>> f.nameans = 'genData.m'ans = 'myFunc.m'ans = 'test_myFunc.m'
13
![Page 14: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/14.jpg)
Searching Directories
>> files = dir('data_2019*.mat');>> files = dir('*.m*');
'data_20190415.mat' 'data_20190521.mat' 'data_2019_aux.mat'?
14
![Page 16: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/16.jpg)
Regular Expressions
>> help regexpregexp Match regular expression
S = regexp(STR,EXPRESSION) matches the regular expression, EXPRESSION, in the input argument, STR. The indices of the beginning of the matches are returned....
>> help regexpiregexpi Match regular expression, ignoring case
START = regexpi(STR,EXPRESSION) matches the regular expression, EXPRESSION, in the input argument, STR, regardless of case. The indices of the beginning of the matches are returned.
See also:16
![Page 17: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/17.jpg)
Regular Expressions
>> str = 'bat cat can car coat court cut ct caoueouat';>> regexp(str, 'can')ans = 9>> regexp(str, 'c[aeiou]+t')ans = 5 17 28 35
>> regexp(str, 'Co[\w].')ans = []>> regexpi(str, 'Co[\w].')ans = 17 22
17
![Page 18: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/18.jpg)
Regular Expressions: Metacharacters
18
![Page 19: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/19.jpg)
Regular Expressions: Logical Operators
19
![Page 20: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/20.jpg)
Regular Expressions: Quantifiers
20
![Page 21: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/21.jpg)
What is the output of the following code?
>> regexp('acoueouat', 'c[aeiou]+t')
A)B)C)D)
21
![Page 22: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/22.jpg)
What is the output of the following code?
>> regexp('acoueouat', 'c[aeiou]+t')
A)B)C)D)
22
![Page 23: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/23.jpg)
What is the output of the following code?
>> regexp('aoueouat', 'c[aeiou]+t')
A)B)C)D)
23
![Page 24: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/24.jpg)
What is the output of the following code?
>> regexp('aoueouat', 'c[aeiou]+t')
A)B)C)D)
24
![Page 25: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/25.jpg)
What is the output of the following code?
>> regexp('aoueouat', 'c|[aeiou]+t')
A)B)C)D)
25
![Page 26: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/26.jpg)
What is the output of the following code?
>> regexp('aoueouat', 'c|[aeiou]+t')
A)B)C)D)
26
![Page 27: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/27.jpg)
What is the output of the following code?
>> regexp('puppy54.mat', '[\d]+')
A)B)C)D)
27
![Page 28: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/28.jpg)
What is the output of the following code?
>> regexp('puppy54.mat', '[\d]+')
A)B)C)D)
28
![Page 29: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/29.jpg)
Saving Variables Using Regular Expressions
>> save myfile.mat -regexp \d>> save myfile.mat -regexp ^data\_2019(04|05)
29
![Page 30: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/30.jpg)
2D Data Visualization
30
[X,Y] = meshgrid(-8:.5:8);R = sqrt(X.^2 + Y.^2) + eps;
Z = sin(R)./R;figuremesh(X,Y,Z)
![Page 31: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/31.jpg)
2D Data Visualization
31
![Page 32: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/32.jpg)
Mesh vs. Surf
32
>> mesh(membrane)>> surf(membrane)
![Page 33: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/33.jpg)
Meshc vs. Surfc
33
>> meshc(membrane)>> surfc(membrane)
![Page 34: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/34.jpg)
Surf vs. Pcolor
34
![Page 35: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/35.jpg)
Image vs. Imagesc
35
>> image(membrane)>> image(membrane*60)>> imagesc(membrane)
![Page 36: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/36.jpg)
Contour vs. Contourf
36
>> contour(membrane)>> contourf(membrane)
![Page 37: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/37.jpg)
Lighting and Shading
37
![Page 38: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/38.jpg)
Lighting and Shading
38
[X,Y] = meshgrid(-8:.5:8);R = sqrt(X.^2 + Y.^2) + eps;Z = sin(R)./R;surf(X,Y,Z)
![Page 39: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/39.jpg)
Lighting and Shading
39
surf(X,Y,Z,'LineStyle','none')
![Page 40: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/40.jpg)
Lighting and Shading
40
lh = light
![Page 41: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/41.jpg)
Lighting and Shading
41
lightangle(lh,-90,25)
![Page 42: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/42.jpg)
Lighting and Shading
42
lighting phong
![Page 43: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/43.jpg)
Lighting and Shading
43
[X,Y] = meshgrid(-8:.1:8);...
![Page 44: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/44.jpg)
Colorbar and ‘colormap’
44
>> pcolor(membrane)>> colorbar
colormap(jet)colormap(parula)
![Page 45: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/45.jpg)
Colorbar and ‘colormap’
45
>> pcolor(membrane)>> colorbar
colormap(gray)colormap(hot)
![Page 46: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/46.jpg)
Colorbar and ‘colormap’
46
>> pcolor(membrane)>> colorbar
colormap(white)colormap(colorcube)
![Page 47: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/47.jpg)
Color Scale and ‘colormap’
47
>> c = hot(255); % use 255 levels in colormap>> c = flipud(c); % invert colormap>> colormap(c); % set colormap to inverted hot
![Page 48: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/48.jpg)
Color Scale and Dynamic Range
48
cLim = [-0.3338, 1.0000]
![Page 49: Lecture 20 Regular Expressions and More Image Processingcs.brown.edu/courses/cs004/lectures/lec20.pdf · Regular Expressions and More Image Processing 1. ... Regular Expressions >>](https://reader036.vdocument.in/reader036/viewer/2022071019/5fd332d13d3aa10d493a56cf/html5/thumbnails/49.jpg)
Color Scale and Dynamic Range
49
colorbar % turn colorbar oncLim = get(gca,'cLim'); % get current scaleset(gca,'cLim',[cLim(2)-1.0 cLim(2)]) % colormap limits [min max]
cLim = [0, 1]