Share via


Image Watch reference

Image Watch is a Visual Studio debugger Watch window for viewing in-memory bitmaps when debugging native C++ code. For an introduction to Image Watch, see Image Watch.

The reference article refers to elements in FIGURE 1:

Screenshot of Image Watch while debugging.

Image List

The Image List (Figure 1, B) was designed to work like Visual Studio’s built-in Autos, Locals, or Watch list: In Locals mode, the list is read-only and gets populated automatically. In Watch mode, expressions can be added/edited by either double-clicking on the expression text, by pressing F2, or by simply starting to type in a new expression. Expressions can be cut (Ctrl+X, Ctrl+Delete), copied (Ctrl+C, Ctrl+Insert), and pasted (Ctrl+V, Shift+Insert), as well.

Up/Down arrow keys, Tab/Ctrl+Tab, and Home/End navigate the image list.

List items can be collapsed by clicking on the +/- expand symbol at the top left of the each item. Collapsed list items only display the expression name, which greatly decreases the refresh time (note that all displayed information, including thumbnails, needs to be reloaded after every breakpoint or single step). This can be useful when refresh times become noticeable, e.g. when the list has many entries, images are very large, or the debugged process is running on a remote machine.

The Image List has a context menu (right click to activate).

Screenshot of Image List menu.

The options available in the context menu include:

  • Expand/Collapse All: expand/collapse all items that are currently in the list

  • Expand New Items: controls if new list items are initially expanded or collapsed

  • Large Thumbnails: toggles between two thumbnail sizes

  • Auto Maximize Contrast: if not checked, pixel values are mapped to display colors using the standard color mapping rules. If checked, the value range of the current pixel data is mapped to the full range of display colors (like Matlab’s imagesc). Note: this setting applies to all images.

  • 1-Channel Pseudo Color: if not checked, single channel images are shown as grayscale. If checked, a pseudo color map is used (like Matlab’s colormap jet). Note: this setting applies to all images.

  • 4-Channel Ignore Alpha: if not checked, the last channel in four channel images is interpreted as alpha. If checked, last channel is ignored.

  • Add to Watch: adds the selected item to the Watch list

  • Add Address to Watch: adds the address of the selected item to the Watch list. This is useful for watching an image across different stack frames.

  • Dump to File: dumps the selected image to a file. Supported formats are PNG, JPG, and BIN (Image Watch internal lossless file format). BIN files are meant to be used with Image Watch only; they can be loaded into the Watch list using the @file operator.

Image Viewer

The Image Viewer (Figure 1, E) shows a larger version of the currently selected image. It allows you to zoom in (mouse wheel) and inspect individual pixel values (Figure 1, H).

For quick A/B comparisons Ctrl+LeftClick on the viewer switches to the most recently viewed image.

The pixel value display format is: x y | c0 c1 … cN. Channel values ci are displayed in the order they appear in memory.

Right-click to bring up the Viewer’s context menu.

Screenshot of Image Viewer menu.

The options available in the context menu include:

  • Zoom to Fit: set zoom factor to fit view window

  • Zoom to Original Size: set zoom factor to 1.0, i.e. one image pixel occupies one pixel on the screen

  • Link Views: if checked, all images of the same size share a single view (like Matlab’s linkaxes). For example, if you zoom in on a region in a 1024x768 image and then select another 1024x768 image in the Image List, the viewer will show that same region in the second image. In contrast, if you then select a 640x480 image, you will see a different region, namely the one that is shared among all 640x480 images.

  • Auto Maximize Contrast/1-Channel Pseudo Color/4-Channel Use Alpha: these are mirrors of the menu items in the Image List’s context menu. Note that while shown in the Viewer menu here, these settings apply to all images.

  • Hexadecimal Display: this toggles the Visual Studio wide “Hexadecimal Display” setting, which is also used by the built-in Watch window. In Image Watch, it determines how pixel values are displayed (Figure 1, H).

  • Copy Pixel Address: copies the current pixel’s memory address to the clipboard. This can be useful for taking notes, for pasting the address to Visual Studio Debugger’s Memory View window, or for creating a data breakpoint.

Image types

Image Watch has built-in support for the following C/C++ image types:

OpenCV:

  • cv::Mat_<>
  • cv::Mat
  • CvMat
  • _IplImage

User-defined image types may be added using the extensibility interface.

Pixel formats

A pixel format in Image Watch consists of a channel type and a channel format.

Image Watch supports these channel types:

  • INT8, UINT8
  • INT16, UINT16
  • INT32
  • FLOAT16
  • FLOAT32
  • FLOAT64

The channel format denotes number of channels (maximal 512).

Optionally, a format string may be associated with the pixel format. It specifies the semantics of each channel for rendering:

  • RG, UV
  • RGB, BGR, YUV
  • RGBA, BGRA

If the format string is absent (as with all OpenCV types, for example), Image Watch’s default color mapping rules are used for rendering.

A number of special YUV formats are supported as well. In this case, the format string also defines the data layout. For a detailed description of YUV formats, see YUV pixel formats.

  • NV12 (two planes: one Y plane, one packed UV plane, subsampled by 2 in both dimensions)
  • YV12 (three planes: one Y plane, one packed U and V plane each, both subsampled by 2 in both dimensions)
  • IYUV (same as YV12 but with U and V planes switched)
  • YUY2 (single plane, interleaved two-channel format: Y in the first channel; U and V subsampled by 2 horizontally and stored alternating in the second channel)

Color mapping

Image Watch uses the following two rules to map pixel values to display colors:

First, determine the color space. If no format string is present, use the default color space for the given number of channels:

  • 1 channel image: grayscale or pseudo color depending on the current viewer setting.
  • 2 channel image: red/green
  • 3 channel image: B, G, R
  • 4 channel image: B, G, R, Alpha, or ignore Alpha depending on current viewer setting.
  • 5 or more channels: map first three channels to B, G, R, and ignore remaining channels

Second, map channel values to color intensity (0% … 100%) depending on the channel type:

  • INT8: -128 … 127

  • UINT8: 0 … 255

  • INT16: -32,768 … 32,767

  • UINT16: 0 … 65,535

  • INT32: 0 … 1 (Note: the range of meaningful INT32 pixel values varies a lot between applications, hence the arbitrary 0…1 choice here. Please enable automatic contrast maximization to adjust the display to your data when working with INT32 images)

  • FLOAT16: 0 … 1

  • FLOAT32: 0 … 1

  • FLOAT64: 0 … 1

Image operators

Image Watch provides a number of simple operators to help visualize pixel data. To distinguish them from C++ expressions, operators have names that begin with a “@”.

All operators evaluate to images. For example, the @band operator extracts a single channel from an image. It takes two arguments: an image and a zero-based band number. Figure 2 (K) illustrates how to extract the green channel from an example image img0.

Operators can be nested: image inputs to operators can be any image-valued expressions, including output from other operators. For example, the @thresh operator takes an image and a threshold, and returns a binary image (0 if < threshold, 1 if >= threshold). Figure 2 (L) shows how to threshold the green channel of img0 at the value 120.

Note

Unless otherwise noted, Image Watch operators internally work with 32bit float arithmetic and return FLOAT32 images. This means that INT32 images can lose precision, and FLOAT64 can lose precision and range (values are clipped to FLOAT32 range).

Note

By default, FLOAT32 values are mapped to display colors as follows: 0.0f maps to 0% intensity, 1.0f maps to 100% intensity. Out of range values are clipped. For example, if you @clamp a UINT8 image to the range [10, 20], the resulting image will be displayed as all white, since all pixel values are in [10, 20] and get clipped to 1.0f during default color mapping. We therefore recommend enabling automatic contrast maximization when working with operators. Alternatively, the @norm8 and @norm16 operators below provide a quick way to manually scale an operator result by 1/255 or 1/65535, respectively.

List of operators:

  • @band(img, number): extract channel number  (UINT32) from img. Note: this operator preserves the input channel type.
  • @thresh(img, threshold): threshold pixels in img: return 1 if >= threshold (FLOAT32) and 0 otherwise
  • @clamp(img, min, max): clamp pixel values in img to lie between min (FLOAT32) and max (FLOAT32).
  • @abs(img): take absolute value of pixels in img
  • @scale(img, factor): scale pixel values in img by factor (FLOAT32)
  • @norm8(img): scale pixels values in img by 1/255
  • @norm16(img): scale pixels values in img by 1/65535
  • @fliph(img), @flipv(img), @flipd(img): flip img horizontally, vertically, and diagonally (matrix transpose), respectively. Note: this operator preserves the input channel type.
  • @rot90(img), @rot180(img), @rot270(img): rotate img by 90, 180, 270 degrees clockwise, respectively. Note: this operator preserves the input channel type.
  • @diff(img0, img1): return pixel-wise difference: img0 – img1
  • @file(path): load image from path (string). Example: @file(“d:\temp\debug.png”) 
  • @mem(address, type, channels, width, height, stride): interpret raw memory as pixels, starting at address (UINT64), with channel type (see Pixel Formats), number of channels (UINT32), width (UINT32), height (UINT32), and stride (UINT32). Example: @mem(myimg.data, UINT8, 1, 320, 240, 320)

FIGURE 2:

Screenshot of Image Watch operators.

See also