Download presentation
Presentation is loading. Please wait.
1
John Federici NJIT Physics Department
Physics 114: Lecture 4 More MatLab Basic matrix/array operations for reading in data and for graphical output Image Data Cartoon and histograms Lecture04 APPLICATION: Write a basic MatLAB program to read in real data and make a plot John Federici NJIT Physics Department
2
Physics Cartoons
3
Data for Images HINT: Use ‘pathtool’ in command window to open path set dialog box You can IMPORT images for files in several ways Use IMPORT DATA tool and specify the file type to be an image (eg. JPEG) Use IMPORT DATA tool to create MATLAB code Use “imread” function IMdata=imread('Cartoon.jpg') Note that the data is imported as INTEGERS for the image. Why is the array of integers a 3D array with the ‘z’ dimension being 3 units for a color image? Display the image using ‘image()’ command >> IMdata=imread('Cartoon.jpg'); >> image(IMdata)
4
Data for Images Since images are just integers, we can create our own images by defining an array of numbers. In this example, we SCALE the colors so that each color represents a number >> C = [ ; ; ]; imagesc(C) colorbar BUT, we can also create images on NON-integers >> [X,Y] = meshgrid(-2:.2:2); >> Z = X .* exp(-X.^2 - Y.^2); >> imagesc(Z) >> colorbar
5
Colormap R G B mymap = [0 0 0 ; 1 0 0 ; 0 1 0 ; 0 0 1 ; 1 1 1];
A colormap is matrix of values between 0 and 1 that define the colors for graphics objects such as surface, image, and patch objects. MATLAB draws the objects by mapping data values to colors in the colormap. Colormaps can be any length, but must be three columns wide. Each row in the matrix defines one color using an RGB triplet. An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0,1]. A value of 0 indicates no color and a value of 1 indicates full intensity. For example, this is a colormap with five colors: black, red, green, blue, and white. R G B mymap = [0 0 0 ; ; ; ; 1 1 1];
6
Colormap EXAMPLES >> colormap summer >> imagesc(Z)
>> colorbar >> colormap default >> imagesc(Z) >> colorbar >> mymap=[0 0 0 ; ; ; ;1 1 1]; >> colormap(mymap) >> imagesc(Z) >> colorbar
7
Converting RGB to grayscale
>> colormap gray(256) >> grayout=rgb2gray(IMdata); >> image(grayout) >> colorbar An aside: What does the x and y axis scale denote?
8
How to acquire Image data using your Laptop’s Webcam
9
Find your webcam among the Devices
You will need to install an image adapter so that the your camera can be controlled via Matlab. Usually, the default winvideo adapter will work. Open Matlab And demonstrate Show export of data
10
Histograms >> z=randn(1000,1);
>> % produce an array (1000 by 1) of Normal Distribution >> % ie. Gaussian distribution of random numbers >> nbins=25; % set # of bins to 25 >> h=histogram(z,nbins); >> xlabel('Value') >> ylabel('# of occurrances') NOTE: histogram ASSUMES that you have 1D data. If you have 2D data (eg. in image) and would like to have a histogram of ALL the data combines, you must first combine the 2D data into a 1D array. Use ‘reshape’ function
11
Histograms Nbin=40 Nbin=25
Note that the shape as well as # of occurrences will change when you change the # of bins (or equivalently, the WIDTH of each bin. Nbin=25 Nbin=40
12
Histograms h = Histogram with properties: Data: [1000x1 double]
Number of bins, Bin limits, and Bin width are related. h = Histogram with properties: Data: [1000x1 double] Values: [1x25 double] NumBins: 25 BinEdges: [1x26 double] BinWidth: BinLimits: [ ] Normalization: 'count' FaceColor: 'auto' EdgeColor: [0 0 0]
13
Histograms Why does the histogram NOT look like a Gaussian distribution?
14
Histograms 100 samples 1000 samples 10000 samples
Why does the histogram NOT look like a Gaussian distribution? 100 samples 1000 samples 10000 samples
15
Class Exercise: Simple processing of an image/ Histogram
Use Matlab HELP or DOCUMENATION SEARCH as needed Create a MATLAB program which Reads in as an image the CARTOON which is posted with the lecture notes on the course web page. Convert the color image to grayscale and Plot the cartoon to make sure that it looks correct. Create a HISTOGRAM of the image pixel counts. Vary the number of bins in the histogram. Does the shape of the histogram appear to change? If you have time, use the camera on your laptop and MATLAB to take a picture of yourself and save the image as a grayscale. Create a histogram of the pixel counts of your image.
16
Preparation for HW #3 For Homework #3, you will prepare JOURNAL QUALITY figures from experimental data You will plot data from a Terahertz (THz) transmission measurement Visible Radio Microwave THZ Infrared UV X-rays Frequency (Hz) 1 THz frequency = 300 m wavelength or 33 cm-1 or 4.1 meV or T = 48 K Also known as Far-Infrared or sub-millimeter
17
THz Transmission Measurement
Think of THz pulses of radiation as similar to a Radar pulse Unlike many other light detectors, my THz system measures ELECTRIC field rather than POWER (~E2)
18
THz Transmission Measurement
Think of THz pulses of radiation as similar to a Radar pulse
19
Download Data for HW#3 from Course Webpage
01/17/ :38:41 Ver Long Scan Optical Delay Delta X (ps) Sweeps 1 Two lines of comments on experimental details Column data of THz Electric Field in Arbitrary Units Column data of time in picoseconds
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.