DUE IN 8 HOURS!!!!!!! MATLAB REQUIRED!!!!!! Evaluation and Presentation of Experimental Data
1 of 19
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2a: Basic Mechanical Measurements
This lab consists of 3 parts to help you understand performing basic mechanical
measurements and presenting the data in a usable form: (1) Excel proficiency, (2) creating an
overlay of the Gaussian PDF and a histogram of measured data, and (3) performing mechanical
measurements using calipers and micrometers. The focus of the formal lab report will be to use
the knowledge gained in (1) and (2) to describe the results of your team’s measurements (3).
Sections I, II, and III are supplementary background materials for your benefit.
They are not required to be submitted as part of the lab report, nor evaluated.
I. EXCEL PROFICIENCY - BACKGROUND [1]
A. OVERVIEW
Engineers are required to do a variety of computations during the analysis and design
phases of a system. In ENGR-202 we will be using Excel to analyze data. While almost any
language could be used the instructor has chosen Excel since it is present on most companies’
computers. While many students may have some background using Excel, the objective of
this document is to ensure that students increase their skill level beyond the
minimum/common skill set to successfully implement the design tools required in the
laboratory assignments in a more efficient way.
In this first module we will NOT worry about significant figures, the objective is to
become familiar with Excel. Subsequently in further modules we will introduce functions that
allow us to specify the number of significant digits.
B. FUNDAMENTAL SKILL SET
You should already know …
Entering data and performing computations using standard operators (+, -, *, /) and built in functions such as average(), etc.
Creation of graphs with proper scaling, annotations, curve fitting (linear regression) and getting coefficients of best fit curve
Formatting cells, e.g. – highlighting and number formatting
Data analysis, e.g. – descriptive statistics and histograms
Each student should perform Exercises 1, 2, and 3 to verify their competency of the
Fundamental Skill Set. Note: data is provided as well as parts of the solution (key values and
graphs). Student answers may differ in last decimal places due to rounding and truncation. If you
need help use: (1) Excel’s built in help and examples; (2) any of the TAs; (3) search the internet
especially for YouTube tutorials on Excel.
1 Adapted with the permission of the author from “ENGR-202 – Excel Proficiency Module I” by Dr. Tom
Chmielewski
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
2 of 19
C. EXERCISE 1
Using the data inTable 1, which represents a standard weight value applied to a scale
and the measurement obtained from a scale
a. Plot measurement vs. standard (hint: type in data and use scatter chart) b. Label each axes and make sure the plot only goes from 0 to 70 lb. on the x axis
and 0 to 80 lb. on the y axis
c. Find the linear trend line and the R squared value and include on chart d. Make the plot lines thicker so they can project and print well e. Include grid lines
The end result should look something like Figure 1.
Table 1: Data for exercise 1 representing a standard weight and the measurement read from the
scale.
Standard (lb) 0 5 10 15 20 25 30 35
Measurement (lb) 0.72 5.36 10.42 15.76 20.57 25.67 30.65 35.67
Standard (lb) cont’d 40 45 50 55 60 65 70
Measurement (lb) cont’d 40.38 45.35 50.74 55.42 60.69 65.65 70.39
Figure 1: Graph that should be obtained in exercise 1 for the scale input/output.
D. EXERCISE 2
Given the data in Table 2,
a. Compute the average value and standard deviation of the population. In your Excel sheet, fill the average value cell with a red background and outline the standard
deviation cell with a black border.
b. Plot the mean value and the data about the mean for each of the samples i. The x axis should be labeled samples 1 thru 15
ii. The scatter should be points – not a curve iii. Plot a straight line corresponding to the mean
y = 0.9993x + 0.5872 R² = 1
0
10
20
30
40
50
60
70
80
0 20 40 60
M e
a su
re m
e n
t (l
b )
Standard (lb)
Measurement (lb)
Linear (Measurement (lb))
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
3 of 19
iv. Label all axes and make lines dark enough to project v. Place the legend at the bottom of the graph as shown
Table 2: Data for exercise 2 of the read weight of a standard.
Measurement No. 1 2 3 4 5 6 7 8
Measured Value (lb) 5.0436 5.0974 5.0682 5.0585 5.0326 5.0919 5.0720 5.0272
Meas. No., cont’d 9 10 11 12 13 14 15
Meas. (lb), cont’d 5.0493 5.0814 5.0861 5.0267 5.0942 5.0650 5.0713
Figure 2: Expected figure produced from exercise 2 for the measured average and scatter.
E. EXERCISE 3
Using the data of exercise 2, plot the histogram of the measured data. In this example, we
used a total of 7 bins with the center bin having the mean value. Compare the number of points
above and below the mean to the scatter plot of exercise 2.
Figure 3: Expected figured produced from exercise 3 for the histogram of measured values.
5.000
5.020
5.040
5.060
5.080
5.100
5.120
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
M e
a su
re d
V a
lu e
( lb
)
Measurement Number
Measured Value (lb) Average (lb)
1
2 2
1
4
2
3
0 0
1
2
3
4
5
F re q u e n cy
Bin
Frequency
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
4 of 19
F. ADVANCING THE FUNDAMENTAL SKILL SET
The objective is to now utilize more features of Excel so that your spread sheets are more
readable. You can use named variables to facilitate documentation in an algorithm. For example,
use “mass_beam” rather than “$AQ$106”.
Note you can also name columns of data. For instance if the column consisting of
the numbers 1, 2, 3 is named “ data_v” then “ average(data_v)” will compute the average.
Named columns can be used to define data ranges in graphs etc.
Students should duplicate Exercise 4 to understand how to name cells. It should be noted
that you can use named cells to define the variables in a formula. For instance if you wanted to
solve for P in the formula
𝑃 = 48𝐸𝐽
𝑙3 𝑑
all that you would need to do is define the cells with numerical values and named E, J, l, and d.
Then enter the formula “= 48*E*J*d/(l^3)” in a cell. Note some names are reserved for Excel so
you may have to choose different names if you get an error.
G. EXERCISE 4
Let us revisit Exercise 2. In this case we will present the data as a column and name the
columns. Then we will compute the average and standard deviation and also name the results.
To name a cell (or column or row of cells) select the cell(s), right click and choose Define
Name from the pull down list.When you choose Define Name Excel will fill in the name if there
is text such as “my_name” in the cell to the left or above the cell(s) highlighted. You have to
click ok. You can also override the name Excel chooses if you wish. It is a good idea to include a
column/row with the name of the variable to aid in documentation. In the following Excel spread
sheet example seen in Table 3, the names of the columns are meas_no and in_data while the
name avg_all is the average value of in_data and std_all is the population standard deviation.
You can then use the name of individual cells in computations such as was done in the
highlighted cell. Here we entered “=3*std_all”. Column names can be used as input to plotting
and other functions. We will address how to access individual cells in a named column in a later
lesson.
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
5 of 19
Table 3: Example data with column names for exercise 4.
meas_no in_data
1 5.0436
2 5.0974
3 5.0682
4 5.0585
5 5.0326
6 5.0919
7 5.0720 name of cell command in cell
8 5.0272 avg_all 5.06436 AVERAGE(in_data)
9 5.0493
10 5.0814 std_all 0.023274 STDEV.P(in_data)
11 5.0861
12 5.0267 compute 3x 0.0698219
13 5.0942 standard deviation
14 5.0650
15 5.0713
II. GAUSSIAN PDF OVERLAY - BACKGROUND
With the insight gained from the Excel Proficiency section, you should be able to open
the Excel file titled: Lab2_Part3_Gaussian_Overaly.xlsx. This file contains 160 data points
corresponding to measurements of the inner diameter of a washer from a previous class. It has
two tabs: the first tab, “Process_Data”, generates the scatter plot of the data around its average
value as well as the histogram of all the data. The second tab, “Gauss_overlay”, uses a static
copy of the histogram data and overlays a Gaussian (or Normal) pdf. To overlay the histogram
with a pdf you must first generate the values of p(x) using the definition of the Gaussian or
normal probability distribution function. Each of these values must be multiplied by the total
area under the histogram so that the area under the pdf becomes the same as the histogram. This
allows a meaningful overlay of the plots. Read the notes associated with key cells. You will need
to do this for you data analysis of the measurements.
III. MECHANICAL MEASUREMENTS & ANALYSIS – BACKGROUND [2]
All scientific and engineering knowledge about the physical world and its governing
principles has been gained by observation and experimentation. The numbers used to describe
physical phenomena and properties are called physical quantities. In order to be consistent each
physical quantity must be expressed in some accepted units whose values are referred to some
accepted standards. In any measurement of a physical quantity, there is always some
experimental error. There are a variety of methods used to identify, control and minimize these
errors. This experiment will provide an opportunity to measure length, a basic physical quantity,
2 Adapted with permission of the authors from “Basic Measurements and Analysis” by K. Scoles, T. Chmielewski,
D. Miller, and R. Marino as based off of R. Carr and R. Quinn, An Introduction to the Art of Engineering.
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
6 of 19
and develop skill in using a variety of instruments designed for this purpose. It will also provide
an opportunity to learn and apply concepts, practices and procedures fundamental to all types of
scientific and engineering experimentation.
After performing this exercise, students should be able to:
a. Determine the accuracy and precision of instruments. b. Measure length using a linear scale (ruler), a Vernier caliper and a micrometer. c. Properly acquire and record data using these instruments. d. Analyze data to identify and/or minimize error. e. Select an optimum method of measurement for a given length measurement
application.
f. Construct a histogram.
A. BACKGROUND INFORMATION
All analog measurements have error and a consequent uncertainty. Errors are classified
as systematic or random. Systematic errors are usually categorized as instrumental, personal, or
extraneous. An instrumental error is due to faults or limitations of the measuring device. This
includes improper calibration as well as broken devices.
Personal errors vary from one observer to the next and indicate any bias the observer
may have. Extraneous errors are introduced by the environment in which measurements are
taken. For example, air currents from a fan or window may alter the readings of mass obtained
on a mass scale.
Hysteresis is another phenomenon that may contribute to error. An instrument is said to
have hysteresis when it shows a different reading for the same measured quantity depending
on whether the quantity is approached from above or below.
Some of the systematic errors may be corrected using a calibration curve. A plot of the
instrument reading against the standard being measured is called a calibration curve. We can
imagine an ideal instrument for which each measurement exactly equals the quantity being
measured. Thus the calibration curve for an ideal instrument is a line of slope one through the
origin. Figure 4 depicts calibration curves for an ideal instrument, a non-ideal instrument and an
instrument with hysteresis.
Figure 4: Calibration curves for (1) an ideal instrument, (2) a non-ideal linear instrument, (3) a
non-ideal, nonlinear instrument with hysteresis.
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
7 of 19
Random error is statistical in nature. These errors change with time and/or position, and
have an associated probability. An increase in the number of measurements taken will reduce the
effect of these errors because they tend to cancel out. Many times it is impossible to eliminate
the errors in a method of measurement. In these cases it is important to be able to reproduce the
same readings. In other words, the errors should be consistent in all measurements.
All errors affect the results to varying degrees. As measurements are used to compute
other physical quantities, the errors are carried throughout in the computation. This compounding
of error as it is carried at each consecutive step is called propagation of error.
B. EXAMPLE 1: UNCERTAINTY
a. The diameter of a rod is given as 32.41 ± 0.02 mm. Thus the actual diameter may be anywhere between:
i. a maximum of: 32.41 + 0.02 = 32.43 mm. ii. a minimum of: 32.41 – 0.02 = 32.39 mm.
b. The mass of a rod is given as 10 grams with a 20% error. Thus the actual mass of the rod may be anywhere between:
i. a maximum of: 10 + 10 • (0.2) = 12 grams ii. a minimum of and: 10 – 10 • (0.2) = 8 grams
C . EXAMPLE 2: ACCURACY
The accuracy of a measurement is its deviation from the actual value of the quantity
being measured. If, for example, a certain balance measures a 100 grams standard mass as
110 grams, its accuracy is only 10%. Similarly, the accuracy of an instrument measures the
deviations of its readings from known inputs. Of course the accuracy depends on the input, so
one arbitrarily defines the accuracy of an instrument as a percentage of its full-scale reading. If
a voltmeter with a 100 V range has an accuracy of 2%, its reading over this range would be
accurate within ±2 volts.
D. EXAMPLE 3: PRECISION
The precision of an instrument has to do with the repeatability of its readings. If the
balance from the previous example gives five different readings (99.0 g, 101.0 g, 100.0 g, 99.5 g
and 100.5 g) for the same standard mass of 100 grams, then its precision would be ± 1.0 g
since the individual measurements deviate from the average (100.0 g) by at most ±1.0 g.
E. EXAMPLE 4: PROPAGATION OF ERROR IN A VOLUME CALCULATION
The linear dimensions of a metal bar are measured within an uncertainty of ±0.1 inch as
illustrated in Figure 5. Find the maximum and minimum values for the volume V of the
metal bar. If the measurements were exact, the volume V would be given by the product: V
= Length x Width x Height = 2.7 in • 2.7 in • 11.5 in = 83.8 in 3 .
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
8 of 19
Figure 5: Metal bar for example 4
But the measurements are not exact and the actual volume of the bar could lie between:
1. a maximum of 2.8" • 2.8" • 11.6" = 90.9 in 3
.
2. a minimum of 2.6" • 2.6" • 11.4" = 77.1 in 3 .
Notice how a seemingly small error in the original measurements is magnified in the
volume calculation.
Finally, we would like to review two related concepts: least count and sensitivity.
Least count is the smallest increment of the measurement unit that can be detected with the
instrument. Sensitivity is defined by the equation:
𝑆𝑒𝑛𝑠𝑖𝑡𝑖𝑣𝑖𝑡𝑦 = ∆𝑂𝑢𝑡𝑝𝑢𝑡
∆𝐼𝑛𝑝𝑢𝑡
In approaching a given experimental problem, various criteria can determine which
method of measurement is optimum or "best". For example, high priority may be given to the
errors a method will introduce and the effect of such errors on the end result. Clearly an
uncertainty of ±1 tsp. salt in a large pot of soup prepared for 20 people is not as significant as ±1
tsp. salt in an individual serving. In another application an engineer might have to give primary
consideration to the practicality of each method. An engineer working in the field will find it
inconvenient to carry an analytic balance. A less precise trip balance may be the best choice for
reasons of convenience alone. Therefore, the purpose of each measurement must be clearly
defined. In this experiment, our purpose is to learn about experimentation and we will explore
different devices and concepts. For our purposes, all equipment will be assumed to be equally
practical.
F. MEAN & STANDARD DEVIATION
Suppose a measurement is performed on N objects giving the data {x1, x2, …, xN}. The
average number of arithmetic mean is given as:
�̅� = 1
𝑁 ∑ 𝑥𝑖
𝑁
𝑖=1
where xi is an absolute measurement and N is the total number of measurements. The absolute
deviation, di, of an individual reading, xi, from the mean value, x, is defined as:
𝑑𝑖 = |𝑥𝑖 − �̅�|
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
9 of 19
The standard deviation of a set of numbers is denoted by the Greek letter sigma, σ. For a
complete set of data, the standard deviation is defined by:
𝜎 = √ 1
𝑁 ∑(𝑥𝑖 − �̅�)
2
𝑁
𝑖=1
However, if the set of points, xi, represents only a sample of the possible readings then we must
use the sample standard deviation formula:
𝜎 = √ 1
𝑁 − 1 ∑(𝑥𝑖 − �̅�)
2
𝑁
𝑖=1
The standard deviation tells how much a typical measurement will deviate from the mean. That
is, it is a measure of the dispersion of the readings from the mean value.
The most precise method of measurement is the one that yields the smallest standard
deviation. In other words, the smaller the deviation from the mean is, the more repeatable the
reading is. The most accurate method may not be the most precise.
Based on the data and these observations it is possible to select the instruments that
comprise the optimum or "best" method of measurement. Using the standard deviation as the
uncertainty, the range of most likely values should be specified in the report.
G. MORE ON HISTOGRAMS
A histogram is a convenient pictorial representation of the distribution of a set of
collected data. A histogram is a graph composed of rectangles. The rectangles composing the
histogram lie over non-over lapping intervals called class intervals or bins. The area of these
rectangles is proportional to the frequency of each interval, which is the number of observations
that fall in each class interval. Usually a histogram is constructed using equal length intervals, so
that the frequencies are proportional to the heights of the rectangles.
The issue of how many rectangles or bins, K, are appropriate for a particular size of data
set3 is addressed by the relationship:
𝐾 = 1.87(𝑁 − 1)0.40 + 1
An estimate of 𝐾 ≈ √𝑁 2
works well for large N.
We would like to introduce at this point some further properties of histograms.
Histograms can be unimodal, bimodal, and multimodal. A histogram that increases to a peak and
then decreases is a unimodal histogram. A bimodal histogram is one with two different peaks
and similarly, a histogram with more than two peaks is called multimodal.
3 Kendal, M.G. and A. Stuart, Advanced Theory of Statistics, Vol. 2, Griffin, London, 1961.
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
10 of 19
A unimodal histogram may be further classified as either symmetric, positively skewed
or negatively skewed. A histogram is said to be symmetric if both the left and right halves are
mirror images of each other. A positively skewed histogram is one with its right side more
stretched out than the left. When the stretching is mostly toward the left then it is said to be a
negatively skewed histogram. Figure 3 shows examples of these various types of histograms.
(Note that a smooth curve has been drawn to represent the tops of each rectangle.)
Figure 6: Symmetry and Modality of Histograms
H. HOW TO USE CALIPERS
Each caliper consists of jaws for holding the object to be measured and two bars with
scales -the main scale and the Vernier scale. Calipers are useful for measuring outside diameters
with the large flat jaws (number 1 in Figure 7), inside diameters with the inside jaws (number 2
in Figure 7), and hole depths (number 3 in Figure 7). Both scales are marked in inches and in
millimeters. For the purposes of this lab, take all measurements in inches. The object to be
measured is first placed between the jaws of the calipers and then the jaws are adjusted to obtain
a snug fit.
Figure 7: Calipers showing two sets of measuring jaws and the protruding depth probe.4
Table 4: List of parts to accompany Figure 7.
1 – outside jaws: used to take external
measures of objects
5 – main scale (inch)
2 – inside jaws: used to take internal measures
of objects
6 – Vernier (cm)
3 – depth probe: used to take the depth of
objects
7 – Vernier (inch)
4 – main scale (cm) 8 – retainer: used to block movable parts
4 http://upload.wikimedia.org/wikipedia/commons/9/96/Vernier_caliper_new.png
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
11 of 19
I. HOW TO MEASURE IN INCHES
Each division on the standard scale corresponds to 0.025 inches. Each division on the
sliding scale corresponds to 0.001 inches or one thousandths of an inch.
Find the division mark on the standard scale that lies just before the zero mark on the
sliding scale. This division gives the length to the nearest 0.025 inch which does not exceed the
true length. Thus the true length is always a little larger.
Next look for the division mark on the sliding bar which exactly lines up with a division
mark on the standard bar. Read this number using the scale on the sliding bar and add it to the
previous number.
In
Figure 8, the division mark on the standard bar that lies just before the zero mark on the
sliding bar is 0.675 inches. The division marks on the two scales line up at the division
corresponding to 0.015 inches so that the total measurement is: 0.675" + 0.015" = 0.690"
Figure 8: Example of combing the results at the caliper zero mark and point where division
marks on sliding and standard bars line up.
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
12 of 19
J. USING THE MICROMETER
Figure 9: Micrometer showing measuring bar (A) and adjustor (B)
A – Measuring bar
Each numbered line on the measurement bar represent 0.1 inches.
The lines on the top half of the measurement bar are in increments of 0.05 inches.
The lines on the bottom half of the measurement bar are in increments of 0.025 inches.
B – Adjustor
The numbers on the adjustor increase from 0 to 25 (i.e. 0.000 to 0.025 inches). Each full rotation of the adjustor
moves the column 0.025 inches or one increment on the
bottom half of the measurement bar.
K. EXAMPLE OF MEASURING WITH MICROMETERS
The example below is using Figure 10. Note: You might want to take photographs of the
caliper and micrometer that you actually use for your report since they may look different from
the ones in this handout.
Measurement reading on the measurement
bar (rounded down to the nearest line).
+
Measurement reading
on the adjustor
=
Measurement
reading
0.25 in. + 0.179 in. = 0.2679 in
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
13 of 19
Figure 10: Example reading on the measurement bar and adjustor of a micrometer.
The “9” in the 0.179 is the estimated value between the lines. This is the precision of the
instrument.
L. FURTHER INFORMATION
How to use and read a Vernier caliper, http://www.tresnainstrument.com/how_to_read_a_vernier_caliper.html
Vernier caliper tutorial, http://www.physics.smu.edu/~scalise/apparatus/caliper/tutorial/
How to use a micrometer, http://www.youtube.com/watch?v=oHqaLMEHlnE
How to read an outside micrometer, http://www.pgiinc.com/howtoreoumi.html
IV. MECHANICAL MEASUREMENTS AND ANALYSIS – PROCEDURE
Each group will be provided with 20 sample washers and 30 sample bolts (sets of 6 from
5 different kinds). In this part of the experiment your team will measure thickness of the washers,
the thread diameter of the bolts and the length of the bolts. In this experiment, errors could
include poor alignment of the caliper or micrometer. Personal errors arise from changes in
perspective, angle of sight or even the lighting in the room, try to be consistent in your method to
take the measurements to avoid artifacts in the data.
Each member will be required to measure the 20 washers and 30 bolts with both the
calipers and the micrometer. The order of measurements does not matter. When the group is
finished they should have the data in an Excel sheet similar to the following (note that this Excel
example only shows the washer data). Make sure you state the dimensions properly.
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
14 of 19
As you take the data, consider the sources of error in each measurement, and how they
may change from instrument to instrument. For example, gently close the jaws of your
micrometer. Does the instrument indicate 0.0000, i.e. does it have a zero offset? Is the offset
positive or negative? What type of error would an offset introduce? There are methods to adjust
the instrument to remove the offset, but we will not do this at this time. Also, note the limitations
of the measurement tools you have available (can you measure all the requested dimensions with
both tools? Why?)
V. MECHANICAL MEASUREMENTS AND ANALYSIS – ANALYSIS
It is highly suggested that you complete this during the lab. This will ensure that you
have correct data and give you a chance to retake data if necessary. Using the Excel skills from
parts I and II of this lab
a. Compute the mean and standard deviation for i. Each set of data (i.e. Student 1 micrometer)
ii. Combined set of micrometer data iii. Combined set of caliper data iv. All data combined
b. Create scatter plots with mean and accuracy limits (see Lecture 1) as well as histograms for i. Combined set of micrometer data
ii. Combined set of caliper data iii. All data combined
c. Overlay the histograms with Normal distributions – discuss if they match why or why not.
washer thickness Student 1 Student 2 Student 3
cal mic cal mic cal mic
sample dim?
1
2
3
4
5
6
7
8
9
10
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
15 of 19
Lab 2b: Image Analysis with MATLAB Original: S.J. Pagano. Edited by: R. Robinson, S. Leist & M. Janko
Goals
Understand how a digital image is stored
Analyze objects within an image using MATLAB Image Processing Toolbox
Perform statistical analysis on the geometry of the objects
Equipment/Software
MATLAB + Image Processing Toolbox Add-on
Digital Camera (Smart phone will suffice)
I. INTRODUCTION
Pictures have been recorded since the early part of the 19th century. Until the advent of the
semiconductor and many years of technological advancement all photographs were recorded
using some type of film-based technology. Film cameras work by taking ambient light (white
light) traveling through a lens system and passes it through color filters to separate red, green,
and blue (RGB) and expose the film, recording an image (Figure 11). Digital cameras, in the
commercialized sense, have only been in use for a relatively short period of time. However, in
that time there has been great advancements in the quality of a single picture and ever-shrinking
camera packages that allow you to record 4K HD quality pictures with a smart phone.
Digital images are recorded using a sensor that is either a charge-coupled device (CCD) or
complementary metal-oxide semiconductor (CMOS). The difference between the two
technologies comes down to how the sensor records the information, but in both cases a
photodetector records the wavelength and intensity of light, storing the information within the
sensor. A photodetector is a physical object, and in the case of smart phones is typically on the
order of a few microns in size. For example, the Nexus 6P uses 1.55 µm pixels, and can pack
11,968,000 of these pixels into a sensor that is only 6.17 x 4.55 mm. In comparison, a single
strand of human hair has a diameter of about 40 µm.
Digital pictures are stored using a matrix that maps each pixel to a matrix coordinate.
Storage of a color image is accomplished using multiple matrices of the same size, this is also
known as a ‘multi-dimensional array’. In the simplest sense, an 800x600 image has a 4:3 aspect
ratio, and would be stored in a multi-dimensional array that is 600x800x3, for 600 rows and 800
columns of pixels, in three individual layers of color intensity (R,G,B). When you view an
image on a computer, the software processes the array into a single, visible image.
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
16 of 19
Figure 111: Example of photography technology: (A) Analog film exposed using color filters to
capture RGB field, (B) Digital sensor that collects RGB color using CCD or CMOS technology.
Image adapted from [5].
II. PROCEDURE
A. PART 1: IMAGE ANALYSIS BASICS
Multiple images of different color dots have been provided (dots.png, vitamins.jpg and
BOLTS.jpg). Your task is to load each image into MATLAB, then break it apart to show how
the individual colors are mapped to the original image. If we return to our example of an
800x600 image, MATLAB will read that image as 600x800x3, where (:,:,1) is red, (:,:,2) is
green, and (:,:,3) is blue. Each layer is valued from 0 to 255, where 0 means there is no data
(black), and 255 means there is full intensity of that particular channel. Breakdown of a simple
colored pattern is provided in Figure 12. Note how the lower row of the individual channels only
pulls out red, green, and blue, while the top row of the channels shows how each color mixes to
produce yellow (R+G), cyan (G+B), and magenta (R+B). The lower row of images is provided
as a complementary image, meaning the intensity value (0-255) was inverted.
Figure 112: Example of a color image (RGB), associated grayscale intensities, and individual
color channel contributions.
5 Digital Photography Tips: http://www.digital-photography-tips.net/history-of-digital-photography-consumer-digitals.html
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
17 of 19
1. For each of the provided images your task is to produce a figure that is similar to Figure
12, showing the grayscale intensities, and R-G-B channels. Refer to the list of helpful
commands at the end of the lab guide and example code for generating the figure.
2. Comment on how each channel is used to make up the individual colors in the original
image.
B. PART 2: PERFORMING AN ANALYTICAL ANALYSIS OF IMAGES
The first part of this section was designed to help you understand how to take apart a
digital picture. Part 2 will focus on how we can use an image to produce analytical data
representing the geometry of objects in the image. Your task will be to process an image of
multiple objects, extract geometry, and use that geometry to create statistical distributions. The
simplest way we can extract geometry is to fit an ellipse to objects in the image, and use the
major axis to define an object size.
EXAMPLE: Measuring Bolts length (Provided Image: BOLTS.jpg)
Using the MATLAB code example below, see how each step of the code performs the
following actions:
1. Read in the image of the bolts provided (BOLTS.jpg).
2. Convert the image to grayscale, then to a binary (black/white) image, use filtering and
inversion as required.
3. Use the ‘regionprops’ function (built in MATLAB) to generate geometry data (major axis
of a best-fit ellipse, you may want to read the ‘help’ provided by MATLAB).
a. Note: Black = 0, White = 255, therefore, in order to analyze an image, the objects
in the image must be white.
b. You need to inspect the results of each step to ensure that it is working correctly.
4. Interpret the results stored in the variable: ‘major’
a. What are the magnitude and units of the data reported in each variable?
b. How does the color of the objects and background affect the results of
‘regionprops’?
c. How would you make the results of ‘regionprops’ have a physical meaning?
Table 5: List of helpful MATLAB commands.
Command Use
imread(‘image.ext’) Read an image and store as a multi-dimensional array
imshow(image) Open a figure window and displays the image
imcomplement(image) Returns a matrix with complementary colors
(BlackWhite)
rgb2gray(image) Converts RGB image to grayscale
im2bw(image,t) Converts grayscale to binary with threshold 0 < t < 1
regionprops(image,'MajorAxisLength') Extracts the elliptical properties (Centroid, Major
Axis, etc…), See ‘help’
bwareaopen(image,p) Removes objects that are p sized or smaller.
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
18 of 19
Example Code for Reading and Visualizing figure in MATLAB:
image=imread(‘BOLTS.jpg’); % Read-in Image R=image(:,:,1); % Extract Red Component G=image(:,:,2); % Extract Green Component B=image(:,:,3); % Extract Blue Component image_gs=rgb2gray(image); % Convert Image to Grayscale
figure(1) subplot(2,3,[1,1.5]),imshow(image);hold on;;title('Original','FontWeight','bold','FontSize',16); subplot(2,3,[2.5,3]),imshow(image_gs);title('Grayscale','FontWeight','bold','FontSize',16); subplot(2,3,4),imshow(R);title('R','FontWeight','bold','FontSize',16); subplot(2,3,5),imshow(G);title('G','FontWeight','bold','FontSize',16); subplot(2,3,6),imshow(B);title('B','FontWeight','bold','FontSize',16);
%% Plotting figure(1) subplot(2,3,[1,1.5]),imshow(image);hold on;;title('Original','FontWeight','bold','FontSize',16); subplot(2,3,[2.5,3]),imshow(image_gs);title('Grayscale','FontWeight','bold','FontSize',16); subplot(2,3,4),imshow(R);title('R','FontWeight','bold','FontSize',16); subplot(2,3,5),imshow(G);title('G','FontWeight','bold','FontSize',16); subplot(2,3,6),imshow(B);title('B','FontWeight','bold','FontSize',16);
Example Code for Extracting Major Axis Length:
image_bw=im2bw(image_gs, 0.40); % Convert Image to Binary image_bw=bwareaopen(image_bw,200); % Noise filter (image,pixel) region=regionprops(image_bw,'MajorAxisLength'); % Find geometry major=[region.MajorAxisLength]; % Vector of Major Axis
Using image processing to collect measurements of the bolts
Using your phone (or any camera available to you) take a picture of all the bolts you measured in
Section IV: Mechanical Measurements and Analysis – Procedure. For this image repeat the
analysis of the image analysis example and in addition generate the following:
a. Histogram of the size (length) distribution.
b. Table of acquired sizes.
c. Combined figure of the original, grayscale, and filtered binary image.
ENGR 202 – Evaluation and Presentation of Experimental Data II – Summer 2016
Lab 2: Basic Mechanical Measurements and Image Analysis with MATLAB
19 of 19
III. REPORT
The report format should follow that in the “ENGR202_Report_Grading.pdf” posted on
the BbLearn site for the course. You are expected to present your methodology and results in a
lab report/ narrative format. The lab report main body should contain: the equipment used; the
methodology used for the measurements; and answers to questions posed in this lab manual.
Calculations (either hand calculations or Excel generated) should be provided in an Appendix.
Show all calculations. At no time should you cut and paste text from your lab handout into your
report. Only put graphs that you want to discuss in detail into the body of your report. The others
can go into an appendix.
Here are some questions to that must be answered in the discussion of results and
conclusions, but do not limit yourself to these:
a. If you needed a measurement to the nearest 0.1 inch, what instrument would you choose? How about 0.01 in, 0.001 in, or 0.0001 in?
b. How did your individual measurements compare to your team results? c. Comment on the accuracy and precision of the measurements. The washers you have are
stamped parts, and you would not expect them to have high precision. What size bolt do you
think they are designed for? How do the sets of bolt measurements compare?
d. Which instrument produces the narrowest distribution of results? What shape do the distributions have?
e. Which standard deviation function did you use in your calculations? Why? f. Discuss whether the histograms match a Gaussian distribution – why or why not. g. How do your bolt measurement results compare to your mechanically measured results?
Compare the errors.
h. What would cause error in your image analysis for counting and dimensional measurements of the objects?
i. What are some good applications using MATLAB’s image analysis tool? What are the pros and cons?
One hardcopy per group should be turned in to your TA. Reports are due at the beginning
of your next scheduled lab meeting. Check BbLearn for a grading rubric which will include more
hints on what to include in the lab and an example report format to get you started.