Presentation is loading. Please wait.

Presentation is loading. Please wait.

Reading and Writing Image Files

Similar presentations


Presentation on theme: "Reading and Writing Image Files"— Presentation transcript:

1 Reading and Writing Image Files
We’ve explored several options for reading in image information MATLAB also supports functions to write images to a number of different formats

2 Reading Image Information
Interactive Import Wizard Easiest Simply double click the file name from the current directory MATLAB will suggest appropriate variable names The matrices are available in the edit window for preview

3 The downside… The problem with interactively importing any data is that you can’t include the instructions in a MATLAB program We need one of the import functions Most standard images can be read in using imread

4 Use load for .mat .dat load cape

5 Image created by loading a built in file

6 Storing Image Information
Use the file menu File-> Save as… Most of the common formats are supported

7 This image of a Mandelbrot is being saved as an enhanced metafile

8 imwrite This function can also be used to store image data in a number of different formats The input depends on the image type Intensity (grayscale) True color Indexed – requires an array plus a colormap

9 Section 14.2 Handle Graphics
A handle is a “nickname” given to an object in MATLAB We can assign a handle to Individual plots The figure window The axis on which we draw the plots

10 Figure User Interfaces Axes Annotation axes Core Objects Plot Objects
Group Objects MATLAB uses a hierarchical system for organizing plotting information

11 Figure User Interfaces Axes Annotation axes Core Objects Plot Objects
Group Objects The basic plotting object is the figure. The figure can contain a number of different objects

12 Figure User Interfaces Axes Annotation axes Core Objects Plot Objects
Group Objects The axes are contained inside the figure. Think of the axes as being layered on top of the figure window . The axes also can contain a number of different objects .

13 Figure User Interfaces Axes Annotation axes Core Objects Plot Objects
Group Objects A plot is drawn on top of the axes.

14 Anatomy of a graph Figure Axes layered on top of the figure
Plot drawn on the axes

15 When you use a plot function…
MATLAB automatically creates a figure an appropriate axis draws the graph (plot) on the axis MATLAB uses default values for many of the plot object properties. For example the first line drawn is always blue, unless the user specifically changes it.

16 Plot Handles Assigning a plot a name (or a handle) allows us to easily ask MATLAB to list the plot object properties

17 h is the plot handle

18 h is the plot handle in this example
The color property specifies the line color – in this case blue The get function returns a list of the object (in this case a plot) properties For example, the LineWidth property is set to 0.500

19 Figure Handles We can also specify a handle name for the figure window

20 The color property specifies the background color in the figure window – in this case gray
F_handle is the figure handle in this example A figure window has a lot of properties

21 If we haven’t specified a handle name, we can ask MATLAB to determine the current figure with the gcf command (get current figure) get(f_handle) and get(gcf) return the same results in this example

22 Axis Handles Just as we can assign a handle to the figure window and the plot itself, we can assign a handle to the axis using the gca function (get current axis ) for example h_axis = gca

23 h_axis is the name of the axis upon which the plot is drawn in this example

24 Annotation Axes In addition there is a transparent layer added to the plot, used for annotation objects, such as: lines legends text boxes

25 What good is all this information?
Use the set function to change the object properties Set requires at least three inputs object handle (plot, figure or axis) property name a new property value

26

27 Property Editor You can accomplish the same thing interactively using the property editor and the property inspector

28 Interactive Property Editing

29 14.3 Animation There are two techniques for creating an animation in MATLAB redrawing and erasing creating a movie We use handle graphics in each case to create the animation

30 Redrawing and Erasing To create an animation by redrawing and erasing you first create a plot then adjust the properties of the graph each time through a loop

31 Consider this equation for a set of parabolas
Each value of k defines a different parabola We could represent this data with a three dimensional plot Or we could create an animation where we draw a series of graphs, each with a different value of k

32 Animation works by redrawing the graph multiple times.

33 M-file to animate the equation of a parabola

34 In this example we… used the XData and YData objects from the plot
These objects assign the data points to be plotted Using the set function allows us to specify new x and y values, and to create a different graph every time the drawnow function is called

35 In the program notice the line…
%set(h,'EraseMode','xor') If you activate this line by removing the comment operator (%) the program does not erase the entire graph each time the graph is redrawn. Only pixels that change color are changed. This makes the animation run faster, a characteristic that is important when the plot is more complicated than the simple parabola used in this example. Refer to the help tutorial for an example animation modeling Brownian Motion.

36 Movies Animating the motion of a line is not computationally intensive, and it’s easy to get nice smooth movement Animating the motion of a surface plot is more complicated and correspondingly more computationally intensive

37 The animation of this figure moves up and down - something like a wave – and takes a lot of computational power

38 This file creates an animation of the surface plot, which runs quite slowly.

39 This file creates and stores a movie of the animation
This file creates and stores a movie of the animation. You can play the movie again with the movie function

40 Movies are saved in a structure array, such the M array shown in this figure

41 Example 14.2 illustrates how to create a movie by zooming in on a Mandelbrot image. Because this process is quite computationally intensive, it’s a good idea to try it out with a low resolution mandelbrot image first

42 This series of Mandelbrot images is a selection of the frames captured to create the movie. Each movie will be different, since it zooms in on a different point on the image.

43 14.4 Other Visualization Techniques
Transparency Hidden Lines Lighting

44 First a small sphere was plotted
Adding transparency to a surface plot makes it possible to see hidden details. First a small sphere was plotted Then a second, larger sphere was plotted on top, obscuring the original sphere The alpha function was used to create a transparent surface alpha(0.5)

45 Mesh plots do not show mesh lines that would be obscured by a solid figure
The hidden off command forces the program to draw the hidden lines.

46 The default lighting is diffuse
When the camlight command is issued a spot light is modeled, located at the camera position

47

48 14.5 Introduction to Volume Visualization
Volume visualization of scalar data (where the data collected or calculated is a single value at each point, such as temperature) Volume visualization of vector data (where the data collected or calculated is a vector, such as velocity)

49 MATLAB includes visualization techniques used with three dimensional data. This is a contourslice of MRI data using the sample data file included with MATLAB

50 Isosurface of flow data using the sample m-file included with MATLAB

51 Contour slices of the wind speed data included with the MATLAB program.

52 Cone plot of the wind velocity data included with the MATLAB program.


Download ppt "Reading and Writing Image Files"

Similar presentations


Ads by Google