Keywords: front-page

## Lab: Framing an Image with Rulers

[Exercises] [Workspace]

Purpose: The purpose of this lab is to learn image composing and editing. The goal is to frame the gull image with a ruler. The use of variables in the cantata workspace is introduced in this lab.

Activities:

1. Display the ruler as an aid in developing the workspace using the User defined and Display Image operators. The ruler image file is $DIP/data/ruler.kdf. The image dimensions are 512 x 14. The major tics and numbers are 7 pixels high.

   The operators required to follow the steps described below are:

   1. Glyphs:Data Manip:Size & Region Operators:Extract

      Create a Region Of Interest (ROI)

   2. Glyphs:Data Manip:Size & Region Operators:Inset

      Combine two images by pasting the second image such that its top left corner pixel goes to the inset coordinates of the first image.

   3. Glyphs:Data Manip:Reorganize Data:Flip

      Reflects the data along the specified coordinate.

   4. Glyphs:Data Manip:Reorganize Data:Switch Axes

      Swaps the coordinates of the image.

2. Create rulers for each edge of the "seagull" image. To add flexibility to your visual program, use the "Variables" functionality. Use WIDTH as a variable to control the width of the image to be extracted from the original.

   1. Get size information about the sea gull image using the Data Object Info and File Viewer operators.

      1. Glyphs:Input/Output:Data Files:User defined
      2. Glyphs:Input/Output:Information:Data Object Info
      3. Glyphs:Input/Output:Information:File Viewer

   2. Create the bottom ruler.

      1. This is the original ruler, but needs to be extracted to the same width as the image.
      2. Open the Workspace:Variables... form
      3. Type the following expression into the "Define Variables / Evaluate Expressions" window "WIDTH = 256", and then select the "Cancel" button.
      4. Open an Extract operator pane, but instead of typing in the value of the width (256), type in the variable name "WIDTH". Unselect all other dimensions.
      5. Connect the ruler input to Extract, and connect Extract to a Display Image operator.
      6. Run Extract and display the results to verify that they are correct.
      7. To keep track of which ruler is which, change the label on the Extract operator from Extract to "Extract (Bottom)". Do this by clicking on the glyph title and filling out the pop-up form.

   3. Top ruler:

      1. Extract the numbers of the ruler (first 7 pixels of the bottom ruler) Use the variable HEIGHT (7) in the same way as WIDTH was used in part A. The HEIGHT variable can be used for both the "Region Size" and the "Region Origin". It is a good idea to verify your results in each of these using a Display Image operator.
      2. Extract the ticks of the ruler (top 7 pixels of the bottom ruler).
      3. Flip the ticks along the Height dimension so that they face down.
      4. Inset the ticks below the numbers. Use the HEIGHT variable with the Inset operator.
      5. Relabel the Inset operator to be "Inset (Top)"

   4. Left Ruler:

      1. Swap the axes (width by the height) of the bottom ruler using the Switch Axes operator.
      2. Flip the results about the width dimension using the Flip operator.
      3. Relabel the Flip operator to be "Flip (Left)"

   5. Right ruler:

      1. Repeat the same procedure as for the Left ruler, but using the top ruler instead of the bottom ruler.
      2. Relabel the Flip operator to be "Flip (Right)".

3. Frame the sea gull image with the rulers. Inset the four rulers at the proper positions of the original image, using the WIDTH and HEIGHT variables.

   1. Attach the Upper Ruler.

      1. Select Glyphs:Data Manip:Size & Region Operators:Inset from the cantata menus, and duplicate it so that there are 4 Inset Operators.
      2. Connect the "Upper Ruler" image to "Input 1" of the first Inset operator.
      3. Connect the sea gull image to "Input 2". Set the "Height Coordinate" to 2*HEIGHT.
      4. Connect the output of this "Inset" to "Input 1" of the next Inset.

   2. Attach the Bottom Ruler.

      1. Connect the gull image to "Input 1" of the first Inset operator.
      2. Connect the bottom ruler to "Input 2". Set the "Height Coordinate" to "WIDTH + (2*HEIGHT)".
      3. Connect the output of this "Inset" to "Input 1" of the next Inset

   3. Attach the Right Ruler.

      1. Connect the Right ruler to "Input 2", and set the "Width Coordinate" to WIDTH and the "Height Coordinate" to 2*HEIGHT.
      2. Connect the output of this Inset to "Input 1" of the next Inset

   4. Attach the Left Ruler.

      1. Connect the Left ruler to "Input 2", and set the "Width Coordinate" to "-2*HEIGHT", and the "Height Coordinate" to "2*HEIGHT".
      2. Display the result.

4. This workspace should work for any square image. Test it by substituting the "Floating Ball" image for the "Spanish Sea Gull" image. Determine the size of the new image and reset the WIDTH variable before executing the workspace.

Exercises

1. Create an encapsulated workspace operator, so that you can use this as a cantata operator.

Khoros Workspace
Execute the visual program c2s5flip-ruler.wk