Skip to content

Commit 7fd65e2

Browse files
committed
demos: add demo for crop operations
1 parent e616094 commit 7fd65e2

File tree

7 files changed

+227
-0
lines changed

7 files changed

+227
-0
lines changed

demos/shape/demoCrop.m

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
% Demonstration of image crop functions
2+
%
3+
% output = demoCrop(input)
4+
%
5+
% Example
6+
% demoCrop
7+
%
8+
% See also
9+
%
10+
11+
% ------
12+
% Author: David Legland
13+
14+
% INRAE - BIA Research Unit - BIBS Platform (Nantes)
15+
% Created: 2022-06-24, using Matlab 9.12.0.1884302 (R2022a)
16+
% Copyright 2022 INRAE.
17+
18+
%% Input data
19+
20+
% read sample image
21+
% (provided within the @image/sampleFiles directory)
22+
img = Image.read('wheatGrainSlice.tif');
23+
24+
figure; show(img);
25+
26+
27+
%% Boxes
28+
29+
% need to segment image to obtain the region of the grain
30+
seg = img > 160;
31+
seg2 = areaOpening(killBorders(seg), 10);
32+
33+
% compute boxes
34+
box = regionBoundingBox(seg2);
35+
obox = regionOrientedBox(seg2);
36+
37+
% display boxes over image
38+
% (requires MatGeom toolbox)
39+
hold on;
40+
drawBox(box, 'color', 'g', 'linewidth', 2);
41+
drawOrientedBox(obox, 'color', 'm', 'linewidth', 2);
42+
43+
44+
%% Crop
45+
46+
resCrop = crop(img, box);
47+
figure; show(resCrop)
48+
title('Crop Box');
49+
write(resCrop, 'wheatGrainCrop.tif');
50+
51+
resCrop2 = cropOrientedBox(img, obox);
52+
figure; show(resCrop2)
53+
title('Crop Oriented Box');
54+
write(resCrop, 'wheatGrainCropOriented.tif');
55+

demos/shape/html/demoCrop.html

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
2+
<!DOCTYPE html
3+
PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4+
<html><head>
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6+
<!--
7+
This HTML was auto-generated from MATLAB code.
8+
To make changes, update the MATLAB code and republish this document.
9+
--><title>demoCrop</title><meta name="generator" content="MATLAB 9.12"><link rel="schema.DC" href="http://purl.org/dc/elements/1.1/"><meta name="DC.date" content="2022-06-24"><meta name="DC.source" content="demoCrop.m"><style type="text/css">
10+
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,font,img,ins,kbd,q,s,samp,small,strike,strong,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td{margin:0;padding:0;border:0;outline:0;font-size:100%;vertical-align:baseline;background:transparent}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:before,blockquote:after,q:before,q:after{content:'';content:none}:focus{outine:0}ins{text-decoration:none}del{text-decoration:line-through}table{border-collapse:collapse;border-spacing:0}
11+
12+
html { min-height:100%; margin-bottom:1px; }
13+
html body { height:100%; margin:0px; font-family:Arial, Helvetica, sans-serif; font-size:10px; color:#000; line-height:140%; background:#fff none; overflow-y:scroll; }
14+
html body td { vertical-align:top; text-align:left; }
15+
16+
h1 { padding:0px; margin:0px 0px 25px; font-family:Arial, Helvetica, sans-serif; font-size:1.5em; color:#d55000; line-height:100%; font-weight:normal; }
17+
h2 { padding:0px; margin:0px 0px 8px; font-family:Arial, Helvetica, sans-serif; font-size:1.2em; color:#000; font-weight:bold; line-height:140%; border-bottom:1px solid #d6d4d4; display:block; }
18+
h3 { padding:0px; margin:0px 0px 5px; font-family:Arial, Helvetica, sans-serif; font-size:1.1em; color:#000; font-weight:bold; line-height:140%; }
19+
20+
a { color:#005fce; text-decoration:none; }
21+
a:hover { color:#005fce; text-decoration:underline; }
22+
a:visited { color:#004aa0; text-decoration:none; }
23+
24+
p { padding:0px; margin:0px 0px 20px; }
25+
img { padding:0px; margin:0px 0px 20px; border:none; }
26+
p img, pre img, tt img, li img, h1 img, h2 img { margin-bottom:0px; }
27+
28+
ul { padding:0px; margin:0px 0px 20px 23px; list-style:square; }
29+
ul li { padding:0px; margin:0px 0px 7px 0px; }
30+
ul li ul { padding:5px 0px 0px; margin:0px 0px 7px 23px; }
31+
ul li ol li { list-style:decimal; }
32+
ol { padding:0px; margin:0px 0px 20px 0px; list-style:decimal; }
33+
ol li { padding:0px; margin:0px 0px 7px 23px; list-style-type:decimal; }
34+
ol li ol { padding:5px 0px 0px; margin:0px 0px 7px 0px; }
35+
ol li ol li { list-style-type:lower-alpha; }
36+
ol li ul { padding-top:7px; }
37+
ol li ul li { list-style:square; }
38+
39+
.content { font-size:1.2em; line-height:140%; padding: 20px; }
40+
41+
pre, code { font-size:12px; }
42+
tt { font-size: 1.2em; }
43+
pre { margin:0px 0px 20px; }
44+
pre.codeinput { padding:10px; border:1px solid #d3d3d3; background:#f7f7f7; }
45+
pre.codeoutput { padding:10px 11px; margin:0px 0px 20px; color:#4c4c4c; }
46+
pre.error { color:red; }
47+
48+
@media print { pre.codeinput, pre.codeoutput { word-wrap:break-word; width:100%; } }
49+
50+
span.keyword { color:#0000FF }
51+
span.comment { color:#228B22 }
52+
span.string { color:#A020F0 }
53+
span.untermstring { color:#B20000 }
54+
span.syscmd { color:#B28C00 }
55+
span.typesection { color:#A0522D }
56+
57+
.footer { width:auto; padding:10px 0px; margin:25px 0px 0px; border-top:1px dotted #878787; font-size:0.8em; line-height:140%; font-style:italic; color:#878787; text-align:left; float:none; }
58+
.footer p { margin:0px; }
59+
.footer a { color:#878787; }
60+
.footer a:hover { color:#878787; text-decoration:underline; }
61+
.footer a:visited { color:#878787; }
62+
63+
table th { padding:7px 5px; text-align:left; vertical-align:middle; border: 1px solid #d6d4d4; font-weight:bold; }
64+
table td { padding:7px 5px; text-align:left; vertical-align:top; border:1px solid #d6d4d4; }
65+
66+
67+
68+
69+
70+
</style></head><body><div class="content"><h2>Contents</h2><div><ul><li><a href="#2">Input data</a></li><li><a href="#3">Boxes</a></li><li><a href="#4">Crop</a></li></ul></div><pre class="codeinput"><span class="comment">% Demonstration of image crop functions</span>
71+
<span class="comment">%</span>
72+
<span class="comment">% output = demoCrop(input)</span>
73+
<span class="comment">%</span>
74+
<span class="comment">% Example</span>
75+
<span class="comment">% demoCrop</span>
76+
<span class="comment">%</span>
77+
<span class="comment">% See also</span>
78+
<span class="comment">%</span>
79+
80+
<span class="comment">% ------</span>
81+
<span class="comment">% Author: David Legland</span>
82+
<span class="comment">% e-mail: [email protected]</span>
83+
<span class="comment">% INRAE - BIA Research Unit - BIBS Platform (Nantes)</span>
84+
<span class="comment">% Created: 2022-06-24, using Matlab 9.12.0.1884302 (R2022a)</span>
85+
<span class="comment">% Copyright 2022 INRAE.</span>
86+
</pre><h2 id="2">Input data</h2><pre class="codeinput"><span class="comment">% read sample image</span>
87+
<span class="comment">% (provided within the @image/sampleFiles directory)</span>
88+
img = Image.read(<span class="string">'wheatGrainSlice.tif'</span>);
89+
90+
figure; show(img);
91+
</pre><img vspace="5" hspace="5" src="demoCrop_01.png" alt=""> <h2 id="3">Boxes</h2><pre class="codeinput"><span class="comment">% need to segment image to obtain the region of the grain</span>
92+
seg = img &gt; 160;
93+
seg2 = areaOpening(killBorders(seg), 10);
94+
95+
<span class="comment">% compute boxes</span>
96+
box = regionBoundingBox(seg2);
97+
obox = regionOrientedBox(seg2);
98+
99+
<span class="comment">% display boxes over image</span>
100+
<span class="comment">% (requires MatGeom toolbox)</span>
101+
hold <span class="string">on</span>;
102+
drawBox(box, <span class="string">'color'</span>, <span class="string">'g'</span>, <span class="string">'linewidth'</span>, 2);
103+
drawOrientedBox(obox, <span class="string">'color'</span>, <span class="string">'m'</span>, <span class="string">'linewidth'</span>, 2);
104+
</pre><img vspace="5" hspace="5" src="demoCrop_02.png" alt=""> <h2 id="4">Crop</h2><pre class="codeinput">resCrop = crop(img, box);
105+
figure; show(resCrop)
106+
title(<span class="string">'Crop Box'</span>);
107+
write(resCrop, <span class="string">'wheatGrainCrop.tif'</span>);
108+
109+
resCrop2 = cropOrientedBox(img, obox);
110+
figure; show(resCrop2)
111+
title(<span class="string">'Crop Oriented Box'</span>);
112+
write(resCrop, <span class="string">'wheatGrainCropOriented.tif'</span>);
113+
</pre><img vspace="5" hspace="5" src="demoCrop_03.png" alt=""> <img vspace="5" hspace="5" src="demoCrop_04.png" alt=""> <p class="footer"><br><a href="https://www.mathworks.com/products/matlab/">Published with MATLAB&reg; R2022a</a><br></p></div><!--
114+
##### SOURCE BEGIN #####
115+
% Demonstration of image crop functions
116+
%
117+
% output = demoCrop(input)
118+
%
119+
% Example
120+
% demoCrop
121+
%
122+
% See also
123+
%
124+
125+
% REPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASHREPLACE_WITH_DASH_DASH
126+
% Author: David Legland
127+
128+
% INRAE - BIA Research Unit - BIBS Platform (Nantes)
129+
% Created: 2022-06-24, using Matlab 9.12.0.1884302 (R2022a)
130+
% Copyright 2022 INRAE.
131+
132+
%% Input data
133+
134+
% read sample image
135+
% (provided within the @image/sampleFiles directory)
136+
img = Image.read('wheatGrainSlice.tif');
137+
138+
figure; show(img);
139+
140+
141+
%% Boxes
142+
143+
% need to segment image to obtain the region of the grain
144+
seg = img > 160;
145+
seg2 = areaOpening(killBorders(seg), 10);
146+
147+
% compute boxes
148+
box = regionBoundingBox(seg2);
149+
obox = regionOrientedBox(seg2);
150+
151+
% display boxes over image
152+
% (requires MatGeom toolbox)
153+
hold on;
154+
drawBox(box, 'color', 'g', 'linewidth', 2);
155+
drawOrientedBox(obox, 'color', 'm', 'linewidth', 2);
156+
157+
158+
%% Crop
159+
160+
resCrop = crop(img, box);
161+
figure; show(resCrop)
162+
title('Crop Box');
163+
write(resCrop, 'wheatGrainCrop.tif');
164+
165+
resCrop2 = cropOrientedBox(img, obox);
166+
figure; show(resCrop2)
167+
title('Crop Oriented Box');
168+
write(resCrop, 'wheatGrainCropOriented.tif');
169+
170+
171+
##### SOURCE END #####
172+
--></body></html>

demos/shape/html/demoCrop.png

4.65 KB
Loading

demos/shape/html/demoCrop_01.png

163 KB
Loading

demos/shape/html/demoCrop_02.png

171 KB
Loading

demos/shape/html/demoCrop_03.png

105 KB
Loading

demos/shape/html/demoCrop_04.png

99.3 KB
Loading

0 commit comments

Comments
 (0)